Solved

LARGE FONTS - big reward for an excelent  answer

Posted on 1999-01-12
14
244 Views
Last Modified: 2013-12-03
I keep having the same problem everytime I try to transfer my program over to a computer with the large fonts enabled in the display settings.  My VC++6 dialog program uses controls that I have placed in the dialog editor, and I want everything to be "exactly" the same size and in the same place.  However, even if I set the font on the dialog, Windows keeps messing it up and changing the size and all of the controls in the dialog box and even the dialog itself.

I can't figure out what to do any more so i'm offering 300+ points for anyone who can give me an "excelent" solution to this problem.  I think the only way around this problem is to somehow disable the large fonts feature for my program.(I still want to create my dialog in the resource editor; I don't want to waste my time creating all the controls during runtime.)
0
Comment
Question by:SileNcer
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327556
Indeed, I would like to see an answer to this as well.  I have had similar problems.

Do you have problems with cut-off text?  Or do you just want it all to be the exact same size on all computers?
0
 

Author Comment

by:SileNcer
ID: 1327557
Both would be nice =), I think it also originates from the same problem.  It seems that even though I choose the "size to content" command on my static text, the darn large fonts takes over and won't display the whole string; the only solution I have found for this is to give extra room for each control, but this causes some of my dialogs to not look right in a regular fonts display.
0
 

Author Comment

by:SileNcer
ID: 1327558
Edited text of question
0
 

Expert Comment

by:koskia
ID: 1327559
I'm sure there's a way to check the current size of fonts in the system, and use a different size of font on either occasions
0
 
LVL 12

Expert Comment

by:migel
ID: 1327560
There are several parameters in the system registry:
HKEY_LOCAL_MACHINE\config\0001\display\settings
DPILogicalX and DPILogicalY for small fonts this value are setted 96 DPI
for large fonts these values properly changed, so if you set large font with aspect 120% these values setted to the 115 DPI

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327561
That could correct the problem, but the computer would have to be rebooted before the font size would change.  I doubt the user would want to reboot to run a program :-)
0
 
LVL 12

Expert Comment

