Getting Window Handle

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
CatoSecundus
Posts: 7
Joined: 05 Jun 2023, 04:11

Getting Window Handle

Post by CatoSecundus » 05 Jun 2023, 04:38

Hello all!

I am not exactly a n00b but I am a n00b to AHK V2.0, so please excuse a simple question.

If I try to open multiple Explorer windows or Chrome windows or Firefox windows, using the following code, I get an active window (I think so because it keeps blinking on the taskbar) but I cannot get it to come to the top/front.

Code: Select all

RunWait(A_WinDir . "\explorer.exe " . FolderPath , , , &OutputVarPID)
Between multiple windows, I have noticed that the ahk_class, ahk_exe, and ahk_pid maybe the same but the ahk_id (or Window Handle) is always different. How do I capture the Window Handle when opening a new window?

User avatar
mikeyww
Posts: 26944
Joined: 09 Sep 2014, 18:38

Re: Getting Window Handle

Post by mikeyww » 05 Jun 2023, 05:15

Welcome to this AutoHotkey forum!

There are various ways.

1. WinMinimize the other similar windows first (GroupAdd). After you open the new window, you can WinWaitActive and then use WinActive.

2. You can Loop until the number of that type of window increases (WinGetList), and then use WinExist.

I'm sure that there are more ways.

Code: Select all

; This script gets the HWND of a new window
#Requires AutoHotkey v2.0
app      := A_WinDir '\explorer.exe'
winTitle := 'ahk_exe' app
GroupAdd 'win', winTitle

F3:: {
 WinMinimize 'ahk_group win'
 Run app
 hWnd := WinWaitActive(winTitle)
 MsgBox hWnd, 'HWND'
}
Possibly:

Code: Select all

; This script gets the HWND of a new window
#Requires AutoHotkey v2.0
app      := A_WinDir '\explorer.exe'
winTitle := 'ahk_class CabinetWClass'

F3:: {
 WinActivate 'ahk_class Progman'
 Run app
 hWnd := WinWaitActive(winTitle)
 MsgBox hWnd, 'HWND'
}

Post Reply

Return to “Ask for Help (v2)”