Re: Changing the Font size of a Static Text control problem
- From: "Tom Serface" <tserface@xxxxxxx>
- Date: Wed, 22 Feb 2006 15:24:32 -0800
Hi Wayland,
I've been off on a holiday, but I've found these classes to be very useful:
http://www.codeguru.com/cpp/controls/editctrl/article.php/c493/
You can safely ignore if you already have your problem solved, but I figured
them worth noting.
Tom
"Wayland" <wyu@xxxxxxxxxxxxx> wrote in message
news:0k5Lf.47$vC4.29@xxxxxxxxxxx
Thank you David and Scott. Your comments were very helpful I was able to
change font size.
Wayland
"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:uOCK29zNGHA.3272@xxxxxxxxxxxxxxxxxxxxxxx
Wayland wrote:
Hello,
I am trying to set the font size for my static text and I am getting
this error: Debug Assertion Failed! When I "ignore" the error the Font
Size does not change.When try changing the text with,
m_sLabel.SetWindowText("Hello"), I get another assertion and it breaks
at void CWnd::SetWindowText(LPCTSTR lpszString)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL)); <--- this is
where it asserts
if (m_pCtrlSite == NULL)
::SetWindowText(m_hWnd, lpszString);
else
m_pCtrlSite->SetWindowText(lpszString);
}
The following is my code:
// Header File
CStatic m_sLabel; // Cpp File
CPageInitDialog::CPageInitDialog(CWnd* pParent /*=NULL*/)
: TStackedPage(CPageInitDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CPageInitDialog) // NOTE: the ClassWizard will add
member initialization here
//}}AFX_DATA_INIT
CFont *m_Font = new CFont;
m_Font->CreatePointFont(240, "Verdana");
m_sLabel.SetFont("m_Font");
}
void CPageInitDialog::DoDataExchange(CDataExchange* pDX)
{
TStackedPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageInitDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_STATIC_INIT_01, m_sLabel);
}
Any comments ideas would be appreciated.
Thanks
The problem stems from fundamental MFC principles. In your dialog
constructor the m_sLabel object exists but its underlying static control
does not yet exist. As a matter of fact, the underlying dialog does not
yet exist either. You cannot access windows in an MFC window class
constructor because the windows have not yet been created or attached to
the C++ object. Result: m_hWnd is NULL at this point, as the ASSERT
discovers.
Move your SetFont call to OnInitDialog, after it calls the base class
OnInitDialog. That is the first point at which the actual dialog and its
controls exist.
--
Scott McPhillips [VC++ MVP]
.
- References:
- Changing the Font size of a Static Text control problem
- From: Wayland
- Re: Changing the Font size of a Static Text control problem
- From: Scott McPhillips [MVP]
- Re: Changing the Font size of a Static Text control problem
- From: Wayland
- Changing the Font size of a Static Text control problem
- Prev by Date: Re: Programmatically Expand or Collapse a sub menu
- Next by Date: Re: Programmatically Expand or Collapse a sub menu - Solved
- Previous by thread: Re: Changing the Font size of a Static Text control problem
- Next by thread: Replaceing content of a CDialog
- Index(es):
Relevant Pages
|