<menu id="w8yyk"><menu id="w8yyk"></menu></menu>
  • <dd id="w8yyk"><nav id="w8yyk"></nav></dd>
    <menu id="w8yyk"></menu>
    <menu id="w8yyk"><code id="w8yyk"></code></menu>
    <menu id="w8yyk"></menu>
    <xmp id="w8yyk">
    <xmp id="w8yyk"><nav id="w8yyk"></nav>
  • 網站首頁 > 物聯資訊 > 技術分享

    SetTimer在無窗口和有窗口線程的使用 . .

    2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀
    睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接 今天犯了一個粗心的錯誤,在無窗口線程中,SetTimer中設置計時器ID,而WM_TIMER消息響應函數中得到的計時器ID卻不是之前設置的計時器ID.

     

    [cpp] view plaincopyprint?
    1. // 111902.cpp : Defines the entry point for the console application.   
    2. //   
    3. //#include "stdafx.h"   
    4. #include "stdio.h"   
    5. #include "windows.h"   
    6. BOOL DispatchThreadMessage(MSG* pMsg);  
    7. VOID CALLBACK OnTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime);  
    8. int main(int argc, char* argv[])  
    9. {  
    10.     printf("Hello World!\n");  
    11.     ::SetTimer(NULL,45,1000,OnTimerProc);  
    12.     MSG msg;  
    13.     while (GetMessage(&msg, 0, 0, 0) > 0)  
    14.     {  
    15.         if (msg.hwnd == NULL && DispatchThreadMessage(&msg))  
    16.             continue;  
    17.         TranslateMessage(&msg);  
    18.         DispatchMessage(&msg);  
    19.     }  
    20.     return 0;  
    21. }  
    22.   
    23. BOOL DispatchThreadMessage(MSG* pMsg)  
    24. {  
    25.     if(pMsg->message == 0x0113)  
    26.     {  
    27.         printf("DispatchThreadMessage: %6d\n",pMsg->wParam);  
    28.         return false;         
    29.     }  
    30.     return false;  
    31. }   
    32. VOID CALLBACK OnTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)  
    33. {  
    34.     printf("OnTimerProc: %6d\n",idEvent);  
    35. }  

     

     

    對應計時器ID的輸出的是一個隨機數字.

     

    原來在msdn中

    nIDEvent
    [in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, and the nIDEvent does not match an existing timer then it is ignored and a new timer ID is generated. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent , then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. If the call is not intended to replace an existing timer, nIDEvent should be 0 if the hWnd is NULL.

    注:只有當hWnd參數為非空時,計時器的ID為設置的 nIDEvent,  否則系統為你自動生成一個計時器ID,可由返回時值獲取.
    RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成
    最近免费观看高清韩国日本大全