Determine if a window is suspended (send Wm_null message, or call Ishungappwindow API to test)

Source: Internet
Author: User

Determine whether a window is suspended (is not responding), in the Multi-window programming is often used, before the other window to send messages, for the purpose of the window can be determined to receive the message, often before the first check whether the window is suspended, we used to use the following method:

[CPP]View PlainCopy
    1. //  determine if a window has stopped responding (timeout 0.5 seconds)   
    2. DWORD_PTR DWRESULT = 0;  
    3. lresult lr = ::sendmessagetimeout (g_hwin, wm_null, 0,  0, smto_abortifhung | smto_block, 500, &dwresult);   
    4. if  (LR)   
    5. {  
    6.     //  can also respond   
    7. }  
    8. else  
    9. {  
    10.     //  has stopped responding (as the old saying window hangs dead)    
    11. }  

Later on (http://blog.csdn.net/wingeek/article/details/3875903) saw a method using the Ishungappwindow API to directly determine whether the window is suspended, From the MSDN view (http://msdn.microsoft.com/en-us/library/ms633526.aspx), this API has been provided from Windows2000, but until Windowsxp_ The SDK was only available at the beginning of SP1 and windows2003. Start guessing is whether the internal is the use of sendmessagetimeout implementation, real-time tracking down, found not. Here is the implementation code for Ishungappwindow:

77d69c61 > 8BFF MOV edi,edi
77d69c63. EBP
77D69C64 8BEC MOV Ebp,esp
77D69C66 6A 4
77d69c68 FF75 PUSH DWORD PTR ss:[ebp+8]
77d69c6b E8 6BEAFAFF Call user32.77d186db
77d69c70 F7d8 NEG EAX
77D69C72 1bc0 SBB Eax,eax
77d69c74 F7d8 NEG EAX
77d69c76 5D POP EBP
77d69c77 C2 0400 RETN 4


77d186db B8 E3110000 MOV eax,11e3
77d186e0 BA 0003fe7f MOV edx,7ffe0300
77d186e5 FF12 call DWORD PTR Ds:[edx]; Ntdll. Kifastsystemcall
77d186e7 C2 0800 RETN 8

Inside the Ishungappwindow is actually very simple, Call user32.77d186db This function, this function is actually ntuserquerywindow (from the back can be seen inside the 77d186db directly to the kernel call, the function number eax is 11E3), where 7ffe0300 is both Kifastsystemcall land Address, in the place of the call Ntuserquerywindow, push the two parameters, namely Ntuserquerywindow (HWND, 4), the first parameter is the handle of the destination window, the second parameter is the query ID, that is, indicating what information to check this window, 4 is to check whether this window hangs, directly by the RING0 to achieve ...

http://blog.csdn.net/magictong/article/details/7296250

Determine if a window is suspended (send Wm_null message, or call Ishungappwindow API to test)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.