Link to home
Start Free TrialLog in
Avatar of SileNcer
SileNcer

asked on

LARGE FONTS - big reward for an excelent answer

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.)
Avatar of thresher_shark
thresher_shark

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?
Avatar of SileNcer

ASKER

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.
Edited text of question
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
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

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 :-)
<< 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.
<<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?
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.
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;
}

Hey! anybody here?
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not a bad idea :-)
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.