Main Window v Sub Window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xavier
Posts: 6
Joined: 25 May 2022, 18:20

Main Window v Sub Window

Post by xavier » 17 Aug 2022, 17:11

Is there a generic way to identify a window as a sub window of an app instead of the app main window?

For instance if you run Notepad++, Window Spy will show ahk_class Notepad++ & ahk_exe notepad++.exe & ahk_pid 10220 for the main window, but ahk_class #32770 & ahk_exe notepad++.exe & ahk_pid 10220 for the Find window.

But in Excel it's ahk_class XLMAIN & ahk_exe EXCEL.EXE & ahk_pid 14360 for the main window and ahk_class bosa_sdm_XL9 & ahk_exe EXCEL.EXE & ahk_pid 14360 for the Find window.

I need to be able to identify (and reject/ignore) sub windows.

Any thoughts?

Rohwedder
Posts: 7627
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Main Window v Sub Window

Post by Rohwedder » 18 Aug 2022, 04:25

Hallo,
when starting an app, the main window gets a new PID each time. Its sub-windows then each have the same PID as their main window. It is enough to clearly identify the main windows. Move the cursor over a window and press Q.

Code: Select all

GroupAdd, Main_Window, ahk_class OpusApp ahk_exe WINWORD.EXE
GroupAdd, Main_Window, ahk_class XLMAIN ahk_exe EXCEL.EXE
GroupAdd, Main_Window, ahk_class Notepad++ ahk_exe notepad++.exe
GroupAdd, Main_Window, ahk_class Notepad ahk_exe notepad.exe
GroupAdd, Sub_Window, ahk_exe WINWORD.EXE
GroupAdd, Sub_Window, ahk_exe EXCEL.EXE
GroupAdd, Sub_Window, ahk_exe notepad++.exe
GroupAdd, Sub_Window, ahk_exe notepad.exe
; ...
q::
MouseGetPos,,, ID
IF WinExist("ahk_id " ID " ahk_group Main_Window")
	ToolTip, Main Window
Else If WinExist("ahk_id " ID " ahk_group Sub_Window")
	ToolTip, Sub Window
Else
	ToolTip, ???
Return

xavier
Posts: 6
Joined: 25 May 2022, 18:20

Re: Main Window v Sub Window

Post by xavier » 18 Aug 2022, 09:24

Thanks a lot @Rohwedder
That ALMOST SOLVED my problem!

Your solution works fine as long as you know in advance what classes and exes look like in a Main App Window, but if you don't, how can you tell if it's a Main o Sub/Client Window?

I need some kind of generic solution

Post Reply

Return to “Ask for Help (v1)”