Link to home
Start Free TrialLog in
Avatar of alsmorris
alsmorris

asked on

Setting a dialog's Background color

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 :)  
Avatar of drnick
drnick

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.

Avatar of alsmorris

ASKER

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
hm, i think you are right,
sorry, but i don't remember another way by now,
but will keep thinking about it :-)
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
Thank for the comment RJSoft,

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

Thanks!
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
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.
ASKER CERTIFIED SOLUTION
Avatar of RJSoft
RJSoft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)
He;
Thanks
Later
Haha,

Sorry dude just trying to be politically correct :P

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
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 :)

:))