create a dpi-aware application
-
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?
-
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?
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)[^].
-
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)[^].
-
Yes I can use GetSytemMetrics for the custom drawings. But not the dialogs templates in resource which are sized by the system.
-
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.
-
If you increase the scaling to 150%, then everything in the display will be that much larger.
-
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?
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.
-
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?
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.
-
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.