• <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>

            小明思考

            高性能服務(wù)器端計(jì)算
            posts - 70, comments - 428, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            SendMessage 和 SendMessageTimeout

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

            MSDN上面有一段文字是這樣說(shuō)的

            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 : 如果指定窗口由調(diào)用線程創(chuàng)建,那么窗口過(guò)程會(huì)被當(dāng)成一個(gè)子程序立即調(diào)用。如果指定窗口由另外一個(gè)線程創(chuàng)建,那么系統(tǒng)會(huì)切換到那個(gè)線程,并且調(diào)用合適的窗口過(guò)程。在線程之間傳遞的消息僅僅當(dāng)接收線程執(zhí)行message retrieval code才會(huì)被處理。發(fā)送線程會(huì)被堵塞直到接收線程處理完消息。但是,發(fā)送線程在等待的同時(shí)會(huì)處理收到的nonqueued messages 。為了阻止這一點(diǎn),使用帶有SMTO_BLOCK參數(shù) 的SendMessageTimeout .

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

            我曾經(jīng)遇到這個(gè)問(wèn)題,我調(diào)用SendMessage向另外一個(gè)線程窗口發(fā)message,本來(lái)以為他會(huì)一直block住,但是他卻調(diào)用了另外一個(gè)消息的處理程序,導(dǎo)致了行為不正確。所以一定要小心使用SendMessage發(fā)給其他線程的窗口。

            我修改了一下,把
            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);
            解決了這個(gè)bug.

            Feedback

            # re: SendMessage 和 SendMessageTimeout  回復(fù)  更多評(píng)論   

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

            # re: SendMessage 和 SendMessageTimeout  回復(fù)  更多評(píng)論   

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

            # re: SendMessage 和 SendMessageTimeout  回復(fù)  更多評(píng)論   

            2011-11-17 10:56 by 寂寞男生
            哥也沒(méi)看懂呀!!!

            # re: SendMessage 和 SendMessageTimeout  回復(fù)  更多評(píng)論   

            2012-02-20 15:59 by zhgkun
            首先英文翻譯的的比較準(zhǔn)確、專業(yè)!
            正在研究SendMessage和SendMessageTImeOut區(qū)別,其中一個(gè)例子是,啟動(dòng)應(yīng)用程序新實(shí)例前,向已存在的實(shí)例發(fā)送copydata消息做一些處理,原先用的是sendmessage,現(xiàn)在覺(jué)得用sendmessagetimeout應(yīng)該更穩(wěn)妥一些

            # re: SendMessage 和 SendMessageTimeout  回復(fù)  更多評(píng)論   

            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.

            順便翻譯一下最后一句
            “如果接收進(jìn)程處于掛起狀態(tài),不再等待(超時(shí))直接返回”
            狠狠色婷婷综合天天久久丁香 | A级毛片无码久久精品免费| 久久精品男人影院| 99久久精品毛片免费播放| 久久精品国产亚洲AV香蕉| 日韩精品无码久久久久久| 亚洲日本久久久午夜精品| 伊人久久五月天| 久久人人爽人人爽人人片AV高清| 久久婷婷是五月综合色狠狠| 亚洲欧洲久久av| 亚洲国产精品无码久久98| 久久人人爽人人爽人人AV| 国产情侣久久久久aⅴ免费| 久久国产精品成人片免费| 久久久久国产精品| 久久久受www免费人成| 久久综合久久综合亚洲| 亚洲国产欧洲综合997久久| 久久久久久亚洲Av无码精品专口 | 久久棈精品久久久久久噜噜| 99久久久精品免费观看国产| 91秦先生久久久久久久| 日韩欧美亚洲国产精品字幕久久久 | 中文精品久久久久国产网址| 久久久久久噜噜精品免费直播| 亚洲а∨天堂久久精品| 久久精品毛片免费观看| 久久国产免费直播| 久久久久久亚洲精品成人| 7国产欧美日韩综合天堂中文久久久久 | 综合网日日天干夜夜久久| 国产精品久久影院| 亚洲国产精品无码久久青草| 久久香蕉超碰97国产精品 | 久久99精品久久久久久hb无码 | 久久久久国产亚洲AV麻豆| 久久男人Av资源网站无码软件| 99久久精品国产一区二区| 伊人久久大香线蕉亚洲五月天| 国内精品伊人久久久久网站|