Thread: CStatic

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    103

    CStatic

    is it possible just to change the text color of a CStatic control? i made a class derived from CStatic and i want to change the text color on MouseMove event i dont wanna use the paint event because i will have to use my own text wrap function and i dont wanna use that, for now i got this code:
    Code:
    HBRUSH CLabel::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
    	CDC dc;
    	HBRUSH brush;
    	pDC->SetBkMode(TRANSPARENT);
    	pDC->SelectObject(&m_font);
    	pDC->SetTextColor(m_color);
    	dc.CreateCompatibleDC(pDC);
    	dc.SelectObject(&((CChateXDlg*)AfxGetMainWnd())->m_bmp);
    	brush = (HBRUSH)::CreateSolidBrush(dc.GetPixel(24, 24));
    	dc.DeleteDC();
    	return brush;
    }
    thanks

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    You create the brush on the stack. Create a brush as member of the class.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    can you give me an example please ? i dont really understand what you mean

    thanks

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Create a class member of type HBRUSH. You only need to create one brush object. Update via SetDCBrushColor().

    Kuphryn

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    ok thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [MFC] Picture box question (CStatic with SS_BITMAP style)
    By Lionel in forum Windows Programming
    Replies: 2
    Last Post: 09-29-2007, 12:13 PM
  2. how to delete a CStatic text
    By earth_angel in forum Windows Programming
    Replies: 13
    Last Post: 08-30-2005, 06:27 AM
  3. Changing font size of CStatic
    By earth_angel in forum Windows Programming
    Replies: 2
    Last Post: 08-12-2005, 10:51 AM