-
February 27th, 2007, 06:41 AM
#1
Default font size for all controls in dialog
I Supposed to set font size for all controls in dialog at runtime. I tried SetFont(pFont) in OnInitDialog function. But the font size is not changing. Please Suggest me. Thanks.
Last edited by sabitha; February 27th, 2007 at 06:44 AM.
-
February 27th, 2007, 06:57 AM
#2
Re: Default font size for all controls in dialog
-
February 27th, 2007, 07:03 AM
#3
Re: Default font size for all controls in dialog
Originally Posted by sabitha
I Supposed to set font size for all controls in dialog at runtime. I tried SetFont(pFont) in OnInitDialog function. But the font size is not changing. Please Suggest me. Thanks.
In addition to my first answer. What is pFont? Is is a member variable of your class? If not it will go out of scope as soon as OnInitDialog finishes and therefore would not have any effect.
But the first code snippet in the faq should do what you want!
Regards,
Laitinen
-
February 27th, 2007, 07:09 AM
#4
Re: Default font size for all controls in dialog
pFont is CFont pointer object.
nTextFontHeight = 20;
m_cFontDialog.CreateFont(nTextFontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, NULL, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, _T("MS Shell Dlg"));
CFont *pFont = &m_cFontDialog;
SetFont(pFont);
-
February 27th, 2007, 07:15 AM
#5
Re: Default font size for all controls in dialog
Change your code to this;
Code:
//In header File
CFont m_Font;
//In OnInitDialog
m_Font.CreateFont(nTextFontHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, NULL, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, _T("MS Shell Dlg"));
//Set the font on a button with ID = ID_BUTTON1
GetDlgItem(ID_BUTTON1)->SetFont(&m_Font);
-
February 27th, 2007, 07:48 AM
#6
Re: Default font size for all controls in dialog
I should not set font size for individual controls. I have to do this by setting font size to dialog.
-
February 27th, 2007, 08:08 AM
#7
Re: Default font size for all controls in dialog
Setting the dialog's font size has no effect on the font size of its controls. You need to set the font for each of them explicitly. Obviously doing this by hand is tedious an error prone.
What you could do is use the EnumChildWindows functions to enumerate all the children of the dialog and have the callback function set the font.
Code:
BOOL CALLBACK EnumChildProc( HWND hwnd,LPARAM lParam)
{
CWnd* wnd = CWnd::FromHandle( hwnd);
wnd->SetFont( (CFont*) lParam);
return TRUE;
}
BOOL CYourDialog::OnInitDialog( )
{
CDialog::OnInitDialog();
...
// create and setup the font
CFont font;
...
EnumChildWindows( GetSafeHwnd(), EnumChildProc, (long) &font);
return TRUE;
}
Har Har
-
February 27th, 2007, 08:25 AM
#8
Re: Default font size for all controls in dialog
Thank you. It is working fine.
-
April 11th, 2007, 03:25 AM
#9
Re: Default font size for all controls in dialog
Hi
What if I'm not using MFC??
I'm using C++ to write my GUI.
Thanks
-
June 14th, 2013, 10:26 AM
#10
Re: Default font size for all controls in dialog
You may also use a loop for iterating through all of the controls, rather than calling EnumChildWindows():
In OnInitDialog() write:
Code:
for(CWnd *pControl=GetWindow(GW_CHILD);pControl;pControl=pControl->GetWindow(GW_HWNDNEXT))
pControl->SetFont(&m_font);
where m_font is a member of the dialog which gets not out of scope as long the dialog exists.
-
June 15th, 2013, 03:38 PM
#11
Re: Default font size for all controls in dialog
Did you try to use SendMessageToDescendants instead?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|