Find the Handle of the window at the top of the screen
Asked Answered
V

3

6

I want to check when the window of an external application (a Poker On Line Game Table) jumps over all other windows because it's my turn to play.

The problem is that the Game table jumps in the foreground... but the window DOES NOT BECOME ACTIVE... this means that I can't check if it is jumped over all the other visible windows by the API GetForegroundWindow (and in fatc this API continue to return the Handle of the previous window, also if it is UNDER the Game Table that is jumped over ALL the desktop windows). Also the GetTopWindow API don't works.

Now the question is: how to find the handle of the top VISIBLE window (the window that is over all the other open windows for my eyes) also if it is not active???


No, the Window IS NOT a TopMost window: in fact if I click on another window it goes in background. If it should be a TopMost window it would remain on the top.

Probably it is put in the foreground by a WM_SHOW or WM_NOACTIVATE flag.

Volpe answered 25/8, 2012 at 21:10 Comment(1)
+1 Welcome to Stack Overflow, nice first question!Herculie
H
0

The poker application must use a Win32 API such as SetForegroundWindow(hWnd) to bring the window to the Top when its your turn.

In order to detect such a call you can use Windbg Script Tracing API calls

You can use it to see the APIs an application is using from your Windbg screen without using another tool. If you need more details from the APIs, just execute LogViewer.exe and open the .lgv file that is automatically created when you use this script.

enter image description here

enter image description here

Output file, with .LGV extension.

enter image description here

LogViewer.exe is part of Debugging Tools For Windows. It's in the same location you installed Windbg. Open the .LGV file using LogViewer.exe:

enter image description here

Source code for API_TRACING.TXT:

$$
$$ =============================================================================
$$ Trace APIs during the Debugging Session. 
$$ Creates a log on Desktop and Windbg window.
$$ To see the more verbose log run logviewer.exe from Debugging Tools for Windows
$$ and open the file that has the .lgv extension.
$$ This file is inside LogExts on your desktop.
$$
$$ Compatibility: Win32, should work on Win64.
$$
$$ Usage: $$>< to run the program.
$$
$$ Roberto Alexis Farah
$$ Blog: blogs.msdn.com/debuggingtoolbox/
$$
$$ All my scripts are provided "AS IS" with no warranties, and confer no rights.
$$ =============================================================================
$$
!logexts.loge
!logexts.logc e *
!logexts.logo e v
!logexts.logb p
$$
$$ ====================================
$$ Logging is enabled for this process.
$$ ====================================

Once you have all this info, you will know what API call to look out for from a particular caller/DLL/etc and that is the time its your turn, the poker window is ontop and you can use this KB article to Find the Handle of the TopMost Window

Herculie answered 26/8, 2012 at 3:38 Comment(3)
>Once you have all this info, you will know what API call to look out for from a particular caller/DLL/etc and that is the time its your turn.... HOW to check???? By dll injection??? I don't know how to make dll injection >Find the Handle of the TopMost Window..... It IS NOT a TopMost window!Volpe
Calm down. Chill with all the question marks and caps, ok? In code you need to poll the logs and debugger to recognize the Win32 API event that the poker app calls. If you want help here, please be nice to people who are volunteering to help youHerculie
Not nice? Sorry... my original language IS NOT english, I try my better.Volpe
C
2

EnumWindows and possibly WindowFromPoint API functions. You can use them via P/Invoke in your VB.NET application and be able to find windows either in top to bottom order (EnumWindows) checking their location, caption etc on the way to identify the window of your interest, or directly locate the window at certain position (WindowFromPoint; I thought your window of interested might be popping up in the center of the screen, or centered by another window you already know or you can easily find it by its caption - this way you know the point of your interest on the screen already).

