WM_CTLCOLORMSGBOX - How?

Unfortuinately it doesn't work in my app.
50 Points for a working description or
source code.

thanks
OnkelAsked:
Who is Participating?
 
nietodConnect With a Mentor Commented:
if there is only one message box up at a time, use a global variable or one related to the owner window to determine how to handle message box.  

If message boxes can be poping up simultaneously, you can use the handle to find out things about the message box.  You can get the title for example.  

Its not a great way of going things, but if it works, its pretty easy.  If it doesn't work, create your own message box from scratch.  (That's what I do.)  Its not hard to do and much more flexible.  I can give more details, if you need.
0
 
nietodCommented:
Just convert the WParam to a DCH.  Set the foreground and background colors and return a brush handle.

case WM_CTLCOLORMSGOX:
{
   HDC    DCHnd  = (HDC) WParam;
   HBRUSH BckBrh = CreateSolidBrush(RGB(0,255,0));  // Green background brush.
   SetTextColor(DCHnd,RGB(255,0,0)); // Set red text.
   SetBkColor(DCHnd,RGB(0,255,0));   // Set green background.

   return (LRESULT) BckBrh;
}
0
 
nietodCommented:
If that isn't enough, post more info.  i.e. what are your trying to do and what is happening.  Posting source code is always good.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
OnkelAuthor Commented:
Well, your example looks almost like my code.

The main question seems to be where to place this message handling.
Usually messages in the MainWndProc do not return anything.
Another question is which MessageBox(I use some very regular ones
created with MessageBox(hwnd,text,captiontext,MB_OK);)
will show the color change. I tried various.
My aim are message boxes which use a selfdefined color.

I raised the reward to 55 points, that's all I have. :-)


0
 
nietodCommented:
You place the code in the window procedure of the window that owns the message box.  The owner window will get the message and the lParam will be the handle to the message box.  You can then test the lParam to see if it is one of the message box's you want to color differently.  If so, handle the message.  If not pass it on to the default window procedure.

I have to warn you, I've never used this, but it seems straightforeward.

As for messages in the main window procedure not returning anything.  That's not true.  Or I'm missunderstanding you.

0
 
OnkelAuthor Commented:
I will cite you:
"You can then test the lParam to see if it is one of the message box's you want to color differently."

But how do I do that?
My message boxes do not return any handle.
There are - as I mentioned before - various message boxes
which are all owned by the main window.
I think that I have to accept that all of them will
have the same color. But well, that's not a problem.



0
 
OnkelAuthor Commented:
WM_CTLCOLORMSGBOX does not occur in the main window
procedure. I checked that with a message box ;-)
and a message spy.
So it looks like I have to create a dialog finally.
Thanks for your help.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.