Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to get and set Display DPI setting in VC++?

Posted on 2005-05-04
5
Medium Priority
?
1,832 Views
Last Modified: 2013-11-20
Hi experts,

From Control panel/Display/Settings tab/Advanced button, users can change the Display DPI setting. The fonts I use in the dialog boxes only shows up nicely when 'Normal Size (96 DPI)' is selected. Higher DPI setting will make the fonts too big for the dialog box. I am not sure what is the best way to solve this type of problem programmatically. I thought at least I should find a way to get the setting value and remind users to use 96 DPI (or if possible set it to 96 DPI in the program). But how to do it? Any suggestions or other approaches?

Thanks.
0
Comment
Question by:jper_hm
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13928093
Check out http://www.codeproject.com/system/enum_display_modes.asp ("Enumerate and Change Display Modes") - the idea is to use 'EnumDisplaySettings()' and 'ChangeDisplaySettings()':

BOOL            bRetVal;
CString            sDevMode;

iMode = 0;

do
{
    bRetVal = ::EnumDisplaySettings(NULL, iMode, &devmode);
    iMode++;
    if (bRetVal)
    {
        sDevMode.Format("%d x %d, %d bits %dhtz",
         devmode.dmPelsWidth, devmode.dmPelsHeight,
         devmode.dmBitsPerPel, devmode.dmDisplayFrequency);
       
        // list box for all modes (see demo)
        if (m_lb1.AddString(sDevMode)==LB_ERR)
            AfxMessageBox("An error occurred!!!");
      }
}
while (bRetVal);

To change the settings:

BOOL bRetVal;

iMode = m_lb1.GetCurSel();
bRetVal = ::EnumDisplaySettings(NULL, iMode, &devmode);
if (bRetVal)
{
    devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT |
                     DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
                  ::ChangeDisplaySettings(&devmode, 0);
}
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 13928333
Oh, actually, it might be easier to do that in the registry - the value is stored in

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current\Software\Fonts

and is called 'LogPixels' - 0x60 means '96' here, th eonly other valid value is 0x78 aka '120'
0
 

Author Comment

by:jper_hm
ID: 13928400
Thank you. It looks like your second answer is what I need. It seems to me that the 'EnumDisplaySettings()' and 'ChangeDisplaySettings()' only change the display resolutions and not the font DPI. Am I right? Or they mean the same thing?

0
 
LVL 86

Expert Comment

by:jkr
ID: 13928609
You're right, just re-checked that - the registry is the way to go.
0
 

Author Comment

by:jper_hm
ID: 13932331
Thank you again.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question