Winmove will not resize some windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
timg11
Posts: 25
Joined: 10 Dec 2016, 14:09

Winmove will not resize some windows

03 Mar 2020, 15:02

I'm defining a hotkey to reduce window size by 1/2. When moving primary monitor to high-res, Windows doesn't handle DPI scaling very well and many windows end up huge.

This code works for some windows (Firefox for example), but it doesn't work for Windows Explorer windows. Why?
Debugging MsgBox shows correct WinTitle and new size, but WinMove takes no action.

Code: Select all

	
#!h::     ; shrink active window to 1/2 size
	WinGetTitle, WinTitle, A
	WinGetPos, MyX,MyY, WWidth, WHeight, A
	WinRestore, %WinTitle%     ; unmaximize if maximized
  	WWidth := WWidth // 2
	WHeight := WHeight // 2
	MsgBox, For Window %WinTitle% -- new size %WWidth% x %WHeight% 
	WinMove, %WinTitle%,, MyX, MyY, WWidth, WHeight
	return
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Winmove will not resize some windows

03 Mar 2020, 16:45

Works on Window Explorer windows for me. Maybe try running the script as admin.
timg11
Posts: 25
Joined: 10 Dec 2016, 14:09

Re: Winmove will not resize some windows

03 Mar 2020, 19:17

AHK is auto run at startup. How do I tell if it is run as admin or not?
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Winmove will not resize some windows

03 Mar 2020, 19:31

Not AHK. Your script that resizes the windows. Right-click on it and select Run As Admin.
timg11
Posts: 25
Joined: 10 Dec 2016, 14:09

Re: Winmove will not resize some windows

04 Mar 2020, 11:13

This script is a hotkey:

Code: Select all

#!h::  
       .....
It runs from Windows-Alt-H, and is executed from the authohotkey.ahk script that loads at startup. So I need to make that script administrator?

Change the shortcut in "C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" to administrator?
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Winmove will not resize some windows

04 Mar 2020, 11:22

Put this at the top of your script:

Code: Select all

if not A_IsAdmin
{
	try
		Run *RunAs "%A_ScriptFullPath%"
	catch
		MsgBox, 4144, Run As Admin Canceled, The app must be run as administrator.`n`nPlease run again and select "Yes" when asked., 1
    ExitApp
}
timg11
Posts: 25
Joined: 10 Dec 2016, 14:09

Re: Winmove will not resize some windows

27 Mar 2020, 08:50

My script is a hotkey that runs on startup in AutoHotkey.ahk.

Code: Select all

#!h::     ; sHrink active window to 1/2 screen size
	    if not A_IsAdmin
      {
      	MsgBox, 4144, Not Admin , 1
      }
      SysGet, S_MonDim, Monitor
      WinGetTitle, WinTitle, A
	    WinGetPos, MyX,MyY, WWidth, WHeight, A
	    WinRestore, %WinTitle%   ; unmaximize if maximized
	     HalfW := (S_MonDimRight // 2)
	     HalfH := (S_MonDimBottom // 2)
	;     MsgBox, %WinTitle% First win %WWidth% x %WHeight%  mon  %S_MonDimRight% x %S_MonDimBottom%     mondiv  %HalfW% x %HalfH%
     		WWidth := WWidth // 2
	    	WHeight := WHeight // 2
	;     MsgBox, For Window %WinTitle% -- After new size %WWidth% x %WHeight%  mondiv  %HalfW% x %HalfH%

      WinMove, %WinTitle%,, MyX, MyY, WWidth, WHeight
    return
I inserted the check in the code above, and it does in fact display the "Not Admin" MsgBox. So it is not running as admin.

What is "%A_ScriptFullPath%"? Is that something that already exists?
Would the command

Code: Select all

Run *RunAs "%A_ScriptFullPath%"
have the effect of re-starting autohotkey.exe as administrator and re-load AutoHotkey.ahk?
User avatar
boiler
Posts: 16949
Joined: 21 Dec 2014, 02:44

Re: Winmove will not resize some windows

27 Mar 2020, 09:02

timg11 wrote: What is "%A_ScriptFullPath%"? Is that something that already exists?
Yes, it's one AHK's built-in variables. It's the file name of the script itself, including its full path.

timg11 wrote: Would the command

Code: Select all

Run *RunAs "%A_ScriptFullPath%"
have the effect of re-starting autohotkey.exe as administrator and re-load AutoHotkey.ahk?
No, not restarting autohotkey.exe. It restarts only this particular script as admin. If you named this script AutoHotkey.ahk, that's what it restarts (I recommend more specific names for your scripts). It needs to have the check, however, so it only runs it if it's not already in admin mode. You should also place the code in my prior post at the very top -- before the hotkey.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bobak and 298 guests