void DisPlayDigit(HDC hdc, int iNum)
{
static BOOL fSegment[10][7] =
{
1,1,1,0,1,1,1, //0
0,0,1,0,0,1,0, //1
1,0,1,1,1,0,1, //2
1,0,1,1,0,1,1, //3
0,1,1,1,0,1,0, //4
1,1,0,1,0,1,1, //5
1,1,0,1,1,1,1, //6
1,0,1,0,0,1,0, //7
1,1,1,1,1,1,1, //8
1,1,1,1,0,1,1 //9
};
static POINT ptSegment[7][6] =
{
5,5, 8,2, 18,2, 21,5, 18,8, 8,8,
5,6, 8,9, 8,19, 5,22, 2,19, 2,9,
21,6, 24,9, 24,19, 21,22, 18,19, 18,9,
5,23, 8,20, 18,20, 21,23, 18,26, 8,26,
5,24, 8,27, 8,37, 5,40, 2,37, 2,27,
21,24, 24,27, 24,37, 21,40, 18,37, 18,27,
5,41, 8,38, 18,38, 21,41, 18,44, 8,44
};
int i;
for(i =0; i<7; ++i)
if(fSegment[iNum][i])
Polygon(hdc, ptSegment[i], 6);
}
void DisplayTime(HDC hdc)
{
SYSTEMTIME time;
int iDigit;
static POINT pt[4] ={2,23, 5,20, 8,23, 5,26};
GetLocalTime(&time);
iDigit = time.wHour/10;//display hour
DisPlayDigit(hdc, iDigit);
OffsetWindowOrgEx(hdc, -24, 0, NULL);
iDigit = time.wHour%10;
DisPlayDigit(hdc, iDigit);
OffsetWindowOrgEx(hdc, -24, 0, NULL);
Polygon(hdc, pt, 4);
OffsetWindowOrgEx(hdc, -8, 0,NULL);
iDigit = time.wMinute/10;//display minute
DisPlayDigit(hdc, iDigit);
OffsetWindowOrgEx(hdc, -24, 0, NULL);
iDigit = time.wMinute%10;
DisPlayDigit(hdc, iDigit);
OffsetWindowOrgEx(hdc, -24, 0, NULL);
Polygon(hdc, pt, 4);
OffsetWindowOrgEx(hdc, -8, 0,NULL);
iDigit = time.wSecond/10;//display second
DisPlayDigit(hdc, iDigit);
OffsetWindowOrgEx(hdc, -24, 0, NULL);
iDigit = time.wSecond%10;
DisPlayDigit(hdc, iDigit);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static int cxClient,cyClient;
static HBRUSH hbrRedBrush;
switch(message)
{
case WM_CREATE:
hbrRedBrush = CreateSolidBrush(RGB(255,0,0));
SetTimer(hWnd, 1, 1000, NULL);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
case WM_TIMER:
InvalidateRect(hWnd, NULL, TRUE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
SelectObject(hdc, hbrRedBrush);
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, 160, 44, NULL);
SetViewportExtEx(hdc, cxClient, cyClient, NULL);
SetWindowOrgEx(hdc, 80,22,NULL);
SetViewportOrgEx(hdc, cxClient/2,cyClient/2, NULL);
DisplayTime(hdc);
SelectObject(hdc, GetStockObject(WHITE_BRUSH));
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
KillTimer(hWnd, 1);
DeleteObject(hbrRedBrush);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
用定时器显示时间 窗口过程函数
最新推荐文章于 2023-10-10 21:48:33 发布