CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2003
    Posts
    938

    Static Text color

    Hello.
    Since i am, newb i donno hwo to do it...adn books don't show this....i coudln't find it on thw web..can somone tell me how to change color in static text ?adn font hopefully.....for each static text.

  2. #2
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315
    Create a CBrush object and intialize it in the OnInitDialog function.

    Override the ON_WM_CTLCOLOR() message for your dialog in the class wizard.

    Now go to the function labeled OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

    Now switch through pWnd->GetDlgCtrlID()

    Code:
    	switch (pWnd->GetDlgCtrlID())
    	{     
    	case IDC_EDIT1: 
    	case IDC_EDIT2: 
    	case IDC_EDIT3: 
    	case IDC_EDIT4: 
    	case IDC_EDIT5: 
    
    		pDC->SetBkMode(TRANSPARENT);
    		pDC->SetTextColor(RGB(0,0,255)); // change the text color
    		hbr = (HBRUSH) m_brushBG;   // apply the brush
    		break;
    
    		// otherwise, do default handling of OnCtlColor
    	default:
    		hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
    	}
    Good luck..

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    In general this is done by reacting on the WM_CTLCOLOR message. Override the associated message handler 'OnCtlColor()' and check for CTLCOLOR_STATIC. There you can change the color appearance of your static controls.

    However, this is a global option. Changing the color the above way would result in all static controls being the same color. Therefore you should subclass the static control and then use message reflection to color it individually.

    However, there exists several color static controls already like this one..

  4. #4
    Join Date
    Aug 2003
    Posts
    938
    exactly how do i create cBrush object ??
    Thx.

  5. #5
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    go to the link given by Mr.Masur...above,,,
    take a look in the source code....
    everything is there.!!
    it will teach you how to draw the brush....
    and will help you with a lot of other stuff...
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  6. #6
    Originally posted by Quell
    exactly how do i create cBrush object ??
    Thx.
    Yep

  7. #7
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    Originally posted by aventec_01
    Yep
    just curious.....wats that yep for???
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  8. #8
    Originally posted by Joseph_R_Thomas
    just curious.....wats that yep for???
    so sory as i hav just changed my contact lens and i dint see de word how infront of de statement

  9. #9
    Join Date
    Apr 2003
    Posts
    893
    Originally posted by Quell
    exactly how do i create cBrush object ??
    Thx.
    Did you solve the problem ? I will go search for you if you need...

    Regards,

  10. #10
    Join Date
    Aug 2003
    Posts
    938
    i doonno how to make a CBrush object...what is the solution ? I tried google...didn't come up with much.......
    Thx in Advance

  11. #11
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Code:
    COLORREF Color;
    CBrush Brush;
    
    Color = RGB(255, 0, 0);
    Brush.CreateSolidBrush(Color);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured