| | |
Resizing MFC Dialog-Based App - Font Resizing Issues
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2005
Posts: 7
Reputation:
Solved Threads: 0
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:
...and I've also tried:
I've even tried playing around with the DC, but that didn't do anything.
I could really use some direction.
Thanks!
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:
C Syntax (Toggle Plain Text)
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:
C Syntax (Toggle Plain Text)
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++) {<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!
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.
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.
![]() |
Similar Threads
- Saving to a file (C)
- Status bar on a dialog box (C)
- CSocket: How do I do this? (C++)
- Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls? (C++)
- vc++ mfc-i can't make getline work with a string for file input (C++)
- Creating Dialog Based Application without MFC (C++)
Other Threads in the C Forum
- Previous Thread: help in the program
- Next Thread: Construct your own random number generator
| Thread Tools | Search this Thread |
Tag cloud for C
#include ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi





