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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ZoppoConnect With a Mentor Commented:
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
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Vinayak KumbarSr Program ManagerCommented:
Hi,

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

VinExpert
0
 
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
 
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
All Courses

From novice to tech pro — start learning today.