Maximize only main window, not its scalable submenus.

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 229
Joined: 10 Mar 2016, 21:19

Maximize only main window, not its scalable submenus.

18 Jun 2016, 01:22

Hello.

I have created a simple code to maximize the main window of a bunch of apps, with the IfWinActive, WinMaximize, GroupAdd commands.
the script works fine but there is an annoying problem with some of those apps:
their right click context menu popups share the same WinTitle attributes with the main window (title,class,exe), and as a result they get maximized too. some apps with this problem are uTorrent,Jdownloader2,Origin,Steam,etc.

is there a general method I can use to avoid this problem with the maximized popups? some way for the AHK to distinguish the main window from its popups?
I tried and set the condition for the maximization to be applied on windows which have a size larger than 300x300, but still there are some instances where the popups are bigger than the restriction and become maximized.
So I am looking for a better solution. :|
Last edited by KilliK on 14 Jan 2017, 06:21, edited 1 time in total.
just me
Posts: 7243
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Maximize only main window, not its context menus.

18 Jun 2016, 03:26

Are you sure about the class?
KilliK
Posts: 229
Joined: 10 Mar 2016, 21:19

Re: Maximize only main window, not its context menus.

14 Jan 2017, 06:19

I am bumping this because I really need to find a solution, because the problem is not limited only to context menus but also to any other window which opens from the main window and is scalable, like the tools windows from Chrome.

And to answer the previous question, yes, the class is the same. for example, for Chrome I use this:

Code: Select all

SetTimer, check, 500
return

check:
if WinActive("Google Chrome ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe ")
WinMaximize A
return
if I press Shift+Esc, it opens Chrome's Task Manager which also becomes maximized, which I want to avoid. It shares the same title,class and process with Chrome's main window.
So, how I can fix this for all those apps with scalable submenus which share the same window info? or is it impossible?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Maximize only main window, not its scalable submenus.

14 Jan 2017, 17:34

No, there's absolutely no way of doing this, it's impossible.
(I'm so used to the doom talk on Stack Overflow!)
Actually ...

try getting the window styles for the windows:

Code: Select all

WinGet, vWinStyle, Style, % "ahk_id " hWnd
WinGet, vWinExStyle, ExStyle, % "ahk_id " hWnd
perhaps getting the class of the parent window will distinguish between them:

Code: Select all

DetectHiddenWindows, On
hWndParent := DllCall("user32\GetAncestor", Ptr,hWnd, UInt,1, Ptr) ;GA_PARENT = 1
hWndOwner := DllCall("user32\GetWindow", Ptr,hWnd, UInt,4, Ptr) ;GW_OWNER = 4
WinGetClass, vWinClass, % "ahk_id " hWndParent
WinGetClass, vWinClass, % "ahk_id " hWndOwner
if one window has an Edit1 control, for example, but the other doesn't,
hCtl will be blank if the control doesn't exist:

Code: Select all

ControlGet, hCtl, Hwnd,, Edit1, % "ahk_id " hWnd
get control information from each window, to find differences:

Code: Select all

q::
WinGet, hWnd, ID, A
WinGet, vCtlList, ControlList, % "ahk_id " hWnd
vOutput := ""
Loop, Parse, vCtlList, `n
{
	;ControlGet, hCtl, Hwnd,, % A_LoopField, % "ahk_id " hWnd
	ControlGetText, vText, % A_LoopField, % "ahk_id " hWnd
	;ControlGet, vIsVisible, Visible,, % A_LoopField, % "ahk_id " hWnd
	ControlGet, vStyle, Style,, % A_LoopField, % "ahk_id " hWnd
	ControlGet, vExStyle, ExStyle,, % A_LoopField, % "ahk_id " hWnd

	vText := StrReplace(vText, "`r", " ")
	vText := StrReplace(vText, "`n", " ")
	vText := SubStr(vText, 1, 500)

	if (vText = "")
		vOutput .= A_LoopField " " vStyle " " vExStyle "`r`n"
	else
		vOutput .= A_LoopField " " vStyle " " vExStyle " " vText "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
get information via Acc library / AccViewer.

Note: wow, even the class is the same!?

[EDIT:]
title: Safe Search - Google Chrome
style: 0x16CF0000
ExStyle: 0x00000100

title: Task Manager - Google Chrome
style: 0x16CF0080
ExStyle: 0x00000101

both had:
class: Chrome_WidgetWin_1
class of parent: #32769
class of owner: (blank)
no controls
Last edited by jeeswg on 09 May 2017, 02:59, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
KilliK
Posts: 229
Joined: 10 Mar 2016, 21:19

Re: Maximize only main window, not its scalable submenus.

15 Jan 2017, 10:24

thank you very much for your help, jeeswg.

one question.
how did you get the class of parent/owner for Chrome?
I used the script you provided but vWinClass gives me blank in both cases. I checked WndParent and WndOwner and they get 0 when I apply the script for Chrome.
how did you come up with
class of parent: #32769
class of owner: (blank)
?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Maximize only main window, not its scalable submenus.

15 Jan 2017, 13:27

That should do it:

Code: Select all

q::
DetectHiddenWindows, On
WinGet, hWnd, ID, A
WinGetTitle, vWinTitle, % "ahk_id " hWnd
WinGetClass, vWinClass, % "ahk_id " hWnd
WinGet, vWinStyle, Style, % "ahk_id " hWnd
WinGet, vWinExStyle, ExStyle, % "ahk_id " hWnd
hWndParent := DllCall("user32\GetAncestor", Ptr,hWnd, UInt,1, Ptr) ;GA_PARENT = 1
hWndOwner := DllCall("user32\GetWindow", Ptr,hWnd, UInt,4, Ptr) ;GW_OWNER = 4
WinGetClass, vWinClassP, % "ahk_id " hWndParent
WinGetClass, vWinClassO, % "ahk_id " hWndOwner

vOutput = ;continuation section
(Join`r`n
title: %vWinTitle%
class: %vWinClass%
style: %vWinStyle%
ExStyle: %vWinExStyle%
class (parent): %vWinClassP%
class (owner): %vWinClassO%
)
Clipboard := vOutput
MsgBox, % vOutput
return
Last edited by jeeswg on 09 May 2017, 03:02, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Maximize only main window, not its scalable submenus.

15 Jan 2017, 13:47

- If you're looping through windows, lines like the first pair, or the second pair below, might help to identify a window to skip.
- I don't know the significance of window style 0x80, so I would probably use the first pair which checks for extended window style 0x1.
- I noticed that 'Task Manager - Google Chrome' has its own taskbar button.
- I might use AccViewer to help find other identifying information.

Code: Select all

if (vWinClass = "Chrome_WidgetWin_1") && (vWinExStyle & 0x1) ;WS_EX_DLGMODALFRAME := 0x1
	continue

if (vWinClass = "Chrome_WidgetWin_1") && (vWinStyle & 0x80)
	continue
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], DanRim, roguekhinkali and 70 guests