I need to know if the window handle I got from WinExist("A") is one of the windows I created in my script via the GUI commands...
I could make a list of handles of windows I spawned to compare with but if there is a sure way to do it in a few ahk functions... that would spare me the list management implementation; the need to add and remove entries from the window list as they are created and destroyed.
The method should determine if the hwnd is from my script and not from any another ahk script that may be running at the same time
The method should work for when in the ahk runner, all version (32b,64b, ansi, unicode) and in the compiled version (.exe)
Is the hwnd from WinExis("A") Mine? Topic is solved
-
- Posts: 202
- Joined: 14 Aug 2016, 04:08
Re: Is the hwnd from WinExis("A") Mine?
Code: Select all
#NoEnv
Gui, +HwndHGUI
Gui, Show, w400 h400, Test
MyPID := DllCall("GetCurrentProcessId")
MyGUIs := "ahk_class AutoHotkeyGUI ahk_pid " . MyPID
If (HWND := WinActive(MyGUIs))
MsgBox, % "Bingo! " . HGUI . " - " . HWND
ExitApp
Re: Is the hwnd from WinExis("A") Mine? Topic is solved
Another option:
Code: Select all
#NoEnv
Gui, +HwndHGUI
Gui, Show, w400 h400, Test
MyPID := DllCall("GetCurrentProcessId")
If (HWND := WinExist("A")) {
WinGetClass, Class
WinGet, PID, PID
If (Class = "AutoHotkeyGUI") && (PID = MyPID)
MsgBox, % "Bingo! " . HGUI . " - " . HWND
Else
MsgBox, % "Nada! The window " . HWND . " doesn't belong to this script!"
}
ExitApp
-
- Posts: 202
- Joined: 14 Aug 2016, 04:08
Re: Is the hwnd from WinExis("A") Mine?
Bingo indeed.
So this gets the process id of this running instance, generates a search, to use in WinActive, for a window of class AutoHotkeyGUI AND of/in process id of this instance
Clever! It works!
Thank you
So this gets the process id of this running instance, generates a search, to use in WinActive, for a window of class AutoHotkeyGUI AND of/in process id of this instance
Clever! It works!
Thank you
-
- Posts: 202
- Joined: 14 Aug 2016, 04:08
Re: Is the hwnd from WinExis("A") Mine?
Hmm, is the class name required? Is is not enough to simply check the PID?
Re: Is the hwnd from WinExis("A") Mine?
Hwnd is unique. Why not hgui == winactive("a") ? I'm on the phone so reading the codeboxes is slightly awkward, sorry if I missed the point.
Cheers.
Cheers.
Re: Is the hwnd from WinExis("A") Mine?
You might omit the class if you want to match non-GUI windows like MsgBox, ToolTip, InputBox, etc. too.
Re: Is the hwnd from WinExis("A") Mine?
Sorry, I missed the point it seems . Nice approach just me
Alternative,
Cheers.
Alternative,
Code: Select all
gui, new ,+hwndA
gui,show, w200 h200
gui, new ,+hwndB
gui,show, w200 h200
myGuiHandles := {(A):A,(B):B}
f1::msgbox % myGuiHandles.hasKey(winactive("A")) ? "My gui!" : "Not my gui"
guiclose(hwnd){
global myGuiHandles
myGuiHandles.delete(hwnd)
gui % hwnd ": destroy"
}
Who is online
Users browsing this forum: No registered users and 398 guests