|
-
Feb 20th, 2002, 02:11 AM
#1
Thread Starter
Addicted Member
Changing a Button's Color
I want to change the color of a button in a dialogbox, I have been doing the following but it doesn't work, I stepped through and the cases do get each called, but it has no effect on the buttons.
<code>
case WM_CTLCOLORBTN:
switch((GetWindowLong((HWND)lParam,GWL_ID))){
case IDC_LINE1:
SetBkColor((HDC) wParam,RGB(255,0,0));
SetTextColor((HDC)wParam, RGB(255,255,255));
case IDC_LINE2:
SetBkColor((HDC) wParam,RGB(0,255,0));
SetTextColor((HDC)wParam, RGB(255,255,255));
case IDC_LINE3:
SetBkColor((HDC) wParam,RGB(0,0,255));
SetTextColor((HDC)wParam, RGB(255,255,255));
}
return ((LRESULT) CreateSolidBrush(RGB(0,0,0)));
</code>
-
Feb 20th, 2002, 11:52 AM
#2
Since your function probably is a DialogProc, the return value is a BOOL and you should return TRUE if you handle the message. The real return value (the LRESULT of a WndProc) is accessed by
SetWindowLong(hDlg, DWL_MSGRESULT, (LONG)result);
This probably won't solve your main problem though.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 20th, 2002, 09:20 PM
#3
Thread Starter
Addicted Member
Nope that doesn't help at all and nope you shouldn't return TRUE regardless, have a look at the help.
I changed the buttons in the VC++ compiler for the dialog boxes so they are owner draw and the follwing code will change the color, but now the text has disapeared regardless of what color I set the text color it won't come back.
<CODE>
case WM_CTLCOLORBTN:/*getting called twice?*/
switch((GetWindowLong((HWND)lParam,GWL_ID))){
case IDC_LINE1:
SetBkColor((HDC) wParam,RGB(255,0,0));
SetTextColor((HDC)wParam, RGB(255,255,255));
temp = GetBkColor((HDC)wParam);
break;
case IDC_LINE2:
SetBkColor((HDC) wParam,RGB(0,255,0));
SetTextColor((HDC)wParam, RGB(255,255,255));
temp = GetBkColor((HDC)wParam);
break;
case IDC_LINE3:
SetBkColor((HDC) wParam,RGB(0,0,255));
SetTextColor((HDC)wParam, RGB(255,255,255));
temp = GetBkColor((HDC)wParam);
break;
}
return ((LRESULT) CreateSolidBrush(temp));
</CODE>
-
Feb 21st, 2002, 10:23 AM
#4
owner draw buttons don't have text, they need to be drawn completely by you.
I did look that thing up in help, it's in the topic "DialogProc".
And you shouldn't create a new brush every time, you should create one for each button at dialog initialization and destroy them at dialog destruction.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|