如题
解决方案 »
- URLDownloadToFile下载文件失败的问题
- 请教一个客户端单线程Socket问题
- 要开发一个IE工具栏需要哪方面的知识?
- VC++ 中有CHuabanView类这个类么?有的画如何构造创建
- ReadFile的用法,怎么判断读取文件结束
- 如果最有效的将COleDateTime转换成time_t类型?在线?
- 哪里可以找到vc++的英文原版连同中文的书
- 关于修改状态栏提示信息...
- 为什么不能创建实例?(小妹没分了)
- 用vc生成的程序是不是debug版本怎么变成比较小的.exe而且我的一个程序在别人的机器上没办法运行怎么办???
- error LNK2019 大家帮帮忙啊 高分求救
- 使用的CserialPort的高手看看,这里有点问题。
user timer in workthread of console app
#include <windows.h>
#include <stdio.h>
#include <conio.h>
unsigned long WINAPI Thread(PVOID pvoid);
void main()
{
DWORD dwThreadId;
printf("use timer in workthread of console application<masterz>\n");
HANDLE hThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
Thread, // thread function
0, // argument to thread function
0, // use default creation flags
&dwThreadId);
DWORD dwwait=WaitForSingleObject(hThread,1000*30);
switch(dwwait)
{
case WAIT_ABANDONED:
printf("main thread WaitForSingleObject return WAIT_ABANDONED\n");
break;
case WAIT_OBJECT_0:
printf("main thread WaitForSingleObject return WAIT_OBJECT_0\n");
break;
case WAIT_TIMEOUT:
printf("main thread WaitForSingleObject return WAIT_TIMEOUT\n");
break;
}
CloseHandle(hThread);
_getch();
}unsigned long WINAPI Thread(PVOID pvoid)
{
MSG msg;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
UINT timerid=SetTimer(NULL,111,3000,NULL);
BOOL bRet;
int count =0;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
if(msg.message==WM_TIMER)
{
count++;
printf("WM_TIMER in work thread count=%d\n",count);
if(count>4)
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
KillTimer(NULL,timerid);
printf("thread end here\n");
return 0;
}
最后一个参数用TIME_CALLBACK_EVENT_SET
使用WaitForMultiObject监测事件