Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

changing my CStatic font size and color

Posted on 2003-11-17
5
Medium Priority
?
2,548 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 45

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 45

Accepted Solution

by:
AndyAinscow earned 60 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
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…
Suggested Courses

772 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