Basic skeleton learnt:
Compiling:
g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello
Source code: hello.cpp
#include <wx/wx.h>
#include <iostream>
using namespace std;
// Create our Application class derived from wxApp
class MyApp: public wxApp
{
public:
bool OnInit(); // have to override onInit
};
class MainWindow: public wxFrame
{
public:
MainWindow(const wxString& title , const wxPoint& pos , const wxSize& size );
};
MainWindow::MainWindow(const wxString& title , const wxPoint& pos , const wxSize& size )
: wxFrame( NULL, -1, title, pos, size)
{
this->Show( TRUE);
};
bool MyApp::OnInit()
{
cout << "start\n";
MainWindow *mainFrame = new MainWindow( _T("Hello empty world"),wxPoint(-1,-1),wxSize(-1,-1));
this->SetTopWindow( mainFrame);
//mainFrame->Show( TRUE);
return TRUE;
};
IMPLEMENT_APP(MyApp);
And here is the screenshot:
- Have to declare an application class derived from wxApp
- Have to override virtual function OnInit of this class
- Have to declare a main window class derived from wxFrame (windows is called frame in wxWidgets)
- in OnInit of our application class, we should create (define) an instance of the main window class defined in step 3.
Set this frame (window) as the top window with method SetTopWindow
Don't forget to set its visibility to True with show method - To make the main() entry point, use macro: IMPLEMENT_APP( OurAppClass) which translated to complicated statement but then last with:
int main( int argc , char ** argv )
{
return ( wxEntry( argc , argv) )
};
- The method name should be OnInit() but I wrote onInit() and nothing comes up to the screen. It took 1 hour to figure out what's going wrong. At least I now know wxWidget naming convention is EveryFirstWordShouldBeCapitalized()
Compiling:
g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello
Source code: hello.cpp
#include <wx/wx.h>
#include <iostream>
using namespace std;
// Create our Application class derived from wxApp
class MyApp: public wxApp
{
public:
bool OnInit(); // have to override onInit
};
class MainWindow: public wxFrame
{
public:
MainWindow(const wxString& title , const wxPoint& pos , const wxSize& size );
};
MainWindow::MainWindow(const wxString& title , const wxPoint& pos , const wxSize& size )
: wxFrame( NULL, -1, title, pos, size)
{
this->Show( TRUE);
};
bool MyApp::OnInit()
{
cout << "start\n";
MainWindow *mainFrame = new MainWindow( _T("Hello empty world"),wxPoint(-1,-1),wxSize(-1,-1));
this->SetTopWindow( mainFrame);
//mainFrame->Show( TRUE);
return TRUE;
};
IMPLEMENT_APP(MyApp);
And here is the screenshot:
Comments
Post a Comment