我想用GetSystemtime();得到系统时间并用TEXTOUT();显示出来要一直更新时间,就好像桌面右下角的时钟一样,那位高手能给我代码啊
解决方案 »
- 分水岭分割算法
- ado data control控件连接数据库
- 怎么样让list Control的滑块消失但不影响EnsureVisiable()的使用?
- 请问我在combobox里面处理退格健,该怎么判断光标处什么哪个字符之间,怎么删去前一个字符呢?
- 怎样将 int类型的16进制数转换为 COLORREF 类型
- 使用Ftp上传文件时,如何能让程序自动识别应该以那种格式(ASCII或Bin)上传该文件?
- unicode下的CTime问题
- Plug and Play 1.0A 规范,规定了什么,哪里能找到?
- vc中数据库操作方面的问题, 请教各位
- vc浏览信息不可以用于此工程的解决办法
- 键盘钩子变成监视剪贴板
- 如何对AfxExtractSubString分割出来的数据排序?
设定一个 1 秒的定时器即可:
::SetTimer(...);
我年前帮别人做的
#pragma comment(lib,"WINMM.lib")
#include "mmsystem.h"
void DrawDigit(HDC hDC,int number)
{
static BOOL fSegment[10][7]={ 1,1,1,0,1,1,1,
0,0,1,0,0,1,0,
1,0,1,1,1,0,6,
1,0,1,1,0,1,1,
0,1,1,1,0,1,0,
1,1,0,1,0,1,1,
1,1,0,1,1,1,1,
1,1,1,0,0,1,0,
1,1,1,1,1,1,1,
1,1,1,1,0,1,1
};
static POINT pCoordinate[7][6]={
7,6,11,2,31,2,35,6,31,10,11,10,
6,7,10,11,10,31,6,35,2,31,2,11,
36,7,40,11,40,31,36,35,32,31,32,11,
7,36,11,32,31,32,35,36,31,40,11,40,
6,37,10,41,10,61,6,65,2,61,2,41,
36,37,40,41,40,61,36,65,32,61,32,41,
7,66,11,62,31,62,35,66,31,70,11,70
};
for(int i=0;i<7;++i)
{
if(fSegment[number][i])
Polygon(hDC,pCoordinate[i],6);
}
}
void DrawTwoDigits(HDC hDC,int number,BOOL bSupress)
{
if(!bSupress||number/10!=0)
DrawDigit(hDC,number/10); OffsetWindowOrgEx(hDC,-42,0,NULL); DrawDigit(hDC,number%10); OffsetWindowOrgEx(hDC,-42,0,NULL);
}void DrawColon(HDC hdc)
{
static POINT ptColon[2][4]={
2,21,6,17,10,21,6,25,
2,51,6,47,10,51,6,55
};
Polygon(hdc,ptColon[0],4);
Polygon(hdc,ptColon[1],4);
OffsetWindowOrgEx(hdc,-12,0,NULL);
}void DrawTime(HDC hDC,BOOL fb24Hour,BOOL bSuppress)
{
SYSTEMTIME sysTime;
GetLocalTime(&sysTime); if(fb24Hour)
{
DrawTwoDigits(hDC,sysTime.wHour,bSuppress);
}
else
{
DrawTwoDigits(hDC,sysTime.wHour%12 ?sysTime.wHour:12,bSuppress);
}
DrawColon(hDC);
DrawTwoDigits(hDC,sysTime.wMinute,FALSE);
DrawColon(hDC);
DrawTwoDigits(hDC,sysTime.wSecond,FALSE);}void GetTimeInformation(BOOL& fB24Hour,BOOL& fSuppress,TCHAR* szHourFormat,TCHAR* szLZero)
{
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_ITIME,szHourFormat,3);
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_ILZERO,szLZero,3);
fB24Hour=(szHourFormat[0]==_T('1')?1:0);
fSuppress=(szLZero[0]==_T('0')?1:0);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static HBRUSH hRedBrush;
TCHAR szHourFormat[3];
TCHAR szLZero[3];
static BOOL fB24Hour;
static BOOL fSuppress;
static int cxClient,cyClient;
RECT rect;
switch (message)
{
case WM_CREATE:
GetTimeInformation(fB24Hour,fSuppress,szHourFormat,szLZero);
hRedBrush=CreateSolidBrush(RGB(255,0,0));
SetTimer(hWnd,IDC_TIMER,1000,NULL);
break;
case WM_SETTINGCHANGE:
GetTimeInformation(fB24Hour,fSuppress,szHourFormat,szLZero);
InvalidateRect(hWnd,NULL,TRUE);
break;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
break;
case WM_TIMER:
rect.left=0;
rect.top=cyClient/3-20;
rect.bottom=2*cyClient/3+20;
rect.right=cxClient;
PlaySound(_T("C:\\WINDOWS\\Media\\ding.wav"),NULL,SND_ASYNC|SND_FILENAME);
InvalidateRect(hWnd,&rect,TRUE);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps); SetMapMode(hdc,MM_ISOTROPIC);
SetWindowExtEx(hdc,276,72,NULL);
SetViewportExtEx(hdc,cxClient,cyClient,NULL);
SetWindowOrgEx(hdc,138,36,NULL); SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);
SelectObject(hdc,GetStockObject(NULL_PEN));
SelectObject(hdc,hRedBrush);
DrawTime(hdc,fB24Hour,fSuppress);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
KillTimer(hWnd,IDC_TIMER);
DeleteObject(hRedBrush);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}