Solved

Checkbox/static color

Posted on 2009-07-10
6
1,303 Views
Last Modified: 2013-12-04
I've colored my window :RGB(195,217,250)

And I have created a static and a checkbox in my WM_CREATE but they come out that there is a grey rectangle arround the text I was wondering how to color it the same as the solidbrush of the window, I've tried doing SetBkColor(GetDc(..),[color]) in the WM_CREATE but it doesn't work. Please help.

//Register the window class

	wc.cbSize = sizeof(WNDCLASSEX);

	wc.style = 0;

	wc.lpfnWndProc = WndProc;

	wc.cbClsExtra=0;

	wc.cbWndExtra=0;

	wc.hInstance=hInst;

	wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);

	wc.hCursor = LoadCursor(NULL,IDC_ARROW);

	wc.hbrBackground=CreateSolidBrush(RGB(195,217,250));//(HBRUSH)(COLOR_WINDOW);

	wc.lpszMenuName=NULL;

	wc.lpszClassName=g_szClassName;

	wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 

//-----------------------------------------------------------------------------------------------------------------

//create seach label

	hwndlblSearch = CreateWindowEx(0,TEXT("static"),TEXT("Table/View name"),SS_LEFT|WS_CHILD|WS_VISIBLE,33,10,116,17,hwnd,(HMENU)lblSearch,NULL,NULL);
 

//Checkbox Table

	hwndcbTable = CreateWindowEx(0,TEXT("BUTTON"),TEXT("Table"),BS_AUTOCHECKBOX|WS_VISIBLE|WS_CHILD,265,32,100,25,hwnd,(HMENU)cbTable,NULL,NULL);

Open in new window

0
Comment
Question by:james2432
  • 3
  • 2
6 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 24822055
Hi james2432,

IMO there's no easy solution for this - the problem simply is that a standard checkbox just draws the text in none-transparent (opaque) drawing mode, so the background of the text is always filled with the background color (GetBkColor) of the DC used for its drawing.

You could try to replace the WndProc of the checkbox (with SetWindowLong) with one of your own which handles WM_PAINT message in a way it modifies the DC's (you can retrieve it with GetDC) text drawing mode to TRANSPARENT (SetBkMode), then call it's original WndProc (CallWndProc) and, if needed, afterwards restore the previous drawing mode.

Hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:james2432
ID: 24822391
I don't really understand...
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 75 total points
ID: 24826935
Zoppo said that the easiest way to implement your idea is to make your own control that will know how to draw itself.
Once we tried to do that without own control - terrible - set a hook was really not easy.
It's about the checkbox.
"static" means a text label - CStatic? if yes, look on this site for WM_CTLCOLOR or for OnCtlColor.
0
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.

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 24827002
More info:
1. here is a proposal (color checkbox class): http://www.codeguru.com/cpp/controls/controls/checkboxcontrols/article.php/c5319
2. here is the same question (maybe interesting to read): http://www.eggheadcafe.com/forumarchives/win32programmergdi/Sep2005/post23674033.asp
 
0
 
LVL 1

Author Comment

by:james2432
ID: 24827785
Yeah this was WIN32..

Anyways i got the label(static) with WM_CTLCOLORSTATIC message
I set a brush to the background color
SetBkColor()
SetBkMode() to transparent
and returned the brush I created

the checkbox dispite being a "BUTTON" seeing as it's static text it can be done via same WM
the same goes for a groupbox

No need for subclassing
Thank you
0
 
LVL 1

Author Closing Comment

by:james2432
ID: 31602011
Because this is a win32api application I couldn't use MFC or AFX, but you set me on the right track
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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

911 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

17 Experts available now in Live!

Get 1:1 Help Now