0

I created a script that automatically sets the window size for certain apps. I put it in Startup so it works independetly. I needed this because I have a laptop with 2560x1600 screen resolution and I use it for work. But when I’m at home, I connect it to my Full HD monitor. The problem is that some apps change their size because of different screen resolutions and it’s very annoying to always resize them manually. So I did this:

#Persistent

GroupAdd, ResizedWin, ahk_exe telegram.EXE
GroupAdd, ResizedWin, ahk_exe Discord.EXE
GroupAdd, ResizedWin, ahk_exe WhatsApp.EXE
GroupAdd, ResizedWin, ahk_exe Notepad.EXE

Loop
{
    WinWait ahk_group ResizedWin
        WinMove, , , , , 1417, 915
    WinWaitClose
}

This is the perfect size for these apps for me. But the current problem is that it’s perfect for WQHD resolution. On FHD it is obviously enormous.

My question is, is there any way to correct the window size so it would look the same both on WQHD and FHD displays? It may be important, but when I use FHD monitor, the laptop is closed, so the WQHD display is inactive. And vice versa, when I use WQHD display the FHD monitor isn’t even connected.

What I have already found in WinMove documentation of AHK is this:

CenterWindow(WinTitle)
{
    WinGetPos,,, Width, Height, %WinTitle%
    WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
}

You can see there is an interesting (A_ScreenWidth/2)-(Width/2) and (A_ScreenHeight/2)-(Height/2) for centering the window. So it is somehow possible, but I’m not sure will it work with width and height of the window. What is more important is that I have no idea how to calculate it, like how much should I divide the screen resolution. If it is 1417x915 on 2560x1600, how much it will be on 1920x1080.

So that is just my assumption. Maybe there is another way?

1 Answer 1

0

First assumption is that you're scaling for resolution independent of DPI, so we'll start there. If your DPI is different however (between screens), you may want to take that into account: See A_ScreenDPI

Next, it looks like you're just scaling the window to some percentage of the available resolution, i.e.:

  • 1417/2560=~55%
  • 915/1600=~57%

So to get 1417 for example, when A_ScreenWidth is 2560, the following are all roughly equivalent when they are evaluated:

  • 1417
  • 1417/2560*A_ScreenWidth
  • .55*A_ScreenWidth

So instead of...

WinMove, , , , , 1417, 915

...use one of the equations above and make the new window size a function of your screen resolution:

WinMove, , , , , .55 * A_ScreenWidth, .57 * A_ScreenHeight

This statement above resizes the window to be 55% of the screen width and 57% of the screen height.

If DPI needs to be taken into account then that's another scaling variable with a default value of 96 being typical. You probably don't need to use this if you're just scaling the window to be a percentage of the overall size of your screen, and if your screen DPI is the default value of 96, the new term in this equation below evaluates to "1", and the effective result will be the same as using the code above above without the DPI term.

WinMove, , , , , .55 * A_ScreenWidth * A_ScreenDPI/96, .57 * A_ScreenHeight * A_ScreenDPI/96

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .