Scale WIndows Display

82 views
Skip to first unread message

The Rickster

unread,
Dec 27, 2022, 3:10:07 PM12/27/22
to
Need: programmatically change Windows scaling percentage.
Background:
Windows Display Settings provides for one to manually change the display scaling.
The value of the current pixels per point is accessible with the tcl command 'tk scaling'. However, using this command does not change the windows scaling factor (as described in the docs). I was unable to locate a command in the twapi package that would do so.
Would appreciate any insight as to how one might change the Windows scaling percentage value.

Rich

unread,
Dec 27, 2022, 6:19:58 PM12/27/22
to
The Rickster <sled...@gmail.com> wrote:
> Need: programmatically change Windows scaling percentage.
> Background:
> Windows Display Settings provides for one to manually change the display scaling.

> The value of the current pixels per point is accessible with the tcl
> command 'tk scaling'. However, using this command does not change
> the windows scaling factor (as described in the docs).

Where in the docs do you see that "tk scaling" would change the windows
system scaling setting? The docs say "Sets and queries the current
scaling factor used by Tk to convert between physical units (for
example, points, inches, or millimeters) and pixels."

The very important part of that sentence is "used by Tk" -- note this
is not saying "used by ms-windows".

> I was unable to locate a command in the twapi package that would do
> so.

If there is none in twapi, you might have no way to do so from inside a
Tcl script.

> Would appreciate any insight as to how one might change the Windows
> scaling percentage value.

Use the Windows Control Panel.

If you meant to add "... from a Tcl script" then there may be no way to
do so.

And, myself, I'd be most pertubed at a windows program that decided it
was going to change the system scale factor unilaterally. That value
impacts all running programs on the system, not just a single app that
wants to mess around with it. My preference would be: "programs do not
change that value, ever".

The Rickster

unread,
Dec 28, 2022, 10:29:02 PM12/28/22
to
Suggest you read and reinterpret what I wrote; which expressed a clear understanding of the functionality of tk scaling. Thanks for the response. However I was asking for a solution; not an opinion - which contains spelling errors that perturb me.
So, do you know whether or not twapi offers the needed functionality?
Do you know of a Windows com object\interface that provides for the needed functionality?

Ashok

unread,
Dec 29, 2022, 6:57:07 AM12/29/22
to
On 12/29/2022 8:59 AM, The Rickster wrote:
> So, do you know whether or not twapi offers the needed functionality?
> Do you know of a Windows com object\interface that provides for the needed functionality?

twapi does not directly offer this and afaik there is no documented
interface.

However, take a look at
https://github.com/lihas/windows-DPI-scaling-sample, in particular the
one using SystemParametersInfo. You may be able to adapt that using
either twapi::SystemParametersInfo or the CFFI package
(https://cffi.magicsplat.com).

I don't have time to try it myself so no guarantees and use at your own
risk :-)

/Ashok

Mole Cool

unread,
Dec 29, 2022, 8:03:21 AM12/29/22
to
I had similar issues with one application. But if you would be able to change the Windows Scaling, and the event is fired to all running apps, what is the benefit for you.

I ended up, with a couple of calculations at the beginning. Next I scaled my used fonts, but you have still an issues if you interface will have label/button images. You need to have them in a couple of dimensions. As far I understand the Microsoft Solution, if you have a font height of 12 and your scale 150%, MS would use 16 instead. Next don't forget you may have multiple screens, with different scale values as well.

The winfo command, with dpi calculation is a little bit misleading. As far I see, on my computer for example 'winfo pixels . 1i' will return 144. But my screen has ~190 Dots per Inch (2.520 x 1.680 with 16 inch diagonal, tk scale returns here 1.99775, and MS set the factor to 150%)

The registry value HKCU/Control Panel/Desktop/WindowMetrics/AppliedDPI is set to 144 (same as winfo pixels . 1i returns)

Yes, you ask for a solution, but it's not that simple :-(

I reviewed also 'Windows scaling issues for high-DPI devices' at support MS, you may check the DPI Awareness section.

Mole Cool

unread,
Dec 29, 2022, 8:09:52 AM12/29/22
to
On the same PC I run an old 8.4 App, here 'tk scaling' returns 1.3333 and the whole fonts looks blurry, I change the tk scaling to 1.5, and it looks better, but not perfect. If I move to a HD Display, it looks much better, so it is tricky.

The Rickster

unread,
Dec 29, 2022, 11:26:13 PM12/29/22
to
First, thanks for the response. The why or benefit is this: our product enables licensee developers to build visual simulicrums of their (not our) desktop applications. It provides for the management of their users haptic and verbal interaction with those applications. Hence, they desire to manage some of the underlying os settings. To that end, our applications enable them to perform and evaluate usability and effectiveness of the applications they simulate with our code. To wit, an airline licensed the software to develop and test simulicrums of airport kiosk self ticketing interactions.

The Rickster

unread,
Dec 30, 2022, 1:56:13 AM12/30/22
to
Hello and thank you so much. The user may now, with the use of our speech rec component, verbally change the dpi setting of their system. As an side, we use SAPI text-to-speech in order to debug tcl scripts. It is sometimes more efficient to hear the value of variables as they are modified, or to be notified audibly when a proc is entered or exited. Be glad to give a snippet of the tcom code to anyone interested.
Reply all
Reply to author
Forward
0 new messages