Page 1 of 1

* Cannot use wxMessageBox in console application?

Posted: Fri Aug 14, 2015 2:20 am
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]

Re: * Cannot use wxMessageBox in console application?

Posted: Fri Aug 14, 2015 7:14 am
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/

Re: * Cannot use wxMessageBox in console application?

Posted: Fri Aug 14, 2015 9:30 am
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. :-)

Re: * Cannot use wxMessageBox in console application?

Posted: Fri Aug 14, 2015 1:51 pm
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?

Re: * Cannot use wxMessageBox in console application?

Posted: Fri Aug 14, 2015 2:21 pm
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?