请贴上源码!
如能解决另开版加分!

解决方案 »

  1.   

    我的做法是在WH_CBT上設置鈎子,在創建窗口時用自己proc替換窗口的Proc,並以窗口的名義創建Timer,在proc中處理WM_TIMER消息。
    注意該調原窗口proc的地方要調用原來的proc
      

  2.   

    如果需要全局的 Timer, 创建一个这样子的线程试试DWORD WINAPI ThreadProc(LPVOID lpParameter)
    {
        HANDLE hTimer = OpenWaitableTimer(SYNCHRONIZE, FALSE, _T("Global\\CSTimer"));    if (hTimer == NULL)
            CreateWaitableTimer(NULL, FALSE, _T("Global\\CSTimer"));    while (TRUE) 
        {
            DWORD dwWait = MsgWaitForMultipleObjects(1, &hTimer, FALSE, INFINITE, QS_ALLEVENTS);
            if (dwWait == WAIT_OBJECT_0)
            {
                // Get the timer event...
            }
            else if (dwWait == WAIT_OBJECT_0 + 1)
            {
                MSG msg;
                if ( !GetMessage(&msg, NULL, 0, 0) )
                    break;
            }
        }    CloseHandle(hTimer);    return 0;
    }
      

  3.   

    才发现写错了一点:if (hTimer == NULL)
        hTimer = CreateWaitableTimer(NULL, FALSE, _T("Global\\CSTimer"));
      

  4.   

    类似这个#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;
    }