Jump to content

2 windows noob question


Recommended Posts

I have two windows named the same thing. How can i seperate them apart persay, so i can send commands to only one of them. IE:

controlsending stuff. i tried winsettitle but obviously that didnt work right since theres two windows of the same name.

controlsend(......, "", "")

both windows have the same everything. and i know how controlsend works, i just need it to work for a handle, not window title.

Edited by skitt
Link to comment
Share on other sites

I have two windows named the same thing. How can i seperate them apart persay, so i can send commands to only one of them. IE:

controlsending stuff. i tried winsettitle but obviously that didnt work right since theres two windows of the same name.

controlsend(......, "", "")

Just get the handles and use those. The handle stays the same for the life of the window, even if the title changes, and it is completely unique no matter how many similar windows are open.

Demo:

#include <GuiConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $n1 = 0, $n2 = 0

Global $hGUI_1 = GUICreate("Test GUI", 300, 300, 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlCreateLabel("This window's handle = " & $hGUI_1, 20, 20, 260, 20)
Global $ctrlLabel_1 = GUICtrlCreateLabel("n + 1 = 0", 20, 60, 100, 20)
GUISetState()

Global $hGUI_2 = GUICreate("Test GUI", 300, 300, 400, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlCreateLabel("This window's handle = " & $hGUI_2, 20, 20, 260, 20)
Global $ctrlLabel_2 = GUICtrlCreateLabel("n + 5 = 0", 20, 60, 100, 20)
GUISetState()

While 1
    Sleep(500)
    $n1 += 1
    ControlSetText($hGUI_1, "", $ctrlLabel_1, "n + 1 = " & $n1)
    $n2 += 5
    ControlSetText($hGUI_2, "", $ctrlLabel_2, "n + 5 = " & $n2)
WEnd

Func _Quit()
    If @GUI_WinHandle = $hGUI_1 Then
        MsgBox(64, "Quit", "Closed from GUI 1.", 2)
    ElseIf @GUI_WinHandle = $hGUI_2 Then
        MsgBox(64, "Quit", "Closed from GUI 2.", 2)
    EndIf
    Exit
EndFunc  ;==>_Quit

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

what im having trouble with though, is putting the handle in for controlsend(). what i have right now is this. (gives an error)

Global $hwnd = "0x00000000001E0574"
ControlSend($hwnd, "", "", "5")
Link to comment
Share on other sites

what im having trouble with though, is putting the handle in for controlsend(). what i have right now is this. (gives an error)

Global $hwnd = "0x00000000001E0574"
ControlSend($hwnd, "", "", "5")
You would normally get the handle with WinGetHandle(), and you can use the INSTANCE parameter if there is more than one. You could get a list of all matches in an array with WinList(). If you really MUST create the handle from a literal (which rarely makes sense because the handle will be different every time the window is created), then you would use HWnd() to create the correct variant type.
#include <Array.au3>

For $n = 1 To 2
     $hwnd = WinGetHandle("[CLASS:Window_Class; TITLE:Window_Title; INSTANCE:" & $n & "]", "")
     MsgBox(64, "Instance: " & $n, "HWnd = " & $hwnd)
Next

$avHwnd = WinList("[CLASS:Window_Class; TITLE:Window_Title]", "")
_ArrayDisplay($avHwnd, "$avHwnd")

$hwnd = HWnd(0x001E0574)
MsgBox(64, "Literal", "HWnd = " & $hwnd & ", Type = " & VarGetType($hwnd))

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...