Author Topic: Easy DPI awareness  (Read 3813 times)

Jeff

  • Administrator
  • Newbie
  • *****
  • Posts: 40
    • View Profile
Easy DPI awareness
« on: March 04, 2020, 03:16:31 PM »
Since the brute-force approach was so time consuming and ugly, I started something new.  The new approach only requires adding 2 lines of code to simple GUI apps to make them fully PMv2 DPI aware.  No more defining the size of each control and manually handing the resizing during a DPI change.  This is all now handled behind the scenes.  Still needs some work to make it more flexible, but feels like a really good start to me.  And since it's simple to try, I'm hoping more people will be interested.  Looking forward to feedback.

Simple functional example.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/Skeleton.zip

Handful of the standard GUI demos that are now fully DPI aware by adding the two lines of code.  Included comparison pics of each program showing the difference of unaware and PMv2 awareness at 200%.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/GUI_Demos.zip

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1897
    • View Profile
Re: Easy DPI awareness
« Reply #1 on: March 04, 2020, 04:52:47 PM »
Thanks Jeff ... looking forward to see how this tests out ...

mekanixx

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Easy DPI awareness
« Reply #2 on: March 05, 2020, 12:01:09 PM »
Jeff, anything else I need to link with?

Code: [Select]
BcxIDE.c(4868): error #2048: Undeclared identifier 'SM_SERVERR2' (did you mean: SMEXF_SERVER?).
BcxIDE.c(24747): error #2048: Undeclared identifier 'MONITORINFOEX' (did you mean: ?).
BcxIDE.c(24747): error #2001: Syntax error: expected ';' but found 'mi'.
BcxIDE.c(24747): error #2048: Undeclared identifier 'mi' (did you mean: MP_8mm?).
BcxIDE.c(24749): error #2048: Undeclared identifier 'MONITOR_DEFAULTTONEAREST' (did you mean: ?).
...

Thanks,
Doyle

Jeff

  • Administrator
  • Newbie
  • *****
  • Posts: 40
    • View Profile
Re: Easy DPI awareness
« Reply #3 on: March 05, 2020, 01:23:16 PM »
Jeff, anything else I need to link with?

Hi Doyle,

Nothing extra that I know of.  I'm still using an older pwall.bat that was created by bldbat years ago though.  But I haven't had any issues across multiple machines.  Which compiler are you using?  I did not try this with LCC, so there may be some modification required to make it work.  I also haven't tested this new approach with anything other than Win10 yet, so it may require some changes to work on other OSes.

I didn't recognize SM_SERVERR2 as part of my code, so I did a little digging and found that it's part of the OSVERSION function.  But SM_SERVERR2, MONITORINFOEX, and MONITOR_DEFAULTTONEAREST all appear to be defined in winuser.h, and that should be one of the standard includes added by BCX during translation.  I know it shows up in my translated C files anyway.

Please let me know your build environment and I'll see what I can do to help.

Thanks,
Jeff


mekanixx

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Easy DPI awareness
« Reply #4 on: March 06, 2020, 10:52:38 AM »
Hello Jeff,

I'm using the updated Win10 and the latest Pelles C. I really haven't tried this but once. I want to get everything else working first.

Code: [Select]
Compiler flags:
pocc.exe -D_WIN32_WINNT=0x0400 /W0 /Go /Gd /Ze /Zx /MT /Tx86-coff %1.c

Linker flags;
polink.exe /release /machine:ix86 /subsystem:windows %1.obj %PRES% ..\lib\lua5.1.lib /out:..\bin\%1.exe

The _WIN32_WINNT=0x0400 flag may have something to do with it not compiling correctly.

Doyle 

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: Easy DPI awareness
« Reply #5 on: March 07, 2020, 05:29:05 PM »
Since the brute-force approach was so time consuming and ugly, I started something new.  The new approach only requires adding 2 lines of code to simple GUI apps to make them fully PMv2 DPI aware.  No more defining the size of each control and manually handing the resizing during a DPI change.  This is all now handled behind the scenes.  Still needs some work to make it more flexible, but feels like a really good start to me.  And since it's simple to try, I'm hoping more people will be interested.  Looking forward to feedback.

