I’m looking for a window that its class name is “CLIPBRDWNDCLASS” (it can be found in office apps 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 that class, so I decided to use recursive EnumChildWindows to enumerate all windows and find the window 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;
}
//-------------------------------------------------------------------------------
The this is that this window does not return by the EnumWindows, only by FindWindow.
Does anyone can tell why it doesn’t work ???
The reason
EnumWindowsdoesn’t work is that the window you are looking for is a message only window.FindWindowExcan find them in two cases:hwndParentandhwndChildAfterare NULL.This code will find all the relevant windows for you (a modified version of a solution from here):
Also note that unlike what’s written in the above link,
GetParent()for message only windows does not returnHWND_MESSAGE(at least not for my tests).