wxMessageBox and unwanted icons -- bug? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
celstark
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Aug 26, 2005 7:37 pm

wxMessageBox and unwanted icons -- bug?

Post by celstark » Thu Nov 17, 2005 9:49 pm

I want to be able to display some simple text for the user with an OK button. Unlike most times I call wxMessageBox, this time I want it clean. No icons and even no beeps if possible. (Yes, I know I could create my own dialog to do this, but I think wxMessageBox should be able to do this -- I think this is a bug.)

According to the 2.6.1 docs, the default style should be wxOK. So, I call the following:
wxMessageBox(info_str,_T("Measurements"));

This gives me the OK button and an Information icon. Interestingly, calling this:
wxMessageBox(info_str,_T("Measurements"), wxID_OK);

will give me the OK button and an Error icon. Something is already amiss then as the icon has changed.

If I try to disable the icon:
wxMessageBox(info_str,_T("Measurements"), ~wxICON_INFORMATION);

I now get the Error icon and both the OK and Cancel buttons (where the heck did Cancel come from?)

Now, trying to turn off all icon output with this:
wxMessageBox(info_str,_T("Measurements"),wxID_OK | ~(wxICON_INFORMATION | wxICON_HAND | wxICON_QUESTION | wxICON_ERROR ));

and I get both the OK button and the Cancel button along with an Error icon. I can rid myself of the Cancel button:
wxMessageBox(info_str,_T("Measurements"),wxID_OK | ~(wxCANCEL | wxICON_INFORMATION | wxICON_HAND | wxICON_QUESTION | wxICON_ERROR ));

but, I'm still left with the Error icon.

So, unless I'm missing something here, the handling of the various buttons and icons isn't working properly. Am I missing something?

Craig

chris
I live to help wx-kind
I live to help wx-kind
Posts: 150
Joined: Fri Oct 08, 2004 2:05 pm
Location: Europe

Post by chris » Thu Nov 17, 2005 10:45 pm

Hi Craig,

I did not test your problems myself, but I did notice you try to pass wxID_OK as a style flag. I think you mixed this up with wxOK, which is the proper style flag to use.

Hope this helps a bit,

Chris
this->signature=NULL;

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: wxMessageBox and unwanted icons -- bug?

Post by upCASE » Fri Nov 18, 2005 8:04 am

celstark wrote:I want to be able to display some simple text for the user with an OK button. Unlike most times I call wxMessageBox, this time I want it clean. No icons and even no beeps if possible. (Yes, I know I could create my own dialog to do this, but I think wxMessageBox should be able to do this -- I think this is a bug.)
It's not really a bug, more a feature.

wxMessageBox uses wxMessageDialog. When called, wxMessageBox will create a wxMessageDialog and show it. The style will be modified as follows

Code: Select all

if ( ( style & ( wxICON_EXCLAMATION | wxICON_HAND | wxICON_INFORMATION | wxICON_QUESTION ) ) == 0 )
    {
        decorated_style |= ( style & wxYES ) ? wxICON_QUESTION : wxICON_INFORMATION ;
    }
decorated_style is the style for the wxMessageDialog. So, if you don't specify an icon, wxMessageBox will add one, guessing which one might be the right one. This is done for convenience as you don't have to pass an icon.

To create a message box without an icon, use wxMessageDialog directly:

Code: Select all

	wxMessageDialog dlg(parent, "Test","Caption",wxOK);
	dlg.ShowModal();
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

celstark
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Aug 26, 2005 7:37 pm

Post by celstark » Fri Nov 18, 2005 4:50 pm

Got it -- I'd actually not come across wxMessageDialog somehow -- thanks.

I'd found the wxMessageBox and it's described as the general purpose message dialog. I agree that the attempt to guess a default icon is certainly a handy feature. If possible -- since this can't be overridden in wxMessageBox, a link in the help file much like the "See also _____" pointing people to wxMessageDialog would be a helpful addition as it's even more general purpose.

Anyway, thanks for the help! All fixed!

Craig

Post Reply