Meta da semana

Tá, eu venho empurrando isso com a barriga há muito tempo! Mas essa semana eu decidi que vou aprender a programar usando o wxWidgets de uma vez por todas! :-D

E prometo não fazer mais gambiarras usando sempre a mesma interface fornecida pelo prof. Creto lá na cadeira de CG1! (será?! hehehehe)

Para começar, nada melhor que um “hello world’ ;-)

/*
* hworld.cpp
* Hello world sample by Robert Roebling
*/

#include “wx/wx.h”

class MyApp: public wxApp
{
virtual bool OnInit();
};

class MyFrame: public wxFrame
{
public:

MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);

DECLARE_EVENT_TABLE()
};

enum
{
ID_Quit = 1,
ID_About,
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( _T(“Hello World”), wxPoint(50,50), wxSize(450,340) );
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;

menuFile->Append( ID_About, _T(“&About…”) );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, _T(“E&xit”) );

wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, _T(“&File”) );

SetMenuBar( menuBar );

CreateStatusBar();
SetStatusText( _T(“Welcome to wxWindows!”) );
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_T(“This is a wxWindows Hello world sample”),
_T(“About Hello World”), wxOK | wxICON_INFORMATION, this);
}

pra compilar:

g++ hworld.cpp `wx-config –libs` `wx-config –cxxflags` -o hworld

E se você também quer aprender a programar em wx, visite a página de documentação do site. Lá tem vários tutorias bacanas, em todos os níveis.

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Sair / Alterar )

Imagem do Twitter

You are commenting using your Twitter account. Sair / Alterar )

Foto do Facebook

You are commenting using your Facebook account. Sair / Alterar )

Connecting to %s

Seguir

Obtenha todo post novo entregue na sua caixa de entrada.

Join 87 other followers