* Cannot use wxMessageBox in console application?

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
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

* Cannot use wxMessageBox in console application?

Post by whoops »

i'm using wxMessageBox function in a console application, but it threw a exception:
Unhandled exception at 0x00000000 in console.exe: 0xC0000005: Access violation.

here is the code:

Code: Select all

#include <wx/wx.h>
int main()
{
	wxInitializer wx;
	if( !wx.IsOk() ) return -1;
	// threw a run-time exception
	wxMessageBox(wxT("Press OK"), wxT("Prompt"), wxOK);
	return 0;
}
i'm using wxWidgets 3.0.2 and Microsoft Visual C++ 2010 Express to build this.
i think it may because console is not a frame or a dialog in wx, so (wxWindow *) 0 would go nowhere.
here is the constractor of wxMessageBox of:
int wxMessageBox (const wxString & message, const wxString & caption = wxMessageBoxCaptionStr, int style = wxOK|wxCENTRE, wxWindow * parent = NULL, int x = wxDefaultCoord, int y = wxDefaultCoord)
it's possible to call a wxMessageBox in console application?
[/size]
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: * Cannot use wxMessageBox in console application?

Post by doublemax »

it's possible to call a wxMessageBox in console application?
No. No gui classes at all.

The question is: What do you want to do with wxWidgets? It is primarily a GUI framework. If you want to build a GUI application in the end, you should start with the "minimal" sample that comes with wxWidgets and go from there.

Maybe this tutorial can help:
http://zetcode.com/gui/wxwidgets/
Use the source, Luke!
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: * Cannot use wxMessageBox in console application?

Post by whoops »

in fact, i've read the wxWidgets tutorial in zetcode http://zetcode.com/gui/wxwidgets/
i'm sorry if this question is stupid, but i think tutorial in zetcode is not enough for me, anyhow
now i'm reading "wxbook" Cross-Platform GUI Programming With wxWidget

do you have any advice for me to learn wxWidgets? i'm new to here, and my english is not good enough,
but it's fine to me to read english documentations. :-)
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: * Cannot use wxMessageBox in console application?

Post by doublemax »

I think the zetcode tutorial is very good except for some minor details.

But everyone has a different type of learning, what exactly are you missing?
Use the source, Luke!
User avatar
whoops
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sat Jun 27, 2015 5:53 am
Location: China

Re: * Cannot use wxMessageBox in console application?

Post by whoops »

have you heard of BOINC https://boinc.berkeley.edu/ (a open-source software for volunteer computing)?
because BOINC using wxWidgets to build BOINC Manager, so i learn wxWidgets,
i want to build a volunteer computing project using wxWidgets, but not make it into BOINC,
just using wxWidgets to design the client application, but it may needs me to deal with multithread, RPC, networking, socket...
but i don't know where to go, do you have any suggestions to me?
 Things being equal, the simplest explanation tends to be the right.

 [ Windows 7 Ultimate x64 | wxWidgets 3.0.2 | Microsoft Visual C++ 2010 Express ]
Post Reply