2
Dim Rectan as RECT: 
GetWindowRect(Hwnd, Rectan)

If Windows font size is set to 100% ==> (Rectan.Right-Rectan.Left) and (Rectan.Bottom - Rectan.Top) give the RIGHT size of a EXTERNAL window.

If the window size is 986x728, I get a size of 986x728. If I copy the window and paste it in Paint, I see a pixel size of 986x728. ALL RIGHT.

But if the Font size is set to 125%, for the same window (that obviously has to be a bit bigger) (Rectan.Right-Rectan.Left) and (Rectan.Bottom - Rectan.Top) get a size of 887x679 (smaller?), while if I copy and paste in Paint, the window I get has a pixel size of 1109x844 pixels.

WHY??? How to get the right size of 1109x844 pixels?

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
ezio
  • 394
  • 3
  • 12
  • 4
    _887 x 1.25 (125%) = 1108.75_, which is rounded up to 1109 (same procedure goes for height). `GetWindowRect` doesn't take DPI scaling into account, so you've got to multiply the size of the resulting rectangle with the current scale factor (like I did in the beginning of this comment). – Visual Vincent Oct 09 '19 at 20:48
  • 2
    Fails is not the same as returning a different value than what you expect. If you provide a valid HWND you have access to, it can't actually fail. – Anders Oct 09 '19 at 21:29
  • 3
    Make your app DPIAware: [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103) – Jimi Oct 09 '19 at 21:38
  • Problem is in the expectation – David Heffernan Oct 09 '19 at 22:30
  • After changing the window font, the size of the windows changes. It may be because the `CreateWindow` specifies `CW_USEDEFAULT`, the system determines the default size of the window. I recommended to specify the `x`,`y`,`nWidth`,`nHeight` of the window, and create a window with DPI Awareness according to DPI change. – Drake Wu Oct 10 '19 at 05:58

0 Answers0