Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2880
  • Last Modified:

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 :)  
0
alsmorris
Asked:
alsmorris
  • 6
  • 5
  • 2
1 Solution
 
drnickCommented:
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
 
alsmorrisAuthor Commented:
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
 
drnickCommented:
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!

 
RJSoftCommented:
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
 
alsmorrisAuthor Commented:
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
 
RJSoftCommented:
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
 
alsmorrisAuthor Commented:
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
 
RJSoftCommented:
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
 
alsmorrisAuthor Commented:
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
 
RJSoftCommented:
He;
Thanks
Later
0
 
alsmorrisAuthor Commented:
Haha,

Sorry dude just trying to be politically correct :P

0
 
RJSoftCommented:
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
 
alsmorrisAuthor Commented:
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.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now