Announcement

Collapse
No announcement yet.

Graphic Get PPI in Windows 10

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphic Get PPI in Windows 10

    In Windows 7 you could set icons to be 100%, 125% or 150%. When using GRAPHIC GET PPI in Windows 7 100% returned 96, 125% returned 120 and 150% returned 144. I don't know if it was correct or not but I used these numbers to change my program fonts, buttons and etc. so they looked almost the same no matter how they had their display set. It seems in Windows 10 it doesn't matter if you set on 100%,125%,150% or 175% the Power Basic GRAPHIC GET PPI always returns 96. I know all of you do a much better job than this on programming but can someone instruct me on how to make your program look almost the same no matter how the user sets his display in Windows 10.

    Thanks in advance you all are always so very helpful to us beginners
    Leroy
    Last edited by Leroy Hindman; 2 May 2021, 02:44 PM.

  • #2
    Never tried doing it in Win10, but another way to check ppi is via GetDeviceCaps, so could always try and compare with what this returns (96 96 in my standard system). What compiler version are you using? (like 10.03, etc). Also, are you sure you have found and used the correct way to set ppi? Since I got Win10, I'm totally lost in MS ways to hide settings..
    '
    Code:
      LOCAL hDC AS DWORD
      hDC = GetDC(%HWND_DESKTOP)
        MSGBOX STR$(GetDeviceCaps(hDC, %LOGPIXELSX)) + STR$(GetDeviceCaps(hDC, %LOGPIXELSY))
      ReleaseDc(%HWND_DESKTOP, hDC)
    '

    Comment


    • #3
      Found out "how-to" and tried it just for fun - there's nothing wrong with the ppi functions, so it must be something else. Changed desktop settings to 125% and got ppi = 120 for all. Compiler version 10.03. Now I "only" need to find my way back to normal settings again..
      '
      Code:
      #INCLUDE "WIN32API.INC"
      FUNCTION PBMAIN () AS LONG
        LOCAL hDC, hDlg AS DWORD
      
        DIALOG NEW 0, "ppi Test",,, 220, 140, %WS_SYSMENU, 0 TO hDlg
        CONTROL ADD GRAPHIC,  hDlg, 120, "", 0, 0, 5, 5
        GRAPHIC ATTACH hDlg, 120
      
        hDC = GetDC(%HWND_DESKTOP)
          MSGBOX STR$(GetDeviceCaps(hDC, %LOGPIXELSX)) + _
                 STR$(GetDeviceCaps(hDC, %LOGPIXELSY)) + $CRLF + _
                 STR$(GRAPHIC(PPI.X)) + STR$(GRAPHIC(PPI.Y))
        ReleaseDc(%HWND_DESKTOP, hDC)
      
      END FUNCTION
      '

      Comment


      • #4
        You have to use an appropriate manifest file to make the application DPI aware. Otherwise, Windows will run the application virtualized and always return 96.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Interesting José, but the code above without manifest works like expected - returns 120 for 125% and 96 for 100% in my Win10 system. Maybe there is some "always run virtualized" setting somewhere in this Win10 mess?

          Comment


          • #6
            In my Windows 10, your code returns 96 without making the application DPI aware, and 168 after calling the API function SetProcessDPIAware (the recommended way is to use an appropriate manifest instead of calling this function).
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              Hm, weird. Then I've got nothing, because I get the values described above (120, etc) after having changed the "advanced scaling setting" (whatever it is called in English system) under screen (display) settings, logged out and in again to make it "stick", like Windows tells me to.

              Comment


              • #8
                Mr. Jose
                What is the appropriate manifest that you refer to.

                Comment


                • #9
                  Code:
                  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
                     <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
                  
                        <assemblyIdentity version="1.0.0.0"
                           processorArchitecture="*"
                           name="ApplicationName"
                           type="win32"/>
                        <description>Optional description of your application</description>
                  
                        <asmv3:application>
                           <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
                              <dpiAware>true</dpiAware>
                           </asmv3:windowsSettings>
                        </asmv3:application>
                  
                        <!-- Compatibility section -->
                        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
                           <application>
                              <!--The ID below indicates application support for Windows Vista -->
                              <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
                              <!--The ID below indicates application support for Windows 7 -->
                              <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
                              <!--This Id value indicates the application supports Windows 8 functionality-->
                              <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
                              <!--This Id value indicates the application supports Windows 8.1 functionality-->
                              <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
                              <!--This Id value indicates the application supports Windows 10 functionality-->
                              <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
                           </application>
                         </compatibility>
                  
                        <!-- Trustinfo section -->
                        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
                           <security>
                              <requestedPrivileges>
                                 <requestedExecutionLevel
                                    level="asInvoker"
                                    uiAccess="false"/>
                                 </requestedPrivileges>
                           </security>
                        </trustInfo>
                  
                        <dependency>
                           <dependentAssembly>
                              <assemblyIdentity
                                 type="win32"
                                 name="Microsoft.Windows.Common-Controls"
                                 version="6.0.0.0"
                                 processorArchitecture="*"
                                 publicKeyToken="6595b64144ccf1df"
                                 language="*" />
                           </dependentAssembly>
                        </dependency>
                  
                     </assembly>
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    Mr Borje
                    Your code in #3 returns 96 for all the settings in my windows 10 home, and I am using PB 10.03.

                    Mr. Jose
                    How do I use your code in a program?

                    Comment


                    • #11
                      Very strange - like I said, it works like expected without manifest or calling SetProcessDPIAware, etc. here (120 for 125%, 96 for 100%, etc). As it should and always has worked in earlier Windows versions. To use manifest (I have a manifest file, XPTheme.xml, saved in PBWin10\WinAPI\ folder)

                      #RESOURCE MANIFEST, 1, "C:\PBWin10\WinAPI\XPTheme.xml"

                      ..or simply call SetProcessDPIAware like it looks at program start: SetProcessDPIAware

                      Added: Just wondering how on earth lots of software is supposed to work if GetDeviceCaps with desktop DC and for example %LOGPIXELSX, etc. is sort of "broken" in Windows 10? Often used when creating fonts, etc. Very strange, IMHO.

                      Comment


                      • #12
                        Thanks Borje
                        When I use SetProcessDPIAware it works perfectly.

                        Comment


                        • #13
                          > How do I use your code in a program?

                          Save it to a file, e.g. Manifest.xml, and include it to you program using #RESOURCE MANIFEST, 1, "Manifest.xml"
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #14
                            > Added: Just wondering how on earth lots of software is supposed to work if GetDeviceCaps with desktop DC and for example %LOGPIXELSX, etc. is sort of "broken" in Windows 10? Often used when creating fonts, etc. Very strange, IMHO.

                            It is not broken. GetDeviceCaps works perfectly in my computer with Windows 10.
                            Forum: http://www.jose.it-berater.org/smfforum/index.php

                            Comment


                            • #15
                              I wonder - if GetDeviceCaps(hDC, %LOGPIXELSY)) returns 120 for 125% scaling in my system and 96 in a couple of other Win10 systems - after log out / log in to reflect change - I'd say something is not reliable and it should for example affect point size in CreateFont calculation. (nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72))

                              But you have provided a good fix, so I won't bother about it. Thank you, José.

                              Comment

                              Working...
                              X