1.SetTimer是需要消息队列支持的,你的程序没有窗口,也就没有消息机制
2.不明白LZ为什么要在线程中SetTimer?,有什么目的?如果只是实现定时器功能,只直用线程就可以模拟出来
DWORD CALLBACK DoThread(PVOID pvoid) 
{
  while(退出条件)
  { 
    Sleep(xxx); 
    DoSomething();
  } 
3.若要创建无窗口的定时器,可以用多媒体定时器TimeSetEvent...
{

解决方案 »

  1.   

    Timer是WM_TIMER消息
    你需要创建消息循环,这样才能有消息队列,接受消息
      

  2.   

    貌似楼主已经建立起了自己的消息循环,但为什么回调函数未启动确实有些奇怪,楼主需要调试一下,看看你的消息循环里收到WM_TIMER消息没有。
      

  3.   

    控制台程序需要手工添加   getmessage,tranlmessage等消息函数来手工建立消息机制,因为settimer需要消息机制支持。
      

  4.   

    你那个接收消息的代码能成功吗?
    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);
        }
    }
    我怎么看你这段根本就没有循环直接出错退出了。
      

  5.   

    在线程中为什么要settimer,没有创建WM_TIMER消息
      

  6.   


    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;
    }
      

  7.   

    WM_USER消息是怎么产生的?在消息循环体里面,貌似又接收到到WM_USER消息?
      

  8.   

    应该和你调用SetTimer(NULL, ...);有关系~