Io non ho fatto molti programmi in wxWindows, ho solo seguito alcuni tutorial linkati dal sito; per fare una prova da MinGWDS cre un nuovo progetto wxWindows; quindi agiungi al progetto i seguenti 3 file:
1 - un file wxProva.cpp (tra i source files)
2 - un file wxProva.h (tra gli include files)
3 - un file wxProva.rc (tra i Resource file)
qui ti riporto il codice per tutti e tre i file:
codice:
/* wxProva.h */
#include <wx/wx.h>
#include <wx/mdi.h>
#include <vector>
using namespace std;
enum
{
ID_Quit = 1,
ID_About,
ID_New
};
class ProvaText: public wxTextCtrl
{
public:
ProvaText();
};
class ProvaChild: public wxMDIChildFrame
{
ProvaText *txt;
public:
ProvaChild();
bool Create(wxMDIParentFrame *parent, wxWindowID id, const wxString& title,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE, const wxString& name = "frame");
};
class ProvaClient: public wxMDIClientWindow
{
public:
ProvaClient();
};
class ProvaFrame: public wxMDIParentFrame
{
vector<ProvaChild *> child_list;
ProvaClient *client;
public:
ProvaFrame(const char* title, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE |
wxVSCROLL | wxHSCROLL, const wxString& name = "frame");
virtual wxMDIClientWindow* OnCreateClient();
virtual void OnNew(wxCommandEvent& event);
virtual void OnQuit(wxCommandEvent& event);
virtual void OnAbout(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
class ProvaApp: public wxApp
{
virtual bool OnInit();
ProvaFrame *frame;
};
codice:
/* wxProva.cpp */
#include "wxProva.h"
BEGIN_EVENT_TABLE(ProvaFrame, wxMDIParentFrame)
EVT_MENU(ID_New, ProvaFrame::OnNew)
EVT_MENU(ID_Quit, ProvaFrame::OnQuit)
EVT_MENU(ID_About, ProvaFrame::OnAbout)
END_EVENT_TABLE()
IMPLEMENT_APP(ProvaApp)
bool ProvaApp::OnInit()
{
frame = new ProvaFrame("Hello World", wxPoint(50,50), wxSize(450,340));
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
ProvaFrame::ProvaFrame(const char* title, const wxPoint& pos,
const wxSize& size, long style, const wxString& name)
: wxMDIParentFrame((wxWindow *)NULL, -1, wxString(title),
pos, size, style, name)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_New, "&New..." );
menuFile->AppendSeparator();
menuFile->Append( ID_About, "&About..." );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, "E&xit" );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, "&File" );
SetMenuBar( menuBar );
CreateStatusBar();
SetStatusText( "Welcome to wxWindows!" );
}
void ProvaFrame::OnQuit(wxCommandEvent& event)
{
Close(TRUE);
}
void ProvaFrame::OnNew(wxCommandEvent& event)
{
ProvaChild *child = new ProvaChild();
child->Create(this, -1, wxT("Child"));
child_list.push_back(child);
}
void ProvaFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWindows Hello world sample",
"About Hello World", wxOK | wxICON_INFORMATION, this);
}
wxMDIClientWindow *ProvaFrame::OnCreateClient()
{
client = new ProvaClient();
client->Create(this, -1);
return client;
}
ProvaClient::ProvaClient()
{
}
ProvaChild::ProvaChild()
{
}
bool ProvaChild::Create(wxMDIParentFrame *parent,
wxWindowID id, const wxString& title,
const wxPoint& pos /* = wxDefaultPosition */,
const wxSize& size /* = wxDefaultSize */,
long style /* = wxDEFAULT_FRAME_STYLE */,
const wxString& name /* = "frame" */)
{
if(!wxMDIChildFrame::Create(parent, id, title, pos, size, style, name))
{
wxMessageBox("Errore nella creazione della finestra",
"Errore", wxOK | wxICON_INFORMATION, this);
return false;
}
txt = new ProvaText();
txt->Create(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH /*| wxTE_PROCESS_ENTER */|
wxTE_PROCESS_TAB | wxTE_NOHIDESEL);
return true;
}
ProvaText::ProvaText()
{
}
codice:
/* wxProva.rc */
#include "wx/msw/wx.rc"
quindi prova ad eseguire...se tutto va bene ti appare un rudimentale editor di testo a più finestre