Solved

changing my CStatic font size and color

Posted on 2003-11-17
5
2,495 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now