Search code examples
vb.netwinapitopmost

Find the Handle of the window at the top of the screen


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.


Solution

  • 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