Solved

WM_CTLCOLORMSGBOX - How?

Posted on 1997-11-03
7
301 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

15 Experts available now in Live!

Get 1:1 Help Now