Reputation: 519
I create a window without showing it:
int main()
{
CreateWindow("SysListView32","Geek",0, 0, 0, 0, 0,NULL, NULL, (HINSTANCE)GetCurrentProcess(), NULL);
getch();
}
...and in another process use FindWindow()
to find its handle:
int main()
{
HWND H = FindWindow("SysListView32", "Geek");
std::cout<< "The handle of created window is : " <<H;
getch();
}
How is FindWindow
finding its handle? I assumed it would not find it, because process1 is not showing the window.
How can I find only visible windows?
Upvotes: 1
Views: 1813
Reputation: 6153
FindWindow finds top-level windows.
While your CreateWindow call is creating a top-level window (i.e. one with no parent) I'm not convinced it will actually work.
It's certainly very unusual (if not wrong) to create a top-level SysListView32. ListView controls should be the children of top-level windows, not top-level windows in their own right.
Upvotes: 0
Reputation: 15164
Even if a window is not visible, it is of course in the list of all existing windows that FindWindow enumerates (you can display this list using Spy++ for example). If you do not want to search for hidden windows, you have to check their flags:
HWND H = FindWindow("SysListView32", "Geek");
if (H) {
LONG style = GetWindowLong(H, GWL_STYLE);
if (style & WS_VISIBLE)
std::cout << "The handle of created visible window is : " << H << std::endl;
else
std::cout << "The handle of created hidden window is : " << H << std::endl;
} else {
std::cout << "No such window found" << std::endl;
}
Upvotes: 6