• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

Using the exclamation icon from AfxMessageBox in my own message box

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?
0
clintMon
Asked:
clintMon
  • 3
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
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
0
 
clintMonAuthor 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?
0
 
DanRollinsCommented:
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jkrCommented:
>>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.
0
 
jkrCommented:
*Argh*, even *way* easier:

HICON hiExclamationMark = LoadIcon(NULL,IDI_EXCLAMATION);
0
 
jkrCommented:
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.
0
 
clintMonAuthor 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.




0
 
clintMonAuthor 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"
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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