Simple functional example.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/Skeleton.zip

Handful of the standard GUI demos that are now fully DPI aware by adding the two lines of code.  Included comparison pics of each program showing the difference of unaware and PMv2 awareness at 200%.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/GUI_Demos.zip

Hi Jeff:

Thank you for your continuing investigations into this difficult area for Win32 APIs.

I just tried to compile skeleton.bas with Pelle's 32 and 64 and had no luck.

Here's the output from the Pelle's compile

Code: [Select]

Setting 64-bit environment for Pelles C...
Compiling "skeleton.c"..........
skeleton.c(325): error #2095: Expected type for parameter 2, but found 'DEVICE_SCALE_FACTOR'.
skeleton.c(325): warning #2099: Missing type specifier; assuming 'int'.
skeleton.c(325): error #2001: Syntax error: expected ')' but found '*'.
skeleton.c(954): error #2095: Expected type for parameter 2, but found 'DEVICE_SCALE_FACTOR'.
skeleton.c(954): warning #2099: Missing type specifier; assuming 'int'.
skeleton.c(954): error #2001: Syntax error: expected ')' but found '*'.
skeleton.c(959): error #2095: Expected type for parameter 2, but found 'DEVICE_SCALE_FACTOR'.
skeleton.c(959): warning #2099: Missing type specifier; assuming 'int'.
skeleton.c(959): error #2001: Syntax error: expected ')' but found '*'.
skeleton.c(970): error #2048: Undeclared identifier 'pScale' (did you mean: ?).
skeleton.c(1525): error #2048: Undeclared identifier 'DEVICE_SCALE_FACTOR' (did you mean: ?).
skeleton.c(1525): error #2001: Syntax error: expected ';' but found 'pScale'.
skeleton.c(1525): error #2048: Undeclared identifier 'pScale' (did you mean: ?).
skeleton.c(1528): error #2140: Type error in argument 2 to 'GetScaleFactorForMonitor_Dynamic'; expected 'int' but found 'int *'.
Linking ................
POLINK: fatal error: File not found: 'skeleton.obj'.


Microsoft VS 2019 cl.exe compiled O.K. with one warning.

Code: [Select]

Compiling "skeleton.cpp"..........
Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28316 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

skeleton.cpp
skeleton.cpp(1823): warning C4838: conversion from 'int' to 'size_t' requires a narrowing conversion
Linking ................
Microsoft (R) Incremental Linker Version 14.24.28316.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Finished!


Line 1823 is

Code: [Select]

  size_t dimensions[1] = {ciCount};


corresponding to part of the translation of dpi_automate.inc line 19.

Code: [Select]

  GLOBAL DYNAMIC ChildControls[ciCount] AS CtrlInfo


This warning can be eliminated if you cahange the previous line 18 from

Code: [Select]

  GLOBAL ciCount


to

Code: [Select]

  GLOBAL ciCount AS size_t


« Last Edit: March 07, 2020, 05:43:51 PM by Robert »

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: Easy DPI awareness
« Reply #6 on: March 07, 2020, 05:42:49 PM »
Since the brute-force approach was so time consuming and ugly, I started something new.  The new approach only requires adding 2 lines of code to simple GUI apps to make them fully PMv2 DPI aware.  No more defining the size of each control and manually handing the resizing during a DPI change.  This is all now handled behind the scenes.  Still needs some work to make it more flexible, but feels like a really good start to me.  And since it's simple to try, I'm hoping more people will be interested.  Looking forward to feedback.

Simple functional example.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/Skeleton.zip

Handful of the standard GUI demos that are now fully DPI aware by adding the two lines of code.  Included comparison pics of each program showing the difference of unaware and PMv2 awareness at 200%.
https://bcxbasiccoders.com/bcxusers/jeffs/dpi/simple/GUI_Demos.zip

I tried it on my "I Love BCX" Valentine's Day demo and found that, as it is now, your new DPI setup does screw up the fonts, as you explained in the preamble in skeleton.bas. Other than that it seems to function as advertised.

