Solved

WM_CTLCOLORMSGBOX - How?

Posted on 1997-11-03
7
311 Views
Last Modified: 2013-12-03
Unfortuinately it doesn't work in my app.
50 Points for a working description or
source code.

thanks
0
Comment
Question by:Onkel
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1408150
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
 
LVL 22

Expert Comment

by:nietod
ID: 1408151
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
 

Author Comment

by:Onkel
ID: 1408152
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1408153
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
 

Author Comment

by:Onkel
ID: 1408154
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
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1408155
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
 

Author Comment

by:Onkel
ID: 1408156
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

13 Experts available now in Live!

Get 1:1 Help Now