Google Answers Logo
View Question
 
Q: Colored Dialog Boxes in Windows ( Answered 4 out of 5 stars,   1 Comment )
Question  
Subject: Colored Dialog Boxes in Windows
Category: Computers > Programming
Asked by: harryh-ga
List Price: $10.00
Posted: 08 Jan 2003 20:25 PST
Expires: 07 Feb 2003 20:25 PST
Question ID: 139638
When creating dialog boxes in windows they are (by default) Grey with
black text (or more propery whatever color combination is set up in
the Appearance Tab in the Display Properties Control Panel).

I want to make a dialog box with a different color scheme.  What is
the cleanest way to do this?  I would have thought I could set some
sort of property in the dialog box resource, but that doens't seem
possible???

-Harry

Request for Question Clarification by skermit-ga on 08 Jan 2003 20:28 PST
Methinks you're asking about VB or VC++?

skermit-ga

Clarification of Question by harryh-ga on 08 Jan 2003 20:38 PST
To Clarify: I need the answer for VC++.

Request for Question Clarification by studboy-ga on 08 Jan 2003 21:53 PST
Have you tried handling the WM_CTLCOLOR message and using
CWinApp::SetDialogBkColor ?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_setting_the_dialog_box.92.s_background_color.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwinapp.3a3a.setdialogbkcolor.asp

Clarification of Question by harryh-ga on 08 Jan 2003 22:04 PST
I am not using MFC.  Just the straight windows APIs.
These comments might lead me in the right direction though (i'm looing into it).

Clarification of Question by harryh-ga on 08 Jan 2003 22:36 PST
OK, I've figured the following out.

In the Dialog box procedure, create one new variable, and add some
stuff to three different messages.

static HBRUSH hb;

WM_INITDIALOG:
    CreateSolidBrush(RGB(0,0,255));

WM_CTLCOLORDLG:
    return (INT_PTR)hb;

WM_DESTROY:
    DeleteObject(hb);

Now the backgreound of the dialog box is blue.
But I have some child controls in my dialog box.  All of their
backgrouds are still gray.  What do I need to do for them?

-Harry

Request for Question Clarification by studboy-ga on 08 Jan 2003 23:13 PST
OK, I think you want to use these (depending on your child) to 
return the brush:

WM_CTLCOLORBTN 
WM_CTLCOLOREDIT 
WM_CTLCOLORLISTBOX 
WM_CTLCOLORSCROLLBAR 
WM_CTLCOLORSTATIC 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devnotes/winprog/wm_ctlcolor_notification.asp

Let me know if this is what you want.

Request for Question Clarification by studboy-ga on 08 Jan 2003 23:16 PST
I mean do what you did for the dialog box to each of your child
control--handling the corresponding WM_CTLCOLOR message (depending on
the type of child control: button, edit, list, etc) to return the
desired color drawing brush.

Clarification of Question by harryh-ga on 08 Jan 2003 23:35 PST
handling these starts to do what I want, but doesn't get all the way.

WM_CTLCOLORBTN  
WM_CTLCOLOREDIT  
WM_CTLCOLORLISTBOX  
WM_CTLCOLORSCROLLBAR  
WM_CTLCOLORSTATIC  

Push Buttons are still gray.  In WM_CTLCOLORBTN MSDN sayss I have to
do an owner draw button if I want a not-grey button.  Can this be
right??  There is no way to tell windows to dray me a button
automatically in any color but the default?

Also for some reasons the dots in my radio buttons, and the checks in
my checkboxes are still showing up Black.  (Even if I SetTextColor()
while handling the messages).

Request for Question Clarification by studboy-ga on 08 Jan 2003 23:54 PST
Unfortunately, I'm afraid the MSDN document is right :)

I did some forum searches and other people confirmed this:

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_10076166.html

You are also correct about the dots and checks, unfortunately...

Request for Question Clarification by studboy-ga on 09 Jan 2003 00:01 PST
See the comments posted to that "rejected" forum answer--
it mentions the checks as well.

Well, sorry Harry.  This is how Microsoft implemented it.

Anyway, it's up to you to decide whether I deserve a compensation or not.

Let me know if you want me to help you with the owner drawn
custom control (but I think you probably know how to do
this already--just a bit of a hassle).

Clarification of Question by harryh-ga on 09 Jan 2003 00:14 PST
Looks like you've lead me as far as you can studboy.
You've been a GREAT help.  You totally deserve compensation.

Do I just click on "Close Question" and it will take me to the payment screen?
Answer  
Subject: Re: Colored Dialog Boxes in Windows
Answered By: studboy-ga on 09 Jan 2003 01:05 PST
Rated:4 out of 5 stars
 
Thanks Harry.  You're very welcomed!

Sorry I wasn't able to help you further with changing the default 
gray color of the push button control without creating your own
custom user control.  

As you have pointed out (and self discovered :), some controls/dialogs'
colors are changeable by handling the WM_CTLCOLOR messages to return
a brush of the desired color.  Unfortunately, push buttons do not 
use the returned brush...

Thanks again and happy programming!
harryh-ga rated this answer:4 out of 5 stars
studboy was extremely helpful with my question.  and very fast with
the responses in our little conversation

Comments  
Subject: Re: Colored Dialog Boxes in Windows
From: studboy-ga on 08 Jan 2003 21:59 PST
 
Check out this sample:

http://www.codeguru.com/combobox/combo_dropdown_dropdownlist.shtml

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy