Jump to content
DanMeow

How to get correct Window Handle (wrong returned after program is run)

Recommended Posts

Hello,

Relating to my previous post I figured out the program (qad client) I started returns wrong handle and that prevents further addressing of controls etc.

This is how I open the qad client and various methods I try to get the handle:
 

Opt("WinTitleMatchMode", 4)

Local $hPID = Run("C:\Program Files (x86)\QAD\QAD Enterprise Applications 2011 SE\QAD.Applications.exe")
Sleep(4000)

Local $hWnd = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.2004eee]")
ConsoleWrite("$hWnd " & $hWnd & @CRLF)
Local $hWnd = WinGetHandle("Prihlášení")
ConsoleWrite("$hWnd " & $hWnd & @CRLF)
Local $hWnd = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.2004eee]","Prihlášení")
ConsoleWrite("$hWnd " & $hWnd & @CRLF)
Local $hWnd = WinGetHandle("[REGEXPTITLE:P*ihl**en*]")
ConsoleWrite("$hWnd " & $hWnd & @CRLF)

Console output (1st is wrong handle, the others don't find anything:

$hWnd 0x005E0986
$hWnd 0x00000000
$hWnd 0x00000000
$hWnd 0x00000000

When I run this function I borrowed from this forum (shows all windows with handles and classes)

$aWindows = WinList()
For $i=1 To $aWindows[0][0]

    ; skip windows without a title
    If $aWindows[$i][0] = '' Then ContinueLoop

    ConsoleWrite($aWindows[$i][0] & ': ')
    ConsoleWrite($aWindows[$i][1]) ;handle
    ConsoleWrite(WinGetClassList($aWindows[$i][1])) ;class
    ConsoleWrite(@CRLF)
Next

 ... I get these (only relevant rows):

Prihlášení: 0x001F0B3AWindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee
WindowsForms10.EDIT.app.0.2004eee
WindowsForms10.Window.8.app.0.2004eee

... so the correct handle should be 0x001F0B3A

This is confirmed by the info tool:
image.thumb.png.68e7d2349b58a2b8f846c805f9344836.png

 

One reason I am thinking of is the eastern european characters in the window title, some of which I cannot reproduce in SciTE.
Another funny thing: If I comment the program run line (2nd line in 1st scrshot) after the client is started, manually click (/activate) the logon screen and then run the script, the first WinGetHandle method starts returning the correct one.

Local $hWnd = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.2004eee]")

The problem is, I want to have this run autonomously on a server on a scheduled basis so activating window is not an option.

Thank you,
Daniel

Share this post


Link to post
Share on other sites
Posted (edited)
Local $hWnd = WinGetHandle("Prihlášení")
ConsoleWrite("$hWnd " & $hWnd & @CRLF)

Ah, you already tried that.  Is the window up and active after the 4 second wait?

It's ugly, but you could just do wingetactive(), which will return the active window's handle.  Or you can get tricky and get all the windows based on your processID

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Posted (edited)

Thank you. 
The window is open in front of others after the 4s wait, so yes, it's active.
I didn't find the winGetActive syntax (some library to include?), but I got the handle using the WinGetTitle as an argument of WinGetHandle.

image.thumb.png.4aabb13cf3cd4b36ab6d21ac3e870e68.png


But I need this whole thing to run scheduled on the server so I don't think anything will become ever active there. 

Edited by DanMeow
typo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...