• High DPI on Windows with Tk

    From chrischavez@21:1/5 to All on Sat Jun 22 19:10:28 2019
    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.


    This approach works in Perl/Tk as well as modern Tcl/Tk wrappers like Tcl::pTk. Note that although $widget->scaling will be updated correctly, certain elements like images will not be resized automatically and may appear smaller than expected.


    Christopher A. Chavez

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From chrischavez@21:1/5 to chrischavez on Mon Jun 24 15:08:39 2019
    On Saturday, June 22, 2019 at 9:10:30 PM UTC-5, chrischavez wrote:
    if ($^O eq 'MSWin32') {
    use Win32::API;

    Correction: `use Win32::API` should instead be `require Win32::API`. Thanks to Vadim Konovalov for spotting this mistake.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)