1

I am working on how to get the window handle by using the mouse cursor pointing on the window. The problem is I cannot get the button/text 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).

Instead of getting the Btn1, I always get the window which is SysTabControl32, it has the same hierarchy level with Tab1, which means I only can reach the SysTabControl32 (not my desired) and could not reach 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 it just shows that those child windows are exist while the ...FromPoint function still cannot find Tab1 and those child windows.

Does anyone know what is the cause of this situation? It seems like the SysTabControl32 (TabCtrl) is blocking the Tab1 (TabDialog), is it? Or the tab structure created by the developer?

Please help.. Thanks

  • Also, Spy++ is able to highlight Btn1 after I clicked "Highlight" but if I use 'Find Window' function, Spy++ cannot detect Btn1. Does anyone know why Spy++ has this kind of behavior when it apply on the tab? Is the Btn1 is not visible for the 'Find Window' function? – Joshua_0101 Nov 26 '19 at 10:07
  • The tab control is above the button in the window heirarchy so `WindowFromPoint` finds it first. You could try `ChildWindowFromPointEx` with the `CWP_SKIPTRANSPARENT` flag, but I suspect that to find overlapping sibling windows you'd need to enumerate all child windows of the parent and compare the coordinates yourself. – Jonathan Potter Nov 26 '19 at 23:09
  • Hi @JonathanPotter , to enumerate all child windows I can use `EnumChildWindows` but can I know what is the mean by compare the coordinates? What are those coordinates? Any suggestion or example to refer?? Thanks – Joshua_0101 Nov 27 '19 at 01:19
  • Also, if this situation is due to overlapping of window, even I enumerate all the child windows but can the `...FromPoint` function know where is the child window that I pointed by mouse cursor? Since the child window already overlapped by the tab control. Can give me some advise? Thanks. – Joshua_0101 Nov 27 '19 at 01:28
  • `GetWindowRect()` to get the coordinates of each sibling control and see if your point is inside it. – Jonathan Potter Nov 27 '19 at 02:47
  • Do you mean compare the value of `POINT` with `RECT` and check whether the POINT is inside the RECT? I tried several times to apply into my code but it return 0. I am not so clear about how to implement your idea into the coding. – Joshua_0101 Nov 27 '19 at 03:39
  • `if (PtInRect(&rc, pt)) { .. }` – Jonathan Potter Nov 27 '19 at 04:27
  • I found that it may not applicable because even I enumerate all child windows, the _SysTabControl32_ also classify as the child window of _MainWindow_. Since the rectangle of _SysTabControl32_ is bigger than the rectangle of _Button_, although the `POINT` is inside `RECT`, the point is also consider inside the rectangle of _SysTabControl32_ and _Button_. In the end, I still get _SysTabControl32_ instead of _Button_. Is it correct or I misunderstand the idea? – Joshua_0101 Nov 27 '19 at 06:23
  • The idea would be to skip the tab control, or maybe do the enumeration in reverse. It's up to you really. – Jonathan Potter Nov 27 '19 at 06:29
  • I have tried several times for this idea and some other methods, it seems like not achieving the goal. Anyway, thanks a lot for providing the ideas. – Joshua_0101 Dec 02 '19 at 07:04
  • hi,Joshua I can detect the “OK" button I created using spy ++, the [Snapshot](https://i.stack.imgur.com/4x4DX.png) is as follows, but I feel that the tabs I created are different from yours, so please tell me what I need to change. – Strive Sun Dec 03 '19 at 09:06
  • Hi Strive Sun, the tab dialog 000A0C6E and 00280AF0 should be parented to the main dialog (00190A46), not the _SysTabControl32_. – Joshua_0101 Dec 03 '19 at 14:43
  • @Joshua_0101 Sorry, I cannot reproduce your issue.If it's convenient for you, can you provide [a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)? I will appreciate it. – Strive Sun Dec 04 '19 at 09:32

0 Answers0