First wxWidget Program

Home / First wxWidget Program

First wxWidget Program

December 9, 2015 | Article | No Comments

After learning some wxWidgets basic, lets open new article for discussing a simple application.

In this article we will cover a basic in creating a wxWidget frame and show how to display an icon. Next we will create a simple example demonstrating usage of an event. Finally, we will see, how widgets communicate in wxWidgets applications.

A simple application

First we create the very basic wxWidgets program.

/** filename: simple.h **/
#include <wx/wx.h>

class Simple : public wxFrame
{
public:
    Simple(const wxString& title);
};

That’s for class declaration, this one for the implementation.

/** filename: simple.cpp **/
#include "simple.h"

Simple::Simple(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
  Centre();
}

And then the main. First the declaration and then the implementation

/** filename: main.h **/
#include <wx/wx.h>

class MyApp : public wxApp
{
  public:
    virtual bool OnInit();
};
/** filename: main.cpp **/
#include "main.h"
#include "simple.h"

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    Simple *simple = new Simple(wxT("Simple"));
    simple->Show(true);
    SetTopWindow(simple);

    return true;
}

Compile the above code as discussed before.

 

,

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial