Solved

Setting a dialog's Background color

Posted on 2004-04-29
13
2,839 Views
Last Modified: 2009-01-31
Hi all...

I know that I can use the WM_CTLCOLORDLG message from a dialogs callback to set the BG color of the dialog, but is there away to set it outside of the callback.  What I mean is I have a child dialog embedded in a window and it does not need a callback proc. but I still want to change the color of it from the ugly gray!

Thanks :)  
0
Comment
Question by:alsmorris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 5

Expert Comment

by:drnick
ID: 10956290
hm, what do you mean with outside callback?
i mean, you can send WM_,,, to the dialogs window handle from everwhere, i think.
you could use SendMessage and GetForegroundWindow .
with GetForegroundWindow get the dialogs window handle,
where i assume you dialog is active,
and then send the message.

0
 

Author Comment

by:alsmorris
ID: 10956393
hi drnick,

By outside a callback I mean the dialog does not have one ... ::CreateDialog(hInstance,(LPCTSTR)IDD_DIALOG,hWnd,NULL);
but I want to change the background color of the dialog.  If I can avoid adding another callback that would be great!

From what I understand (from MSDN) the WM_CTLCOLORDLG is a nofication and you cannot set the dialog color by called it from ::SendMessage().   I guess what I'm trying to say is; Is there another way to change the color of a dialog box other than the WM_CTLCOLORDLG  notification message.

Thanks
0
 
LVL 5

Expert Comment

by:drnick
ID: 10961648
hm, i think you are right,
sorry, but i don't remember another way by now,
but will keep thinking about it :-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:RJSoft
ID: 11028435
For dialog based apps in your application class you create a public function and uses api
void MyColors(int In)
{
if(In==1)
SetDialogBkColor(RGB(Red1,Green1,Blue1));
if(In==2)
SetDialogBkColor(RGB(Red2,Green2,Blue2));
}

Then call that function in InitInstance

You can even try getting away with changing child dialogs color by
calling the above function using parent pointer to app class in the child dialogs OnInitDialog func

      CMyApp *Ca=(CMyApp*)GetParent();
      Ca->DialogColor(2);

I can get away with this because my child dialog covers the parent so it dont look bad. Also I have dialog window styles that are not moveable by the user.

RJ
0
 

Author Comment

by:alsmorris
ID: 11032986
Thank for the comment RJSoft,

But the problem is I'm not using MFC and I think the SetDialogBkColor function is MFC only?

Thanks!
0
 
LVL 3

Expert Comment

by:RJSoft
ID: 11033163
Most everything mfc has api equivalent.

So my guess would be to capture message WM_CTLCOLORDLG from your application class. Or maybe application main window.

Then use SendMessage.

RJ
0
 

Author Comment

by:alsmorris
ID: 11033526
RJSoft,

The WM_CTLCOLORDLG message is a notification message and cannot be sent by SendMessage... It would be cool if we could see the source for the MFC SetDialogBkColor to see how it does it :)  I think there is no way around it, I will probably have to use the WM_CTLCOLORDLG inside the callback to set the Dlg color.
0
 
LVL 3

Accepted Solution

by:
RJSoft earned 125 total points
ID: 11036398
Yes your right. It's been a long while since I toyed arround with that one.

Also I seem to recall some notes from "Charlse Petzold" (Windows api programming guru) about how you cant use it to change the dialog button color.

Here is an old example code from a Turbo C++ 3.1 (16 bit)OWL.
I remember giving up on it after I read some of the notes from Petzold.
But I believe that some controls can be altered this way.

Maybe it could help a little, giving you some better clues as how to start.

RJ

//In .h file
HBRUSH WMCtlColor(RTMessage msg)=[WM_FIRST + WM_CTLCOLOR];



// You would use CTLCOLOR_DLG
// or maybe capture WM_CTLCOLORDLG instead

HBRUSH TMainWindow::WMCtlColor(RTMessage msg)
{
if( HIWORD(msg.LParam)==CTLCOLOR_BTN)
{
SetTextColor((HDC) msg.WParam, RGB(255, 0, 0));
SetBkMode((HDC) msg.WParam, TRANSPARENT);
return MyBrush;
}
else return NULL;
}//endfunc
0
 

Author Comment

by:alsmorris
ID: 11225434
Well I'm giving up on this and creating a callback for the dialog.  I'm awarding the points to RJSoft as he/she had the most ideas on this one :)
0
 
LVL 3

Expert Comment

by:RJSoft
ID: 11229224
He;
Thanks
Later
0
 

Author Comment

by:alsmorris
ID: 11235278
Haha,

Sorry dude just trying to be politically correct :P

0
 
LVL 3

Expert Comment

by:RJSoft
ID: 11241354
No problemo.

BTW, Do yourself a favor and switch to MFC Visual C++ (try to get 7.0 if you can). All I have is VC++6.0 standard edition and I have been happy with it.

I used to program with Borland and finally switched over to VC. At first I was intimidated but now I would not even consider going back to Borland/Inprize ever again. Took a couple of weeks for me to adjust.

Problem was I took way too long to make the switch. So I got seriously behind. By now I should be proficcient in C# and .Net. But I'm slow like a turtle.

Too many features built into the MFC Visual studio to ever consider going back to Inprize. But it makes sense when you think of it cause it's thier operating system.

If you do decide to switch. Check out Jeff Procise book Programming Visual C++ 6.0. Great book.

Later.
RJ
0
 

Author Comment

by:alsmorris
ID: 11251359
Thank RJ,

I acutally have a copy of that book somewhere.  I'm one of those people who avoids MFC.  I guess you could call me an old skooler but I hate having to depend or statically link those MFC librarbies :)

:))
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

624 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