Print Page | Close Window

How to change the color of a CStatic

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=8795
Printed Date: 14 November 2025 at 6:01am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to change the color of a CStatic
Posted By: ocoralan
Subject: How to change the color of a CStatic
Date Posted: 15 November 2007 at 10:06am
Dear Support:
I have a program which is based on the CXTResizeDialog, I met two questions:

(1) There is a CStatic in this dialog, In default, the font color is black, when something is wrong, it's color will change to red, is there any such class in the xtreme toolkitpro?

(2) Can I make the resize gripper in the bottom right corner visible?

Thank you.




Replies:
Posted By: Ashok
Date Posted: 16 November 2007 at 8:16am

Hi, I am not sure whether this solution is suits you. But this is solution for changing the color of the Static.

 override OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

HBRUSH CDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)

{

if (nCtlColor == CTLCOLOR_STATIC)

return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

COLORREF clr = RGB(0,0,0); -- type the color u want

static CBrush brush;

static COLORREF brushColor = 0;

if (brush.GetSafeHandle() == 0 || brushColor != clr)

{

brush.DeleteObject();

brush.CreateSolidBrush(clr);

brushColor = clr;

}

pDC->SetTextColor(clr);

return brush;

}



Posted By: ocoralan
Date Posted: 18 November 2007 at 10:46am
Thank you for your help.

But I donn't think this method suits for me, because there are other CStatic controls in my dialog.

My requirement is following:
When the customers enter the wrong password, the font color of the specified CStatic will be changed to red.

to Support: Are there any such class which is derived from CStatic in the XTreme ToolkitPro?


Posted By: jimmy
Date Posted: 19 November 2007 at 4:51am
Create your own class CTransparentStatic : public CStatic.
And this class handle OnCtlColor itself.
Or your create a complete owndraw CStatic with Transparent flag.
See www.codeproject.com, there are some sample.

  Jimmy



Posted By: rdhd
Date Posted: 27 November 2007 at 1:33pm
A static doesn' t have to use the fixed ID assigned by the resource editor. Open your resource file and select the control on the dialog and invoke the properties command. Give the static control its own ID. Then in OnCtlColor simply take the input CWnd and call GetDlgCtrlID().
 
Look for the ID you gave it and when your static comes thru color it appropriately.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net