Keep on carrying on.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1897
    • View Profile
Re: Easy DPI awareness
« Reply #7 on: March 07, 2020, 06:04:24 PM »
I think it was extremely courageous of Jeff to name this thread "Easy DPI Awareness".

I'm guessing there are others who see the irony in that decision  :-)



Jeff

  • Administrator
  • Newbie
  • *****
  • Posts: 40
    • View Profile
Re: Easy DPI awareness
« Reply #8 on: March 07, 2020, 08:31:21 PM »
I just tried to compile skeleton.bas with Pelle's 32 and 64 and had no luck.

I've compiled without issue on multiple computers with stock Pelles 9.  Do you have any SDKs installed in Pelles?  It looks like DEVICE_SCALE_FACTOR isn't defined for some reason.  Shtypes.h contains the definition of DEVICE_SCALE_FACTOR.  Shtypes.h should be included by shlobj.h.  And shlobj.h appears to be one of the standard includes in the generated c/cpp file.  Let's start there and see what we can find.


I tried it on my "I Love BCX" Valentine's Day demo and found that, as it is now, your new DPI setup does screw up the fonts, as you explained in the preamble in skeleton.bas. Other than that it seems to function as advertised.

Keep on carrying on.

Ok, great.  Yes, fonts are definitely on my list.  I just wanted to handle the main form and control location/size first.


I think it was extremely courageous of Jeff to name this thread "Easy DPI Awareness".
I'm guessing there are others who see the irony in that decision  :-)

Hey, I had to grab everyone's attention somehow.  :)  "Not as ridiculously difficult DPI Awareness that likely needs some more work" just didn't have the same ring to it. 

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: Easy DPI awareness
« Reply #9 on: March 08, 2020, 12:04:52 AM »
I just tried to compile skeleton.bas with Pelle's 32 and 64 and had no luck.

I've compiled without issue on multiple computers with stock Pelles 9.  Do you have any SDKs installed in Pelles?  It looks like DEVICE_SCALE_FACTOR isn't defined for some reason.  Shtypes.h contains the definition of DEVICE_SCALE_FACTOR.  Shtypes.h should be included by shlobj.h.  And shlobj.h appears to be one of the standard includes in the generated c/cpp file.  Let's start there and see what we can find.


Hi Jeff:

I had Frankie's SDK installed so I uninstalled that and Pelle's and reinstalled Pelle's after manually cleaning out the Pelle's folder. Frankie's uninstaller does not remove everything that was installed with the SDK.

Skeleton.bas now compiles with Pelle's with a few warnings.

Thank you for the suggestions.

Jeff

  • Administrator
  • Newbie
  • *****
  • Posts: 40
    • View Profile
Re: Easy DPI awareness
« Reply #10 on: March 09, 2020, 04:40:49 PM »
I just tried to compile skeleton.bas with Pelle's 32 and 64 and had no luck.

I've compiled without issue on multiple computers with stock Pelles 9.  Do you have any SDKs installed in Pelles?  It looks like DEVICE_SCALE_FACTOR isn't defined for some reason.  Shtypes.h contains the definition of DEVICE_SCALE_FACTOR.  Shtypes.h should be included by shlobj.h.  And shlobj.h appears to be one of the standard includes in the generated c/cpp file.  Let's start there and see what we can find.


Hi Jeff:

I had Frankie's SDK installed so I uninstalled that and Pelle's and reinstalled Pelle's after manually cleaning out the Pelle's folder. Frankie's uninstaller does not remove everything that was installed with the SDK.

Skeleton.bas now compiles with Pelle's with a few warnings.

Thank you for the suggestions.

Hi Robert,

Thank you for the update.  I can only assume we can get this working with Frankie's SDK installed.  I'll see what I can figure out.  Glad to hear standard Pelles is working for you now (with warnings). 

Oh, and thank you for the tip about changing this for Microsoft VS 2019
Code: [Select]
GLOBAL ciCount AS size_t
Jeff