Hello All,

I've been trying to modify an app to be able to resize nicely and I've finally gotten that working. However, while the controls in my main dialog get bigger, the font stays the same size, which is a problem.

I wanted the font to get proportionally bigger as the dialog grew, but have run into a number of problems.

I have a vector that contains ID's of the controls I want to modify.

Here are a few things I've tried:

void CAppDlg::augmentFont(double change)
{
  LOGFONT lf;                        // Used to create the CFont.
  CFont m_font;
	
  memset(&lf, 0, sizeof(LOGFONT));   // Clear out structure.
  lf.lfHeight = 20 * change;              
  strcpy(lf.lfFaceName, "Arial");    
  m_font.CreateFontIndirect(&lf);    // Create the font.

  for(int i = 0; i < controlVector.size(); i++)
  {
	GetDlgItem(controlVector[i])->SetFont(&m_font);
  }
}

...and I've also tried:

void CAppDlg::augmentFont(double change)
{
CFont m_font;

m_font.CreateFont (((int)20*change), 0, 0, 0, FW_THIN, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
		
for(int i = 0; i < controlVector.size(); i++)
{
[INDENT]GetDlgItem(controlVector[i])->SetFont(&m_font);][/INDENT]
}

I've even tried playing around with the DC, but that didn't do anything.

I could really use some direction.

Thanks!

Recommended Answers

All 2 Replies

u cant change font of a dialog box on the fly, well u can try subclassing ur controls and thn processing WM_SETFONT msg.

Dialog Box Fonts
The system uses the average character width of the dialog box font to calculate the position and dimensions of the dialog box. By default, the system draws all text in a dialog box using the SYSTEM_FONT font.

To specify a font for a dialog box other than the default, you must create the dialog box using a dialog box template. In a template resource, use the FONT Statement. In a dialog box template, set the DS_SETFONT or DS_SHELLFONT style and specify a point size and a typeface name. Even if a dialog box template specifies a font in this manner, the system always uses the system font for the dialog box title and dialog box menus.

When the dialog box has the DS_SETFONT or DS_SHELLFONT style, the system sends a WM_SETFONT message to the dialog box procedure and to each control as it creates the control. The dialog box procedure is responsible for saving the font handle passed with the WM_SETFONT message and selecting the handle into the display device context whenever it writes text to the window. Predefined controls do this by default.

Microsoft® Windows® 2000/Windows XP: The system font can vary between different versions of Windows. To have your application use the system font no matter which system it is running on, use DS_SHELLFONT with the typeface MS Shell Dlg, and use the DIALOGEX Resource instead of the DIALOG Resource. The system maps this typeface such that your dialog box will use the Tahoma font on Windows 2000/Windows XP, and the MS Sans Serif font on earlier systems. Note that DS_SHELLFONT has no effect if the typeface is not MS Shell Dlg.

Above is taken from MSDN.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.