Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

AutoHotkey: WinMaximize with Instr

Hello experts,
I would like to understand why winmaximize works in some case and not in other case.

WinMaximize is applied as followed:

^+F12::
If(WinActive("ahk_exe chrome.exe"))
{
	WinMaximize
	Return
}
Else
  MsgBox,4144,Error,Google Drive is not the active window
Return

Open in new window


However it doesn't work as followed:
^+F12::
WinGetActiveTitle,Title
If (InStr(Title,"Google Drive"))
{
	WinMaximize
	Return
}
Else
  MsgBox,4144,Error,Google Drive is not the active window
Return

Open in new window

Thank you for your help.
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Hi Luis,

This is well-known issue with AutoHotkey scripts and is documented here:

https://www.autohotkey.com/docs/commands/WinMaximize.htm

Note this comment (copied here under "Fair Use"):
If a particular type of window does not respond correctly to WinMaximize, try using the following instead:
It then proceeds to offer this code:

PostMessage, 0x112, 0xF030,,, WinTitle, WinText  ; 0x112 = WM_SYSCOMMAND, 0xF030 = SC_MAXIMIZE

Open in new window

Give that a spin. Regards, Joe
Avatar of Luis Diaz

ASKER

Sorry for my ignorance but I don't understand the logic. Put instead of WinMaximize windows the line recommended?
^+F12::
WinGetActiveTitle,Title
If (InStr(Title,"Google Drive"))
{
	PostMessage, 0x112, 0xF030,,, WinTitle, WinText  ; 0x112 = WM_SYSCOMMAND, 0xF030 = SC_MAXIMIZE
	Return
}
Else
  MsgBox,4144,Error,Google Drive is not the active window
Return

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tested the following and it works.
^+F12::
WinGetActiveTitle,Title
If (InStr(Title,"Google Drive"))
{
	PostMessage,0x112,0xF030,,,%Title%
	Return
}
Else
  MsgBox,4144,Error,Google Drive is not the active window
Return

Open in new window



Thank you for your help.
Great news! Thanks for letting me know that it works. Regards, Joe