![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
//#include<iostream>
//#include "windows.h"
//#include<string>
//#include<time.h>
//#include<atltime.h>
//using namespace std;
//
//void main()
//{
//
// ////CTime 转CString
// //CTime currTime;
// //CString str;
// // currTime=GetCurrentTime();
// //str=currTime.Format("%H:%M:%S");
// //wcout<<str.GetString()<<endl;
// //CTimeSpan spanTime;
// //spanTime=20;
// //currTime+=spanTime;
// //str=currTime.Format("%H:%M:%S");
// //wcout<<str.GetString()<<endl;
// //getchar();
//
// //CString 转CTime
//
// /*CString timestr = "2000年04月05日";
// int a,b,c ;
// sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&a,&b,&c);
// CTime time(0,0,0,a,b,c);
//
// CString str;
// str=time.Format("%H:%M:%S");
// wcout<<str.GetString()<<endl;
// getchar();*/
// /*CString sss("23:13:23");
// int a,b,c;
// sscanf(sss.GetBuffer(sss.GetLength()),"%d:%d:%d",&a,&b,&c);
// CTime timess(0,0,0,a,b,c);
// str=timess.Format("%H:%M:%S");
// wcout<<str.GetString()<<endl;*/
//}
#include <windows.h>
#include <stdio.h>
#include <conio.h>
int count =0;
//处理函数
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
count++;
printf("WM_TIMER in work thread count=%d\n",count);
}
//线程
DWORD CALLBACK Thread(PVOID pvoid)
{
MSG msg;
PeekMessage(&msg,NULL,WM_USER,WM_USER,PM_NOREMOVE);
UINT timerid=SetTimer(NULL,111,3000,TimerProc);//3秒执行一次,ID为111
BOOL bRet;
while( (bRet = GetMessage(&msg,NULL,0,0))!= 0)
{
if(bRet==-1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
KillTimer(NULL,timerid);
printf("thread end here\n");
return 0;
}
int main()
{
DWORD dwThreadId;
printf("use timer in workthread of console application\n");
HANDLE hThread = CreateThread(NULL,0,Thread,0,0,&dwThreadId);
_getch();
return 0;
}