Re: Changing the Font size of a Static Text control problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



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]





.



Relevant Pages

  • Re: Changing the Font size of a Static Text control problem
    ... I am trying to set the font size for my static text and I am getting this ... error: Debug Assertion Failed! ... You cannot access windows in an MFC window class ... Move your SetFont call to OnInitDialog, after it calls the base class ...
    (microsoft.public.vc.mfc)
  • Re: Stumped, baffled, and perplexed.......
    ... programmer stunt that gives MS Windows a bad name. ... Yahoo Widgets lists 326 clock apps. ... TrueType, OpenType, PostScript, etc. font on the system. ... Surely the slow running network to which you refer is your personal ...
    (rec.video.production)
  • Re: Font for a menu?
    ... It wouldn't be so bad if the Windows key were somewhere else on the keyboard, ... That's the one - the main problem is that Microsoft don't distribute a font ... I think the Unicode set has been ... flags exist in the set - but only flags for upward stems. ...
    (microsoft.public.vc.mfc)
  • Re: Change icon and font size on the All Programs menu?
    ... General tab | Select Large icons or Small icons | Click OK | Click ... Start Menu Font. ... If you select a windows and buttons setting other than Windows Classic, ... of Display Properties, *NOT* Windows Classic theme on the Themes tab ...
    (microsoft.public.windowsxp.customize)
  • Re: Those little dots
    ... > Marlett font char 'n' is thte one Windows uses. ... I thought it was unicode character $2022 of font Tahoma. ... Windows XP displays the dot. ...
    (borland.public.delphi.language.objectpascal)