Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. create a dpi-aware application

create a dpi-aware application

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++wpflearning
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Theo Buys
    wrote on last edited by
    #1

    I try to find out what the best strategy is to create a MFC based application that is dpi-aware. Windows is based on 96 dpi for years. Today there are pc's like the Microsoft Surface that have lot more dots per inch. In windows you can set the screen scaling factor to 100%, 125%, 150%, etc. If you build the application with a manifest that set DPI Awareness with High DPI Aware, then the resource templates like dialogs scale automatically. Only the custom drawings must be scaled with extra code like:

    int DpiScale(int val)
    {
    const HDC hDC = ::GetDC(NULL);
    const UINT dpix = ::GetDeviceCaps(hDC, LOGPIXELSX);
    ::ReleaseDC(NULL, hDC);
    return ::MulDiv(val, dpix, 96);
    }

    int DpiPerc()
    {
    return DpiScale(100);
    }

    DpiScale you can for coordinates or font points. DpiPerc you can use to select the a icon or picturewith the right resolution from resource. My question is, must I develop the application for 1024 x 768?

    L G 2 Replies Last reply
    0
    • T Theo Buys

      I try to find out what the best strategy is to create a MFC based application that is dpi-aware. Windows is based on 96 dpi for years. Today there are pc's like the Microsoft Surface that have lot more dots per inch. In windows you can set the screen scaling factor to 100%, 125%, 150%, etc. If you build the application with a manifest that set DPI Awareness with High DPI Aware, then the resource templates like dialogs scale automatically. Only the custom drawings must be scaled with extra code like:

      int DpiScale(int val)
      {
      const HDC hDC = ::GetDC(NULL);
      const UINT dpix = ::GetDeviceCaps(hDC, LOGPIXELSX);
      ::ReleaseDC(NULL, hDC);
      return ::MulDiv(val, dpix, 96);
      }

      int DpiPerc()
      {
      return DpiScale(100);
      }

      DpiScale you can for coordinates or font points. DpiPerc you can use to select the a icon or picturewith the right resolution from resource. My question is, must I develop the application for 1024 x 768?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Theo Buys wrote:

      must I develop the application for 1024 x 768?

      No, your application should work on any screen if it allows Window to scale it correctly. If the screen size is important then you can get the current values from GetSystemMetrics function (Windows)[^].

      T 1 Reply Last reply
      0
      • L Lost User

        Theo Buys wrote:

        must I develop the application for 1024 x 768?

        No, your application should work on any screen if it allows Window to scale it correctly. If the screen size is important then you can get the current values from GetSystemMetrics function (Windows)[^].

        T Offline
        T Offline
        Theo Buys
        wrote on last edited by
        #3

        Yes I can use GetSytemMetrics for the custom drawings. But not the dialogs templates in resource which are sized by the system.

        L 1 Reply Last reply
        0
        • T Theo Buys

          Yes I can use GetSytemMetrics for the custom drawings. But not the dialogs templates in resource which are sized by the system.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Dialogs are scaled by Windows to match the screen size.

          T 1 Reply Last reply
          0
          • L Lost User

            Dialogs are scaled by Windows to match the screen size.

            T Offline
            T Offline
            Theo Buys
            wrote on last edited by
            #5

            Not true... When I created a dialog template that is at 96 dpi full screen. With a system dpi scaling of 150% ( 144 dpi) the bottom and right are not visible with the same screen size.

            L 1 Reply Last reply
            0
            • T Theo Buys

              Not true... When I created a dialog template that is at 96 dpi full screen. With a system dpi scaling of 150% ( 144 dpi) the bottom and right are not visible with the same screen size.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If you increase the scaling to 150%, then everything in the display will be that much larger.

              T 1 Reply Last reply
              0
              • L Lost User

                If you increase the scaling to 150%, then everything in the display will be that much larger.

                T Offline
                T Offline
                Theo Buys
                wrote on last edited by
                #7

                Because the Microsoft Surface is default at 150% system scaling, I must do dialog development in 1024 x 768 pixels at 96 dpi to match the full screen for a dpi-aware application. Right?

                L 1 Reply Last reply
                0
                • T Theo Buys

                  Because the Microsoft Surface is default at 150% system scaling, I must do dialog development in 1024 x 768 pixels at 96 dpi to match the full screen for a dpi-aware application. Right?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Theo Buys wrote:

                  I must do dialog development in 1024 x 768 pixels at 96 dpi

                  Dialogs have their own measurement system (dialog units) which is supposed to make them look the same on any screen. But, as I said above, if you magnify to 150% you need to make sure it will still fit in the space you have.

                  1 Reply Last reply
                  0
                  • T Theo Buys

                    I try to find out what the best strategy is to create a MFC based application that is dpi-aware. Windows is based on 96 dpi for years. Today there are pc's like the Microsoft Surface that have lot more dots per inch. In windows you can set the screen scaling factor to 100%, 125%, 150%, etc. If you build the application with a manifest that set DPI Awareness with High DPI Aware, then the resource templates like dialogs scale automatically. Only the custom drawings must be scaled with extra code like:

                    int DpiScale(int val)
                    {
                    const HDC hDC = ::GetDC(NULL);
                    const UINT dpix = ::GetDeviceCaps(hDC, LOGPIXELSX);
                    ::ReleaseDC(NULL, hDC);
                    return ::MulDiv(val, dpix, 96);
                    }

                    int DpiPerc()
                    {
                    return DpiScale(100);
                    }

                    DpiScale you can for coordinates or font points. DpiPerc you can use to select the a icon or picturewith the right resolution from resource. My question is, must I develop the application for 1024 x 768?

                    G Offline
                    G Offline
                    Gisle Vanem
                    wrote on last edited by
                    #9

                    There a good blog-entry for this item here: http://blog.softwareverify.com/how-to-make-your-mfc-or-non-mfc-program-support-high-dpi-monitors-the-easy-way/

                    -- Gisle V.

                    T 1 Reply Last reply
                    0
                    • G Gisle Vanem

                      There a good blog-entry for this item here: http://blog.softwareverify.com/how-to-make-your-mfc-or-non-mfc-program-support-high-dpi-monitors-the-easy-way/

                      -- Gisle V.

                      T Offline
                      T Offline
                      Theo Buys
                      wrote on last edited by
                      #10

                      Thanks! This is the info where I was looking for!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups