Jump to content

how to use wingetpos with two no windows tittle?


Recommended Posts

IM sure that you do know the process name, once you know that, you can use this piece of script, in my example i use notepad.exe

$searchforprocess = 'notepad.exe'

; Get a list of all existing lists. (stolen function from helpfile)
 Local $aList = WinList()

; Loop through the array displaying only visable windows.
For $i = 1 To $aList[0][0]
    If BitAND(WinGetState($aList[$i][1]), 2) Then
        $process = _ProcessName(WinGetProcess($aList[$i][1]))
        consolewrite($process&@crlf)
        if $process = $searchforprocess Then
            WinActivate($aList[$i][1])
            exitloop
        endif
    EndIf
Next

func _ProcessName($pid)
    if isstring($pid) then $pid = processexists($pid)
    if not isnumber($pid) then return -1
    $proc = ProcessList()
    for $p = 1 to $proc[0][0]
        if $proc[$p][1] = $pid then return $proc[$p][0]
    Next
    return -1
EndFunc

 

Link to comment
Share on other sites

$a = WinList("[CLASS:Windowsforms10.Windows.8.app.0.378734a]")

Might have a typo in there...next time, paste the text, and not screen shots.  Makes life easier for everyone (including yourself not having to add the images to the posts)

edit: if the class changes (I believe they do for windowsforms), you can instaed use REGEXPCLASS:Windowsforms10.*

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.
Link to comment
Share on other sites

Use the snippet I gave you (add it after the new window opens), and then loop through it and find the one where the handle doesn't match the original one.

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.
Link to comment
Share on other sites

Probably using the active window, huh.  Not always reliable.  Or maybe instance based in the 'title'.  Also not always reliable.

You should stick with how you got the first one, and then continue looping until you get the second one.

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.
Link to comment
Share on other sites

Yes! Depend on active windows. Because when I test, WinGetHandle always show the newest handle. 

#include <array.au3>

WinWaitActive("[CLASS:Windowsforms10.Windows.8.app.0.378734a]")
$handle = WinGetHandle("[CLASS:Windowsforms10.Windows.8.app.0.378734a]")
$Pos_Size = WinGetPos($Handle)
_ArrayDisplay($Pos_Size)

I dont know how to use your snippet with many handle will change. (Main application will show 1 handle (change after app open) , create a new section to save will show 1 handle (change after create new section) and each times to press Enter, the handle will change)

Link to comment
Share on other sites

You can use WinList to list all windows matching the specified class :

$aList = WinList("[CLASS:Windowsforms10.Windows.8.app.0.378734a]")

It returns an array. The order of this array depends of how your application works : 
 - If there is a parent window with a child  window, then the row1 will contain values for the child GUI (even if the main window is actived)
 - If each window is a main window (no parent), then the order of the array will correspond to the display order of each window. (active window in row1)

Can you try this code and give us the result ?

#include <Array.au3>
#include <WinAPI.au3>

$aWinList = WinList("[CLASS:Windowsforms10.Windows.8.app.0.378734a]")
Local $aWinInfo[ $aWinList[0][0] ][4]

For $i = 1 To $aWinList[0][0]
    $aPos = WinGetPos($aWinList[$i][1])
    $aWinInfo[$i - 1][0] = $aWinList[$i][0]
    $aWinInfo[$i - 1][1] = $aWinList[$i][1]
    $aWinInfo[$i - 1][2] = "X=" & $aPos[0] & "; Y=" & $aPos[1] & "; W=" & $aPos[2] & "; H=" & $aPos[3]
    $aWinInfo[$i - 1][3] = _WinAPI_GetParent($aWinList[$i][1])
Next
_ArrayDisplay($aWinInfo, "", "", 0, Default, "Title|Hwnd|Position/Size|ParentHwnd")

Also, you can try this example to understand how windows a re ordered :

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>


; example of 3 windows (1 main window with a child, and a second main window)
Local $aGuis[3]
$aGuis[0] = GUICreate("MainGUI", 300, 300, 0, 0)
$aGuis[1] = GUICreate("MainGUI_2", 300, 300, 320, 0)
$aGuis[2] = GUICreate("ChildGUI", 300, 300, 640, 0, -1, -1, $aGuis[0])
GUISetState(@SW_SHOW, $aGuis[0])
GUISetState(@SW_SHOW, $aGuis[1])
GUISetState(@SW_SHOW, $aGuis[2])

;active one of the 3 windows randomly
WinActivate( $aGuis[Random(0, 2, 1)])
ConsoleWrite("Active GUI=" & WinGetTitle("[ACTIVE]"))


$aWinList = WinList("[CLASS:AutoIt v3 GUI]")
Local $aWinInfo[ $aWinList[0][0] ][5]

For $i = 1 To $aWinList[0][0]
    $aPos = WinGetPos($aWinList[$i][1])
    $aWinInfo[$i - 1][0] = $aWinList[$i][0]
    $aWinInfo[$i - 1][1] = $aWinList[$i][1]
    $aWinInfo[$i - 1][2] = "X=" & $aPos[0] & "; Y=" & $aPos[1] & "; W=" & $aPos[2] & "; H=" & $aPos[3]
    $aWinInfo[$i - 1][3] = _WinAPI_GetParent($aWinList[$i][1])
    $aWinInfo[$i - 1][4] = ( WinActive($aWinList[$i][1]) ? 1 : 0)
Next
_ArrayDisplay($aWinInfo, "", "", 0, Default, "Title|Hwnd|Position/Size|ParentHwnd|Active")

Sleep(2000)

 

Edited by jguinch
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...