Solved

changing my CStatic font size and color

Posted on 2003-11-17
5
2,509 Views
Last Modified: 2013-12-03
How can i change my CStatic font size and color?

Given
ID:IDC_STATIC
Caption: "Sample"


0
Comment
Question by:girlswants_me
  • 3
  • 2
5 Comments
 

Author Comment

by:girlswants_me
ID: 9762404
anybody can help?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9762458
Override the WM_CTLCOLOR message.

HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      
      if(nCtlColor == CTLCOLOR_STATIC)
      {
            UINT nID = pWnd->GetDlgCtrlID();
            switch(nID)
            {
            case IDC_STATIC://and other here
                  pDC->SetTextColor(RGB(0, 0, 255));
                  break;
            }
      }
      
      // TODO: Return a different brush if the default is not desired
      return hbr;
}
0
 

Author Comment

by:girlswants_me
ID: 9769508
anybody can give me a simple code using like this ->

CProgressCtrl* pmyCtrl = (CProgressCtrl *) GetDlgItem(IDC_PROGRESS1);
 pmyCtrl->SetRange(0,100);
 pmyCtrl->SetStep(10);
 pmyCtrl->StepIt();

change to this..

CStatic* pmyCtrl = (CStatic*) GetDlgItem(IDC_STATIC);
pmyCtrl->setfont(
pmyCtrl->SetWindowText("hello");
   

0
 

Author Comment

by:girlswants_me
ID: 9769510
anybody can help?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 30 total points
ID: 9769790
Sorry - you can't use the default ID of IDC_STATIC you must supply your own.

The OnCtlColor is a standard way to provide custom colouring especially when you have many controls.

To change the font of a control create your own font first  then use the SetFont fn.

eg.
      HDC hDC = ::GetDC(NULL);
      int iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);

      LOGFONT logFont;
      memset( &logFont, 0, sizeof(logFont));

      //8 point font, for use in some Apps where space on screen is a premium
      _tcscpy(logFont.lfFaceName, _T("Arial"));
      logFont.lfHeight = -MulDiv(8, iLogPixelsY, 72);      
      logFont.lfWeight = FW_NORMAL;
      logFont.lfUnderline = false;
      logFont.lfItalic = false;
      VERIFY(m_MyFont.CreateFontIndirect(&logFont));


CStatic* pmyCtrl = (CStatic*) GetDlgItem(IDC_STATIC_X);
pmyCtrl->Setfont(&m_MyFont);
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question