Solved

changing my CStatic font size and color

Posted on 2003-11-17
5
2,527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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