1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <windows.h>
#include <Commctrl.h>
#include "resource.h"
#define IDT_TIMER 10
HINSTANCE hInst;
HWND hWnd;
FARPROC lpfnOldWndProc;
int compteurdepassage=0;
int Increment=0;
LONG FAR PASCAL SubClassFunc(HWND hwnd, WORD Message, WORD wParam, LONG lParam)
{
if (Message == WM_PAINT)
{
HDC hDC;
PAINTSTRUCT ps;
RECT ClientRect, LeftRect, RightRect;
char szTexte[30];
HRGN hRgn;
DWORD dwTextStyle = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
int nPos = (int)SendMessage(hwnd, PBM_GETPOS, 0, 0);
COLORREF crBarColour = GetSysColor(COLOR_HIGHLIGHT);
COLORREF crBgColour = GetSysColor(COLOR_WINDOW);
GetClientRect(hwnd, &ClientRect);
LeftRect = RightRect = ClientRect;
int D = LeftRect.right - LeftRect.left;
LeftRect.right = LeftRect.left + (int)((D * nPos) / 100);
RightRect.left = LeftRect.right;
hDC = BeginPaint(hwnd, &ps) ;
// Dessiner la bar
FillRect(hDC, &LeftRect, (HBRUSH)CreateSolidBrush(crBarColour));
FillRect(hDC, &RightRect, (HBRUSH)CreateSolidBrush(crBgColour));
// Afficher le texte
wsprintf(szTexte, "ATTENTE : %d%%", nPos);
SetBkMode(hDC, TRANSPARENT);
// Le blanc
hRgn = CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom);
SelectClipRgn(hDC, hRgn);
SetTextColor(hDC, crBgColour);
DrawText(hDC, szTexte, (int)lstrlen(szTexte), &ClientRect, dwTextStyle);
// Le bleu
DeleteObject(hRgn);
hRgn = CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom);
SelectClipRgn(hDC, hRgn);
SetTextColor(hDC, crBarColour);
DrawText(hDC, szTexte, (int)lstrlen(szTexte), &ClientRect, dwTextStyle);
EndPaint (hwnd, &ps) ;
return TRUE;
}
if (Message == WM_GETDLGCODE) //Bloque les touches clavier (enter)
return DLGC_WANTALLKEYS;
return CallWindowProc((WNDPROC)lpfnOldWndProc, hwnd, Message, wParam, lParam);
}
LRESULT CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
Increment = 3000/10;
SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETSTEP, (WPARAM) 10, 0);
lpfnOldWndProc = (FARPROC)SetWindowLong(GetDlgItem(hDlg, IDC_PROGRESS1),
GWL_WNDPROC, (DWORD) SubClassFunc);
SetTimer(hDlg, IDT_TIMER, Increment, NULL);
}
break;
case WM_TIMER:
if(wParam == IDT_TIMER)
{
SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
compteurdepassage ++;
if(compteurdepassage >= 10)
{
KillTimer(hDlg,IDT_TIMER);
EndDialog(hDlg, FALSE);
}
return TRUE;
break;
}
case WM_COMMAND:
break;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
int i;
InitCommonControls();
for(i=0;i<10;i++)
{
Sleep(500);
compteurdepassage=0;
Increment=0;
DialogBox(hInstance, (LPCTSTR)IDD_DIALOG, NULL, (DLGPROC)DlgProc);
}
return 1;
} |
Partager