I am working on getting
hwnd
by using the mouse cursor pointing on button. The problem is I cannot reach the button which is inside a tab dialog.
I used Spy++ to get the hierarchy, there are 3 layers to reach the desired button.
MainWindow (#32770) -
Tab1 (#32770) -
Btn1 (Button). It shows that
Tab1 is not parented to
SysTabControl32 and have the same parent window with
SysTabControl32.
Instead of getting the
Btn1, I always get
SysTabControl32, which has the same hierarchy level with
Tab1, means that I only can reach the
SysTabControl32 but not the
Tab1.
If I used
WindowFromPoint
and point my mouse on
Btn1, I will get
SysTabControl32; using
ChildWindowFromPoint
, I will get 0 as return value; using
RealChildWindowFromPoint
, I will get
SysTabControl32.
Spy++ only can detect
MainWindow,
SysTabControl32 and
Tab1 but it cannot detect
Btn1. I can get all the child windows by using
EnumChildWindow
but the
...WindowFromPoint
function still cannot find
Tab1 and those child windows. Also, Spy++ is able to highlight
Btn1 after I "Highlight" it but if I use 'Find Window' function in Spy++,
Btn1 cannot be detected.
Is it the reason is the
overlapping of sibling windows? It seems like
SysTabControl32 is keep blocking the
...WindowFromPoint
function to get the child windows. Does anyone know what is the cause of this situation and how to solve it? Please help..Thanks
What I have tried:
#include<windows.h>
#include<iostream>
using namespace std;
int main() {
POINT pt;
Sleep(3000);
GetCursorPos(&pt);
HWND hWnd = WindowFromPoint(pt);
HWND hWndParent = GetParent(hWnd);
MapWindowPoints(NULL, hWndParent, &pt, 1);
HWND hWndChild = RealChildWindowFromPoint(hWndParent,pt);
char class_name[100];
char title[100];
GetClassNameA(hWndChild,class_name, sizeof(class_name));
GetWindowTextA(hWndChild,title,sizeof(title));
cout <<"Window name : "<<title<<endl;
cout <<"Class name : "<<class_name<<endl;
cout <<"hwnd : "<<hWndChild<<endl<<endl;
system("PAUSE");
return 0;
}