Why does FindWindow find a window that EnumChildWindows does not?

I am looking for a window in which its class name is "CLIPBRDWNDCLASS" (it can be found in office applications and other applications).

If I use FindWindow or FindWindowEx, I find the first HWND that has this class, but I want all the windows with this class, so I decided to use the recursive EnumChildWindows to list all the windows and search for the window that I want:

//------------------------------------------------------------------------------- BOOL CALLBACK enum_wnd_proc(HWND h, LPARAM lp) { char cls[1024] = {0}; ::GetClassNameA(h, cls, 1024); if(std::string(cls) == "CLIPBRDWNDCLASS") { // match! } ::EnumChildWindows(h, enum_wnd_proc, NULL); return TRUE; } //------------------------------------------------------------------------------- int _tmain(int argc, _TCHAR* argv[]) { ::EnumWindows(enum_wnd_proc, NULL); return 0; } //------------------------------------------------------------------------------- 

This is that this window does not return to EnumWindows, only with FindWindow.

Can anyone tell me why it is not working?

+4
source share
2 answers

The reason EnumWindows does not work is because the window you are looking for is just a message box .

FindWindowEx can find them in two cases:

  • If both hwndParent and hwndChildAfter are NULL.
  • If you specify "HWND_MESSAGE" as the parent window.

This code will find for you all the relevant windows (a modified version of the solution from here ):

 HWND hWindow = FindWindowExA(HWND_MESSAGE, NULL, "CLIPBRDWNDCLASS", NULL); while (hWindow ) { // Do something here with window... // Find next window hWindow = FindWindowExA(HWND_MESSAGE, hWindow , "CLIPBRDWNDCLASS", NULL); } 

Also note that unlike what is written in the link above, GetParent() does not return HWND_MESSAGE for window messages only (at least not for my tests).

+7
source

My old easy way to ENUMERATE all message-only windows is:

EnumChildWindows (GetAncestor (FindWindowEx (HWND_MESSAGE, 0,0,0), GA_PARENT), addr EnumChildProc, 0)

// GetAncestor (FindWindowEx (HWND_MESSAGE, 0,0,0), GA_PARENT) = "GetMessageWindow" (class "Message")

// GetAncestor (FindWindowEx (HWND_DESKTOP, 0,0,0), GA_PARENT) = GetDesktopWindow (class "# 32769")

+3
source

Source: https://habr.com/ru/post/1399197/


All Articles