Shortest wxWidgets Program

Source: Internet
Author: User
Tags wxwidgets
Write c ++ Program What tools are used? In Linux, I think netbeans6.1 is still good. In Windows, there is no tool that will surpass ms. However, the Professional Edition is too expensive, and Microsoft Visual C ++ 2008 quick version is free of charge. However, there is no MFC in the quick version, so you have to select a GUI library. ---- In fact, you don't need to use MFC ...... There are many GUI Libraries, but few are mature, rich documentation, free and cross-platform. It is said that QT is good, but qt's authorization on vs is not free and not written in standard C ++. Therefore, wxWidgets is selected. This library is hard to tell its shortcomings. If you have to find out, wxWidgets is too similar to MFC. Some people say that he is not trendy enough to use a lot of templates and so on. If you are bored, I will not talk about it.
A wxWidgets program should at least look like this: # Include " Wx/wx. h "
Class Plot3dapp: Public Wxapp {
Virtual BoolOninit ();
} ;

Class Plot3dframe: Public Wxframe {
Plot3dframe (ConstWxstring&Title );
} ;

Implement_app (plot3dapp)
Bool Plot3dapp: oninit () {
Plot3dframe*Frame=NewPlot3dframe (wxt ("Plot3d"));
Frame->Show (True);
Return True;

Plot3dframe: plot3dframe ( Const Wxstring & Title)
: Wxframe (null, wxid_any, title) {}

After compilation

There are several points to note about this program:
1) how to compile. Of course, first compile the wxWidgets library. The ide I use is Microsoft Visual C ++ 2008 quick build.
Set after compilation:
Contains file path: C: \ wxWidgets-2.8.7 \ include
And C: \ wxWidgets-2.8.7 \ Lib \ vc_lib \ mswd;
Library path: C: \ wxWidgets-2.8.7 \ Lib \ vc_lib
Project property settings:
Preprocessor defines Win32; _ debug ;__ wxmsw __;__ wxdebug __; _ windows; nopch
Enter wxmsw28d_core.lib wxbase28d_net.lib wxbase28d for the connector. lib wxmongod. lib wxmongod. lib wxpngd. lib wxzlibd. lib wxregexd. lib wxexpatd. lib winmm. lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib (of course, you can see that the library I compiled is the debug version)

2) It indicates that a wxWidgets program must define at least two classes: an app class inherited from wxapp, which must define the virtual bool oninit () function and a frame class inherited from wxframe;

3) the virtual bool oninit () function must at least implement a similar

Plot3dframe * Frame = New Plot3dframe (wxt ( " Plot3d " ));
Frame -> Show ( True );

These two functions construct a frame class and display it, entering the message loop;

4) for the frame class, set the two parameters of the parent wxframe class:: Wxframe (null, wxid_any, title)

5) Where is main () or winmain?

# Define Implement_app (appname )\
Implement_app_no_themes (appname )\
/* * ************** (1 )****************** */
# Define Implement_app_no_themes (appname )\
Implement_app_no_main (appname )\
/* * ************** (1.2 )****************** */
# Define Implement_wxwin_main \
Extern   " C "   Int Winapi winmain (hinstance ,\
Hinstance hprevinstance ,\
Wxw.lineargtype lpcmdline ,\
Int Ncmdshow )\
Return Wxentry (hinstance, hprevinstance, lpcmdline, ncmdshow );\

Have you seen it? It seems that every C ++ program must have a main function, which is good. Just like the conservation of energy, one cannot be masked by the appearance. The difference lies only in the way it is packaged and hidden.
6) possible errors, especially connection errors:
Main. OBJ: Error lnk2001: unresolved external symbol "public: Virtual bool _ thiscall wxapp: Initialize (Int &, wchar_t **)"(? Initialize @ wxapp @ uae_naahpapa_w @ Z)
Note that the parameter "wchar_t **" is related to Unicode, change the settings project> Properties> Configuration Properties> General> Project ults> character set (use Unicode Character Set and not set)

7) I am wrong, but it can be shorter: # Include " Wx/wx. h "
Class Plot3dapp: Public Wxapp {
Virtual BoolOninit ();
} ;
Implement_app (plot3dapp)
Bool Plot3dapp: oninit () {
Wxframe*Frame=NewWxframe (null, wxid_any, wxt ("Plot3d"));
Frame->Show (True);
Return True;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.