Change Text Color of a Checkbox
-
Thursday, March 08, 2012 1:05 PM
Hi,
The problem domain is: C++, Win32 (Compatible with XP, Vista, Win7, Win8 - 32 & 64 bits)
I am using Visual Studio 2010 - VC++ - Project is based on ATL, WTLI have already seen this and it does not help me. http://social.msdn.microsoft.com/Forums/en-NZ/vcgeneral/thread/cd6e7637-3550-4d1c-9b11-4f0f0965675f
I have a checkbox control (BUTTON) on my dialogbox resource.
CONTROL "Remember me",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,89,273,167,11
I am already handling: WM_CTLCOLORSTATIC - by which I am maintaining transparency of the controls and changing the text color of controls.
For some reasons, (I am not aware of) the Dialogbox also gets this WindowMessage for checkbox as well, even though it is a Button not a Static.
This is a basic code written on OnCtlColorStatic()
DefWindowProc()
::SetTextColor((HDC)wParam, m_crText);
::SetBkMode((HDC)wParam, TRANSPARENT);
return Brush...
It is working fine for all Static controls, and even for the checkbox it is making it transparent - BUT it is unable to change the Text Color of the checkbox!
When I made the Checkbox as BS_OWNERDRAW then I started to get the WM_CTLCOLORBTN message (which is good) but then whole control is not drawn and in the DialogBox class I will have to handle the WM_DRAWITEM and to draw the full checkbox control myself which is what I do not want to do.
So how to solve this issue?Regards - Habib
- Moved by Bob_BaoMVP Friday, March 09, 2012 2:43 AM (From:Application Compatibility for Windows Desktop Development)
All Replies
-
Friday, March 09, 2012 7:48 PM
case WM_CTLCOLORSTATIC : { HDC hdc = (HDC)wParam; HWND hWnd = (HWND)IParam; if(hWnd == hCheckBox) { SetBkMode(hdc,TRANSPARENT); SetTextColor(hdc,RGB(0,255,0)); return (LRESULT)hBrush; } } break;Remember checkbox sends a CTLCOLORSTATIC and not CTLCOLORBTN :) . In your text color i am not able to see any COLORREF parameter
::SetTextColor((HDC)wParam, m_crText); what is this m_crText . Did you specified any where your color or what
Thanks
Rupesh Shukla
- Edited by Pintu ShuklaMicrosoft Community Contributor Friday, March 09, 2012 7:51 PM
- Proposed As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Monday, March 12, 2012 1:34 AM
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Thursday, March 15, 2012 1:43 AM
-
Tuesday, March 20, 2012 1:31 PMThis link and the example code helped me (though not entirely - and as I am using PNG background with transparency and with 2 dialogs technique)
http://www.codeguru.com/forum/showthread.php?t=521126

