DanMeow Posted July 24, 2020 Posted July 24, 2020 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: 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
jdelaney Posted July 24, 2020 Posted July 24, 2020 (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 July 24, 2020 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.
DanMeow Posted July 24, 2020 Author Posted July 24, 2020 (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. But I need this whole thing to run scheduled on the server so I don't think anything will become ever active there. Edited July 24, 2020 by DanMeow typo
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now