Solved

Setting a dialog's Background color

Posted on 2004-04-29
13
2,776 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
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

22 Experts available now in Live!

Get 1:1 Help Now