15,471
社区成员
发帖
与我相关
我的任务
分享
int main()
{
int iRet = 0;
DWORD dwThreadId;
HANDLE hThread;
DWORD exitCode = 0;
hThread = CreateThread(NULL,0,DoThread,0,0,&dwThreadId);
PRINT("线程已创建成功...");
dwStat = WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
return 0;
}
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
PRINT("Hello......");
}
DWORD CALLBACK DoThread(PVOID pvoid)
{
MSG msg;
UINT timerid;
BOOL bRet;
char sCurDateTime[18] = {0};
PRINT("进入线程处理...");
bRet = PeekMessage(&msg,NULL,WM_USER,WM_USER, PM_NOREMOVE);
timerid=SetTimer(NULL,123,2000,TimerProc);
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);
}
}
KillTimer(NULL,timerid);
PRINT("线程处理结束...");
return 0;
}
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;
}
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);
}
}
我怎么看你这段根本就没有循环直接出错退出了。