Resizing MFC Dialog-Based App - Font Resizing Issues

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 7
Reputation: deineMutti is an unknown quantity at this point 
Solved Threads: 0
deineMutti deineMutti is offline Offline
Newbie Poster

Resizing MFC Dialog-Based App - Font Resizing Issues

 
0
  #1
May 23rd, 2006
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:

  1. void CAppDlg::augmentFont(double change)
  2. {
  3. LOGFONT lf; // Used to create the CFont.
  4. CFont m_font;
  5.  
  6. memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
  7. lf.lfHeight = 20 * change;
  8. strcpy(lf.lfFaceName, "Arial");
  9. m_font.CreateFontIndirect(&lf); // Create the font.
  10.  
  11. for(int i = 0; i < controlVector.size(); i++)
  12. {
  13. GetDlgItem(controlVector[i])->SetFont(&m_font);
  14. }
  15. }

...and I've also tried:

  1. void CAppDlg::augmentFont(double change)
  2. {
  3. CFont m_font;
  4.  
  5. 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");
  6.  
  7. for(int i = 0; i < controlVector.size(); i++)
  8. {<blockquote>GetDlgItem(controlVector[i])->SetFont(&m_font);]</blockquote>}

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

I could really use some direction.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Resizing MFC Dialog-Based App - Font Resizing Issues

 
0
  #2
May 24th, 2006
u cant change font of a dialog box on the fly, well u can try subclassing ur controls and thn processing WM_SETFONT msg.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Resizing MFC Dialog-Based App - Font Resizing Issues

 
0
  #3
May 24th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC