1.SetTimer是需要消息队列支持的,你的程序没有窗口,也就没有消息机制
2.不明白LZ为什么要在线程中SetTimer?,有什么目的?如果只是实现定时器功能,只直用线程就可以模拟出来
DWORD CALLBACK DoThread(PVOID pvoid)
{
while(退出条件)
{
Sleep(xxx);
DoSomething();
}
3.若要创建无窗口的定时器,可以用多媒体定时器TimeSetEvent...
{
2.不明白LZ为什么要在线程中SetTimer?,有什么目的?如果只是实现定时器功能,只直用线程就可以模拟出来
DWORD CALLBACK DoThread(PVOID pvoid)
{
while(退出条件)
{
Sleep(xxx);
DoSomething();
}
3.若要创建无窗口的定时器,可以用多媒体定时器TimeSetEvent...
{
解决方案 »
- 指定CreateFile的哪个标志可以向文件末尾添加数据?
- gdi+填充问题
- 如何在自己的程序里面添加ini文件,来保存程序的状态
- 谁能提供个网络较时NTP服务端的源码分享参考下
- 应该挂接哪些API函数
- CSDN优秀版主评比!!vc版的同学们快去支持啊~!~!支持蒋老大和狗狗!!!!
- CListView列表控件的问题?急,在线等待?
- 请问vc在debug编译模式下运行需那些.dll才能在没装vc的机器上运行?
- IE 工具栏判断某一网是否登录
- 请问我动态加CCecklistbox,但运行后报错,是何原因?
- MFC 线程创建问题?
- 在VC6里运行没有问题,但是在VS2012里面运行就不行(有代码)
你需要创建消息循环,这样才能有消息队列,接受消息
while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if(bRet == -1)
{
// handle the error and possibly exit
PRINT("GetMessage Error...");
}
else if (msg.message = WM_USER)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
PRINT("接收到WM_USER消息....");
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
我怎么看你这段根本就没有循环直接出错退出了。
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
printf("Hello......\r\n");
}DWORD CALLBACK DoThread(PVOID pvoid)
{
MSG msg;
UINT timerid;
BOOL bRet;
char sCurDateTime[18] = {0};
printf("进入线程处理...\r\n"); //bRet = PeekMessage(&msg,NULL,WM_USER,WM_USER, PM_NOREMOVE); timerid = SetTimer(NULL, 123, 2000, TimerProc); while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} KillTimer(NULL, timerid); printf("线程处理结束...\r\n");
return 0;
}int main()
{
int iRet = 0;
DWORD dwThreadId;
HANDLE hThread;
DWORD exitCode = 0; hThread = CreateThread(NULL,0,DoThread,0,0,&dwThreadId);
printf("线程已创建成功...\r\n");
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
return 0;
}