Solved

changing my CStatic font size and color

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 79
List out all word 7 261
conditional code and condition difference 9 77
Change to event 1 101
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 …
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now