X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/deed8373ae8958d61f7b2ccd83648cfa4136e6b3..3fb8a2bcfb362fa35dadd142b0569059a784fbb3:/docs/doxygen/overviews/helloworld.h diff --git a/docs/doxygen/overviews/helloworld.h b/docs/doxygen/overviews/helloworld.h index ff5c20d287..12c8ae1cfb 100644 --- a/docs/doxygen/overviews/helloworld.h +++ b/docs/doxygen/overviews/helloworld.h @@ -10,20 +10,22 @@ @page overview_helloworld Hello World Example +@tableofcontents + This page shows a very simple wxWidgets program that can be used as a skeleton for your own code. While it does nothing very useful, it introduces a couple of important concepts and explains how to write a working wxWidgets application. -First, you have to include wxWidgets' header files, of course. This can -be done on a file by file basis (such as @c wx/window.h) or using one -global include (@c wx/wx.h) which includes most of the commonly needed headers -(although not all of them as there are simply too many wxWidgets headers to -pull in all of them). For the platforms with support for precompiled headers, -as indicated by @c WX_PRECOMP, this global header is already included by @c -wx/wxprec.h so we only include it for the other ones: +First, you have to include wxWidgets' header files, of course. This can be done +on a file by file basis (such as @c wx/window.h) or using one global include +(@c wx/wx.h) which includes most of the commonly needed headers (although not +all of them as there are simply too many wxWidgets headers to pull in all of +them). For the platforms with support for precompiled headers, as indicated by +@c WX_PRECOMP, this global header is already included by @c wx/wxprec.h so we +only include it for the other ones: @code -// wxWidgets "Hello world" Program +// wxWidgets "Hello world" Program // For compilers that support precompilation, includes "wx/wx.h". #include @@ -45,17 +47,16 @@ public: }; @endcode -The main window is created by deriving a class from wxFrame and -giving it a menu and a status bar in its constructor. Also, any class -that wishes to respond to any "event" (such as mouse clicks or -messages from the menu or a button) must declare an event table -using the macro below. +The main window is created by deriving a class from wxFrame and giving it a +menu and a status bar in its constructor. Also, any class that wishes to +respond to any "event" (such as mouse clicks or messages from the menu or a +button) must declare an event table using the macro below. -Finally, the way to react to such events must be done in "handlers". -In our sample, we react to three menu items, one for our custom menu -command and two for the standard "Exit" and "About" commands (any program -should normally implement the latter two). Notice that these handlers -don't need to be neither virtual nor public. +Finally, the way to react to such events must be done in "handlers". In our +sample, we react to three menu items, one for our custom menu command and two +for the standard "Exit" and "About" commands (any program should normally +implement the latter two). Notice that these handlers don't need to be neither +virtual nor public. @code class MyFrame: public wxFrame @@ -83,20 +84,20 @@ enum }; @endcode -Notice that you don't need to define identifiers for the "About" and "Exit" -We then proceed to actually implement an event table in which the events -are routed to their respective handler functions in the class MyFrame. +Notice that you don't need to define identifiers for the "About" and "Exit". We +then proceed to actually implement an event table in which the events are +routed to their respective handler functions in the class MyFrame. -There are predefined macros for routing all common events, ranging from -the selection of a list box entry to a resize event when a user resizes -a window on the screen. If @c wxID_ANY is given as the ID, the given handler will be -invoked for any event of the specified type, so that you could add just -one entry in the event table for all menu commands or all button commands etc. +There are predefined macros for routing all common events, ranging from the +selection of a list box entry to a resize event when a user resizes a window on +the screen. If @c wxID_ANY is given as the ID, the given handler will be +invoked for any event of the specified type, so that you could add just one +entry in the event table for all menu commands or all button commands etc. -The origin of the event can still be distinguished in the event handler as -the (only) parameter in an event handler is a reference to a wxEvent object, -which holds various information about the event (such as the ID of and a -pointer to the class, which emitted the event). +The origin of the event can still be distinguished in the event handler as the +(only) parameter in an event handler is a reference to a wxEvent object, which +holds various information about the event (such as the ID of and a pointer to +the class, which emitted the event). @code wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) @@ -106,31 +107,32 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) wxEND_EVENT_TABLE() @endcode -As in all programs there must be a "main" function. Under wxWidgets main is implemented -using this macro, which creates an application instance and starts the program. +As in all programs there must be a "main" function. Under wxWidgets main is +implemented using this macro, which creates an application instance and starts +the program. @code wxIMPLEMENT_APP(MyApp) @endcode -As mentioned above, wxApp::OnInit() is called upon startup and should be -used to initialize the program, maybe showing a "splash screen" and creating -the main window (or several). The frame should get a title bar text ("Hello World") -and a position and start-up size. One frame can also be declared to be the -top window. Returning @true indicates a successful initialization. +As mentioned above, wxApp::OnInit() is called upon startup and should be used +to initialize the program, maybe showing a "splash screen" and creating the +main window (or several). The frame should get a title bar text ("Hello World") +and a position and start-up size. One frame can also be declared to be the top +window. Returning @true indicates a successful initialization. @code bool MyApp::OnInit() { - MyFrame *frame = new MyFrame( "Hello World", wxPoint(50,50), wxSize(450,340) ); + MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) ); frame->Show( true ); return true; } @endcode -In the constructor of the main window (or later on) we create a menu with our menu -items as well as a status bar to be shown at the bottom of the main window. Both have -to be associated with the frame with respective calls. +In the constructor of the main window (or later on) we create a menu with our +menu items as well as a status bar to be shown at the bottom of the main +window. Both have to be associated with the frame with respective calls. @code MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) @@ -188,6 +190,7 @@ void MyFrame::OnAbout(wxCommandEvent& event) The implementation of custom menu command handler may perform whatever task your program needs to do, in this case we will simply show a message from it as befits a hello world example: + @code void MyFrame::OnHello(wxCommandEvent& event) { @@ -196,8 +199,9 @@ void MyFrame::OnHello(wxCommandEvent& event) @endcode Here is the entire program that can be copied and pasted: + @code -// wxWidgets "Hello world" Program +// wxWidgets "Hello world" Program // For compilers that support precompilation, includes "wx/wx.h". #include @@ -240,7 +244,7 @@ wxIMPLEMENT_APP(MyApp); bool MyApp::OnInit() { - MyFrame *frame = new MyFrame( "Hello World", wxPoint(50,50), wxSize(450,340) ); + MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) ); frame->Show( true ); return true; } @@ -285,4 +289,3 @@ void MyFrame::OnHello(wxCommandEvent& event) @endcode */ -