develooper Front page | perl.tcltk | Postings from June 2019

High DPI on Windows with Tk

Thread Next
From:
Christopher Chavez
Date:
June 23, 2019 02:10
Subject:
High DPI on Windows with Tk
Message ID:
3B4E27E0-7AA8-47FB-8662-6167CFFD487E@gmx.us
Hi everyone,

I wanted to share a way for using high-DPI appearance on Windows that I found, in case anyone was interested. I have posted it to 
https://www.perlmonks.org/?node_id=11101747


Before calling MainWindow->new in Tk, use Win32::API to invoke SetProcessDPIAware():

if ($^O eq 'MSWin32') {
   use Win32::API;
   # See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setprocessdpiaware
   my $SetProcessDPIAware = Win32::API::More->new('User32', 'BOOL SetProcessDPIAware()');
   $SetProcessDPIAware->Call() or warn 'Failed to set process DPI awareness';
}


This isn't the approach Microsoft recommends (they suggest using an application manifest instead), but this seems to be an easy enough approach for standalone scripts.


Recent Tcl/Tk will enable high-DPI by default for scripts run using tclsh/wish, but not the Tcl C API. I'm not sure this behavior should be the default in Tcl::pTk, for compatibility (i.e. since Perl/Tk does not enable high-DPI) and because certain elements like images will not be resized automatically.

Maybe Tcl::Tk would be more in favor of having this behavior by default (for consistency with Tcl/Tk), but it might require XS or dependency on another module like Win32::API.


Christopher A. Chavez

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About