用定时器显示时间 窗口过程函数

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);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值