by:migel
ID: 1327562
<< thresher_shark
<< I doubt the user would want to reboot to run a program :-)
As I understand you want chage registry to get correct dialog appearance. It isn`t good idea.
I say that you can get inforamation about font scale. Once getted this info you can change dialogs font size at ruintime.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:SileNcer
ID: 1327563
<<migel
<<I say that you can get inforamation about font scale. Once <<getted this info you can change dialogs font size at ruintime.

So are you saying I can take the registry information and somehow use it with CreateFont() and set the dialog to it so the font will always be the same size?  If so, how could something like this be done?  And...would the resource editor be able to use this font as well?
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327564
migel - Oh... so that's what you mean :-)  That is definitely a better idea :-)

SileNcer - Unfortunaly, I do not believe the resource editor could do this as the resources are dealt with at compile time, not a run time.
0
 
LVL 12

Expert Comment

by:migel
ID: 1327565
I try change font at runtime and here is my code:
// Note it is only example
// derive own class from the CDialog and override DoModal method.
Platform Win95 compiler MS VC++ v 6.0 (but must compiled with another compiler)
(Caption font and caption dimentions is not changed) -

// override DoModal dialog method
int CAboutDlg::DoModal()
{
      // first getting info
      HKEY hKeyScale  = 0;
      DWORD wType = REG_SZ;
      TCHAR      szBuffer[18] = _T("");
      DWORD dwSize = sizeof(szBuffer);
      RegOpenKey(HKEY_LOCAL_MACHINE, "config\\0001\\display\\settings", &hKeyScale);
      RegQueryValueEx(hKeyScale,"DPILogicalX", NULL, &wType, (LPBYTE)szBuffer, &dwSize);
      WORD wScale = (WORD)atol(szBuffer);
      
  //m_lpszTemplateName = NULL;
      LPDLGTEMPLATE lpDialogTemplate = NULL;

      HGLOBAL hDialogTemplate = m_hDialogTemplate;
      HINSTANCE hInst = AfxGetResourceHandle();
      hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
      HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
      hDialogTemplate = LoadResource(hInst, hResource);

      if (hDialogTemplate != NULL)
            lpDialogTemplate = (LPDLGTEMPLATE)LockResource(hDialogTemplate);
      // find font record
      // return -1 in case of failure to load the dialog template resource
      if (lpDialogTemplate == NULL)
            return -1;
      WORD* lpByte = (WORD*) lpDialogTemplate;
      lpByte += sizeof(*lpDialogTemplate)/sizeof(WORD);
      if (*lpByte) // Menu
            {
            if (*lpByte == 0xFFFF)
                  lpByte += 2; // mark and menu ID
            else
                  while (*(lpByte++)) NULL;
            }
      else
            lpByte++;//skip zero

      if (*lpByte) // class
            {
            if (*lpByte == 0xFFFF)
                  lpByte += 2; // mark and menu ID
            else
                  while (*(lpByte++)) NULL;
            }
      else
            lpByte++; //skip zero

      if (*lpByte) // title
            while (*(lpByte++)) NULL;
      else
            lpByte++ ;//skip zero
      
      if (lpDialogTemplate->style & DS_SETFONT)
            {
            // set WORD boundary
            WORD *lpSize = lpByte;
            *lpSize = MulDiv(*lpSize, 96, wScale);
            lpByte++; // start font name
            while (*(lpByte++)) NULL;
            }
      // correct dialog sizes
      lpDialogTemplate->x = MulDiv(lpDialogTemplate->x, 96, wScale);
      lpDialogTemplate->y = MulDiv(lpDialogTemplate->y, 96, wScale);
      lpDialogTemplate->cx = MulDiv(lpDialogTemplate->cx, 96, wScale);
      lpDialogTemplate->cy = MulDiv(lpDialogTemplate->cy, 96, wScale);
      
      for (int i = 0; i < lpDialogTemplate->cdit; i++)
      {
            LPDLGITEMTEMPLATE lpItems = (LPDLGITEMTEMPLATE)lpByte;
            lpItems->cx = MulDiv(lpItems->cx, 96, wScale)+1;
            lpItems->cy = MulDiv(lpItems->cy, 96, wScale)+1;
            lpItems->x  = MulDiv(lpItems->x, 96, wScale)+1;
            lpItems->y  = MulDiv(lpItems->y, 96, wScale)+1;

            lpByte += sizeof(*lpItems)/sizeof(WORD);
            // WORD alignment
            lpByte = (LPWORD)((((DWORD)(lpByte)+1)/sizeof(WORD))*sizeof(WORD));
            if (*lpByte == 0xFFFF)
                  lpByte += 2; // mark and class ID
            else
                  {
                  while (*(lpByte++)) NULL;
                  //lpByte++; // skip zero
                  }

            // WORD alignment
            lpByte = (LPWORD)((((DWORD)(lpByte)+1)/sizeof(WORD))*sizeof(WORD));
            if (*lpByte == 0xFFFF) // title
                  lpByte += 2; // mark and resource ID
            else
                  {
                  while (*(lpByte++)) NULL;
                  //lpByte++; // skip zero
                  }

            // WORD alignment
            lpByte = (LPWORD)((((DWORD)(lpByte)+1)/sizeof(WORD))*sizeof(WORD));

            if (*lpByte) // control creation data
                  {
                  if (*lpByte == 0xFFFF)
                        lpByte += 2; // mark and menu ID
                  else
                        while (*(lpByte++)) NULL;
                        //lpByte++; // skip zero
                  }
            else
                  lpByte++; //skip zero
            lpByte = (LPWORD)((((DWORD)(lpByte)+3)/sizeof(DWORD))*sizeof(DWORD));
      }
      m_lpszTemplateName = NULL;
      InitModalIndirect(lpDialogTemplate);

      int nRes = CDialog::DoModal();
      UnlockResource(hDialogTemplate);
      FreeResource(hDialogTemplate);
      return nRes;
}

0
 
LVL 12

Expert Comment

by:migel
ID: 1327566
Hey! anybody here?
0
 
LVL 12

Accepted Solution

by:
migel earned 320 total points
ID: 1327567
See my comment above.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1327568
Not a bad idea :-)
0
 

Expert Comment

by:pinerio
ID: 2388029
Thank you for help me. Unfortunately I don't use DoModal. I Create the dialog and use it in a not modal way.
And I wanted a solution to the problem without changing the font size.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now