Solved

Setting a dialog's Background color

Posted on 2004-04-29
13
2,811 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which Linux flavors will this run on? 6 103
C++ mouse_event mouse look 7 112
Outlook 13 85
Create a worker thread ( servicing thread) using the Message queue 3 23
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

697 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