• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            小明思考

            高性能服務器端計算
            posts - 70, comments - 428, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            SendMessage 和 SendMessageTimeout

            Posted on 2006-07-21 09:50 小明 閱讀(10366) 評論(5)  編輯 收藏 引用 所屬分類: Win32
            SendMessageTimeout并不是簡單在SendMessage加上Timeout的功能。

            MSDN上面有一段文字是這樣說的

            If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. To prevent this, use SendMessageTimeout with SMTO_BLOCK set. For more information on nonqueued messages, see Nonqueued Messages.


            翻譯一下:

            SendMessage : 如果指定窗口由調用線程創建,那么窗口過程會被當成一個子程序立即調用。如果指定窗口由另外一個線程創建,那么系統會切換到那個線程,并且調用合適的窗口過程。在線程之間傳遞的消息僅僅當接收線程執行message retrieval code才會被處理。發送線程會被堵塞直到接收線程處理完消息。但是,發送線程在等待的同時會處理收到的nonqueued messages 。為了阻止這一點,使用帶有SMTO_BLOCK參數 的SendMessageTimeout .

            =================================華麗的分割線===========================

            我曾經遇到這個問題,我調用SendMessage向另外一個線程窗口發message,本來以為他會一直block住,但是他卻調用了另外一個消息的處理程序,導致了行為不正確。所以一定要小心使用SendMessage發給其他線程的窗口。

            我修改了一下,把
            pWnd->SendMessage(MSG_LOG_MESSAGE, nMsgType, (LPARAM)(LPCTSTR)m_cstrMessage);
            改成了
            HWND hWnd = pWnd->GetSafeHwnd();
            ::SendMessageTimeout(hWnd,MSG_LOG_MESSAGE, nMsgType, (LPARAM)(LPCTSTR)m_cstrMessage,SMTO_BLOCK,15000,0);
            解決了這個bug.

            Feedback

            # re: SendMessage 和 SendMessageTimeout  回復  更多評論   

            2006-12-27 15:02 by honey
            好!!!雖然我看不懂寫些什么

            # re: SendMessage 和 SendMessageTimeout  回復  更多評論   

            2009-02-12 14:50 by lijinyan3000
            沒看明白啊。。。可能是我水平不夠。。。

            # re: SendMessage 和 SendMessageTimeout  回復  更多評論   

            2011-11-17 10:56 by 寂寞男生
            哥也沒看懂呀!!!

            # re: SendMessage 和 SendMessageTimeout  回復  更多評論   

            2012-02-20 15:59 by zhgkun
            首先英文翻譯的的比較準確、專業!
            正在研究SendMessage和SendMessageTImeOut區別,其中一個例子是,啟動應用程序新實例前,向已存在的實例發送copydata消息做一些處理,原先用的是sendmessage,現在覺得用sendmessagetimeout應該更穩妥一些

            # re: SendMessage 和 SendMessageTimeout  回復  更多評論   

            2012-02-20 16:21 by zhgkun
            LRESULT SendMessageTimeout(
            HWND hWnd, // handle to window
            UINT Msg, // message
            WPARAM wParam, // first message parameter
            LPARAM lParam, // second message parameter
            UINT fuFlags, // send options
            UINT uTimeout, // time-out duration
            PDWORD_PTR lpdwResult // return value for synchronous call
            );

            fuFlags
            [in] Specifies how to send the message. This parameter can be one or more of the following values

            SMTO_ABORTIFHUNG
            Returns without waiting for the time-out period to elapse if the receiving process appears to be in a "hung" state.

            順便翻譯一下最后一句
            “如果接收進程處于掛起狀態,不再等待(超時)直接返回”
            色偷偷偷久久伊人大杳蕉| 欧美大香线蕉线伊人久久| 品成人欧美大片久久国产欧美...| 亚洲国产成人久久精品影视| 久久黄视频| 久久夜色精品国产网站| 成人a毛片久久免费播放| 偷偷做久久久久网站| 91精品国产高清91久久久久久| 久久精品国产精品亚洲艾草网美妙| 久久无码国产专区精品| 久久亚洲国产午夜精品理论片 | 久久人妻无码中文字幕| 久久精品国产91久久麻豆自制| 色偷偷88欧美精品久久久| 国产精品一区二区久久| 蜜臀久久99精品久久久久久小说| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 伊人久久大香线焦综合四虎| 亚洲精品久久久www| 久久99国产精品久久99| 99精品久久久久久久婷婷| 欧美午夜精品久久久久久浪潮| 国产精品久久久久久搜索| 天堂久久天堂AV色综合| 性做久久久久久免费观看| www亚洲欲色成人久久精品| 久久精品人人做人人妻人人玩| 香蕉久久影院| 久久久久一级精品亚洲国产成人综合AV区 | 日韩va亚洲va欧美va久久| 久久九九亚洲精品| 久久亚洲欧美日本精品| 91久久精品91久久性色| 久久精品黄AA片一区二区三区| 午夜精品久久久久久中宇| 亚洲香蕉网久久综合影视| 亚洲色欲久久久综合网东京热 | 成人妇女免费播放久久久| 久久水蜜桃亚洲av无码精品麻豆| 97精品伊人久久久大香线蕉|