WinMove not working in maximized window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

WinMove not working in maximized window

Post by tatagi » 30 Nov 2023, 19:19

I want to move the window to the size and location I decide, but it doesn't work on a maximized window.(notepad, chrome, or any other)

for example:

Code: Select all

^!a::
winmove, ahk_class Notepad,, -20, -15, 1970, 1100
In most cases, that works, but not when notepad is maximized.
winrestore can be used to avoid this problem but it activates even minimized window first then do the winmove, not what I want.

any thoughts would be appreciated.

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

Re: WinMove not working in maximized window

Post by mikeyww » 30 Nov 2023, 19:29

You can restore non-minimized windows. Check the state. You could also choose to restore a window only if it is maximized.

tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: WinMove not working in maximized window

Post by tatagi » 30 Nov 2023, 20:19

I tried this:

Code: Select all

^!a::
WinGet, WinState , MinMax, ahk_class Notepad
if (WinState = 1)
{
winrestore, ahk_class Notepad
winmove, ahk_class Notepad,, -20, -15, 1970, 1100
}
else
winmove, ahk_class Notepad,, -20, -15, 1970, 1100
return
all good, but problem is, minimized window is not resized. again I can use winrestore but it means it will lose its minimized state(it goes active)
so question is, is it possible to keep minimized window intact but just resize it?

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

Re: WinMove not working in maximized window

Post by mikeyww » 30 Nov 2023, 22:04

I'm skeptical, but perhaps a workaround is to adjust the window when you are ready to minimize or display it.

User avatar
V0RT3X
Posts: 243
Joined: 20 May 2023, 21:59
Contact:

Re: WinMove not working in maximized window

Post by V0RT3X » 01 Dec 2023, 08:58

@tatagi, perhaps the Window Resize script from @jrachr can be of use?
viewtopic.php?f=76&t=123313&p=548220&hilit=resize#p548210

It works great and can easily be edited to also position your windows. It will resize and position maximized and minimized windows.
Sadly, I can't help with the keeping the minimized window minimized part.

How I edited the script for myself...

Code: Select all

^T:: 

Resize("ahk_exe notepad.exe" , 1990, 80, 680, 860)        ; <-- Added X & Y.
; Resize("ahk_exe firefox.exe", , , 3850, 2025)
; Resize("ahk_exe thunderbird.exe" , , , 2900, 1600)
Return

;------------------------

Resize(WinTitle, Xpos, Ypos, Width, Height) {        ; <-- Added Xpos & Ypos.
 WinGet Win, List, % WinTitle
 If (Win > 0) {
  Loop % Win {  ; Loop through all matching Windows for this WinTitle
   WinRestore % W := "ahk_id" Win%A_Index%
   WinMove    % W,, Xpos, Ypos, Width, Height        ;  <-- Added Xpos & Ypos.
  }
    MsgBox 64, Resized, % "Resized to " Width " x " Height ":`n`n" WinTitle
 } Else {
    Soundbeep, 800, 200
    MsgBox 48, Error, % "Window was not found.`n`n" winTitle
    }
}
Return

^Home:: 
        Reload
Return

^Esc:: 
        ExitApp
Return

Post Reply

Return to “Ask for Help (v1)”