Corridor answered 26/8, 2012 at 8:0 Comment(5)
Ty Roman, but Your idea don't works IN THIS CASE. Yes it's true: by EnumWindows I can get the Windows Handles in top to bottom order... but when the Game Table jumps in the foreground THE WINDOW IS NOT ACTIVATE, so the z order don't changes. If I put (for example) Notepad over the table, when the table jumps in foreground THE FIRST HANDLE IS ALWAYS THE NOTEPAD HANDLE, since Notepad remains the active window.Volpe
WindowFromPoint.... I have 6-8 tables in different position of the screen. I would have to chek them positions by WindowRect and check 5-6 points for every tabe to be sure that is on top... I will try, but I fear the WindowFromPoint API finds the Handle of the ACTIVE Window under that point.Volpe
The WindowFromPoint function DOES NOT retrieve a handle to a hidden or DISABLED window, even if the point is within the window. DISABLED WINDOW: a window that does not receive input such as mouse clicks and key presses... and the Table when jumps in foreground does NOT receive input, since is not activate.Volpe
WindowFromPoint is one of the family of fucntions (simplest). ChildWindowFromPointEx does disabled, invisible and transparent windows as well.Corridor
Yes, I have seen, ty... but there is another reason because I can't use a WindowFromPoint family API. If someone has a BIG monitor and opens 4 game tables without to put one on the other... I can't know if one of the 4 tables needs action, because ChildWindowFromPoint "see" all the tables on the top of the screen, without any overlapping...Volpe
A
1

Sounds like the app may be using SetWindowPos(..., HWND_TOPMOST, ...) to become a topmost window. Windows that are positioned this way don't have to be active to appear on top.

In that case, you can try using GetWindow(..., GW_HWNDFIRST) to find the topmost window in the window manager's z-order. See http://support.microsoft.com/kb/126386 for a short code snippet that does this.

Agnostic answered 26/8, 2012 at 3:47 Comment(3)
I was looking for that kb article! When do you know when to call it? I'm thinking you would manually get the Window Handle and then from constant polling when ever the handle is returned from the API call you know the poker app is ontop?Herculie
No, the window IS NOT a TopMost window.Volpe
A window that is not activate NEVER is first in z order, also if it is FOR THE EYES the top window... The first window in Z order is the window that receives the input (the Foreground window).Volpe
H
0

The poker application must use a Win32 API such as SetForegroundWindow(hWnd) to bring the window to the Top when its your turn.

In order to detect such a call you can use Windbg Script Tracing API calls

You can use it to see the APIs an application is using from your Windbg screen without using another tool. If you need more details from the APIs, just execute LogViewer.exe and open the .lgv file that is automatically created when you use this script.

enter image description here

enter image description here

Output file, with .LGV extension.

enter image description here

LogViewer.exe is part of Debugging Tools For Windows. It's in the same location you installed Windbg. Open the .LGV file using LogViewer.exe:

enter image description here

Source code for API_TRACING.TXT:

$$
$$ =============================================================================
$$ Trace APIs during the Debugging Session. 
$$ Creates a log on Desktop and Windbg window.
$$ To see the more verbose log run logviewer.exe from Debugging Tools for Windows
$$ and open the file that has the .lgv extension.
$$ This file is inside LogExts on your desktop.
$$
$$ Compatibility: Win32, should work on Win64.
$$
$$ Usage: $$>< to run the program.
$$
$$ Roberto Alexis Farah
$$ Blog: blogs.msdn.com/debuggingtoolbox/
$$
$$ All my scripts are provided "AS IS" with no warranties, and confer no rights.
$$ =============================================================================
$$
!logexts.loge
!logexts.logc e *
!logexts.logo e v
!logexts.logb p
$$
$$ ====================================
$$ Logging is enabled for this process.
$$ ====================================

Once you have all this info, you will know what API call to look out for from a particular caller/DLL/etc and that is the time its your turn, the poker window is ontop and you can use this KB article to Find the Handle of the TopMost Window

Herculie answered 26/8, 2012 at 3:38 Comment(3)
>Once you have all this info, you will know what API call to look out for from a particular caller/DLL/etc and that is the time its your turn.... HOW to check???? By dll injection??? I don't know how to make dll injection >Find the Handle of the TopMost Window..... It IS NOT a TopMost window!Volpe
Calm down. Chill with all the question marks and caps, ok? In code you need to poll the logs and debugger to recognize the Win32 API event that the poker app calls. If you want help here, please be nice to people who are volunteering to help youHerculie
Not nice? Sorry... my original language IS NOT english, I try my better.Volpe

© 2022 - 2024 — McMap. All rights reserved.