Making a CStatic Bold

I have a CFormView with several controls that I define in a resource file.  I would like to make a label on my form bold.  Usually with a dialog, I simply put this code in the OnInitDialog() function:

//Sets the Font to Bold on the Description Box
if ( m_fntDesc.m_hObject == NULL )
{
LOGFONT logFont;
CFont* pFont = GetFont();
pFont->GetLogFont(&logFont);
logFont.lfWeight = FW_BOLD;
m_fntDesc.CreateFontIndirect(&logFont);
}
m_ctlConfigDesc.SetFont(&m_fntDesc);


Where m_ctlConfigDesc is a CStatic member variable and m_ftnDesc is a CFont member variable.  Since there is not an OnInitDialog() function for CFormView, where do I put this code.  Or is there something else that I have to do intead?

Thanks,

Jordan
jordan_pAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wildyCommented:
Use OnInitialUpdate
0
jordan_pAuthor Commented:
I used OnInitialUpdate.  Because I'm dynamically replacing the views in a CSplitterWnd pane, OnInitialUpdate doesn't get called.

Here's the code from the derived CSplitterWnd class that changes the views:

BOOL CSplitter::ReplaceView(int row, int col, CRuntimeClass* pViewClass, SIZE size)
{
      CCreateContext context;
      BOOL bSetActive;
      
      
      if ((GetPane(row,col)->IsKindOf(pViewClass))==TRUE)
       return FALSE;
      
      
      // Get pointer to CDocument object so that it can be used in the creation
      // process of the new view
      CDocument * pDoc= ((CView *)GetPane(0,0))->GetDocument();
      CView * pActiveView=GetParentFrame()->GetActiveView();
      if (pActiveView==NULL || pActiveView==GetPane(row,col))
            bSetActive=TRUE;
      else
            bSetActive=FALSE;
      
    // set flag so that document will not be deleted when view is destroyed
      pDoc->m_bAutoDelete=FALSE;      
    // Delete existing view
      ((CView *) GetPane(row,col))->DestroyWindow();
    // set flag back to default
    pDoc->m_bAutoDelete=TRUE;
      
    // Create new view                        
      
      context.m_pNewViewClass=pViewClass;
      context.m_pCurrentDoc=pDoc;
      context.m_pNewDocTemplate=NULL;
      context.m_pLastView=NULL;
      context.m_pCurrentFrame=NULL;
      
      CreateView(row,col,pViewClass,size, &context);
      
      CView * pNewView= (CView *)GetPane(row,col);
      
      if (bSetActive==TRUE)
            GetParentFrame()->SetActiveView(pNewView);
      
      RecalcLayout();
      GetPane(row,col)->SendMessage(WM_PAINT);
      
      pDoc->UpdateAllViews(NULL);

      return TRUE;
}
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

Place it in OnSetFocus() and take to do those operations only once.

VinExpert
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

SteveGTRCommented:
Do this in your OnInitDialog():

LOGFONT logFont;

m_ctlConfigDesc.GetFont()->GetLogFont(&logFont);
logFont.lfWeight = FW_BOLD;
m_fntDesc.CreateFontIndirect(&logFont);
m_ctlConfigDesc.SetFont(&m_fntDesc);

Good Luck,
Steve

0
ZoppoCommented:
Hi jordan_p,

I would place it in the view's Create()-function, somehow like this:

------------------------------------------------------------------------------------------------
BOOL CTestView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
 BOOL bRet = CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
 
 if ( bRet )
 {
  CWnd* pWnd = GetDlgItem( IDC_STATIC_BOLD );
  LOGFONT lf;
  CFont* pFont;

  pFont = pWnd->GetFont();
  pFont->GetLogFont( &lf );
  lf.lfWeight = FW_BOLD;
  CFont font;
  font.CreateFontIndirect( &lf );
  pWnd->SetFont( &font );
 }

 return bRet;
}
------------------------------------------------------------------------------------------------

hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jordan_pAuthor Commented:
I ended up using ZOPPO's answer.  It worked perfect.  Can you do on OnInitDialog on a CFormView?  I'm not sure.
0
jordan_pAuthor Commented:
This is exactly what I needed.  Thanks.
0
ZoppoCommented:
your welcome           :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.