We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Using the exclamation icon from AfxMessageBox in my own message box

clintMon
clintMon asked
on
Medium Priority
985 Views
Last Modified: 2009-01-29
I have created my own dialog that will serve as a custom message box.  But I need to steal the exclamation image from the standard message box.  I took a screen shot, pasted into paint, and make a .bmp file that contains only the triangular exclamation point image (and the white box around it).  The problem is this white box.  I need to put this bitmap on my dialog, on a button, a picture box, or a CStatic.  I don't really care which control, to be honest.  But I can't seem to get rid of that white box around the bitmap.  Any thoughts?
Comment
Watch Question

CERTIFIED EXPERT
Author of the Year 2009

Commented:
Make it into an icon instead.  You can usually put an ICON resource in the same places you can put a BMP... just use the Resource Editor to set the white part as the background color.

-- Dan

Author

Commented:
OK.  In my res folder in my project, i need to have the exclamation point image saved as an icon (an .ico extension).  How do I make my exclamation point image into an .ico file?
CERTIFIED EXPERT
Author of the Year 2009

Commented:
You don't need an .ico file -- you can create one from scratch

1) Open PBrush and create a 32x32 color image
2) Press Ctrl+A and Ctrl+C  (copy the entire thing to the clipboard)
3) In VC++ IDE, click the Resources tab.  
4) Locate "<yourProject> resources"
5) right-click it and select "Insert..."
6) Select "Icon" and click [New]
7) Press Ctrl+V  (paste the 32x32 bitmap from the clipboard)

You might be all done... by default, anything that was white in the bitmap will be mapped to that blue-greenish color that (in the Icon Editor) means "the transparent background"

Close the icon editor window.  If you want, you can "rename" the icon to give it a different ID (other than IDI_ICON1) by right-clicking it in the tree and selecting Properties.  If you really want to own a lovely .ICO file, you can right-click it in the tree and select "Export..."

There is lots of additional info in the online help for the resource editor that comes with Visual C++

-- Dan
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>But I need to steal the exclamation image from the standard message box

Why not just loading it from the DLL it resides in using 'LoadIcon()'? That also prevents copyright issues.
CERTIFIED EXPERT
Top Expert 2012
Commented:
*Argh*, even *way* easier:

HICON hiExclamationMark = LoadIcon(NULL,IDI_EXCLAMATION);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
BTW, if that is really a message box, why aren't you using

MessageBox(NULL,"Test text","Caption",MB_ICONEXCLAMATION | MB_OK);

in the 1st place.

Author

Commented:
Thanks jkr, et al.  Worked like a charm.   I knew there had to be a cinch way to do this, even though C++ sometimes makes mountains out of molehills.

My exact WORKING code, for anyone else who wants to know, is:

// put a picture control (CStatic) on the dialog;

// associate a variable with it:
CStatic      m_picture;

//In OnInitDialog(), get an icon handle to the desired image (in my case, this was the exclamation point icon on the standard windows message box)
HICON hiExclamationMark = LoadIcon(NULL,IDI_EXCLAMATION);      

//load icon into the desired control (in my case, the picture control (CStatic))
m_picture.SetIcon(hiExclamationMark);      

That's it.




Author

Commented:
One more thing:

>> BTW, if that is really a message box, why aren't you using MessageBox(NULL,"Test text","Caption",MB_ICONEXCLAMATION | MB_OK); in the 1st place?

Because I needed to change the text on the dialog's buttons (from "Yes", "No", or "OK", "Cancel", to "Delete" and "Convert"
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.