Jeg arbejder videre med Dev-C++, og er nu kommet til:
http://www.bzzt.net/~wxwidgets/icpp_wx4.htmlI mit projekt har jeg to filer basic.h og main.cpp.
basic.h:
#ifndef BASIC_H
#define BASIC_H
#include <wx/wx.h>
static const
wxChar
*FILETYPES = _T( "Text files|*.txt|"
"C/C++ source files|*.cpp;*.cc;*.c|"
"C/C++ header files|*.hpp;*.h|"
"Make files|Mak*;mak*|"
"Java files|*java|"
"Hypertext markup files|*html;*htm;*HTML;*HTM|"
"All files|*.*"
);
static const wxChar
*TITLE =
_T("Basic - Step 3: Responding to events");
class BasicApplication : public wxApp
{
public:
virtual bool OnInit();
};
class BasicFrame : public wxFrame
{
public:
BasicFrame( const wxChar *title,
int xpos, int ypos,
int width, int height);
~BasicFrame();
wxTextCtrl *theText;
wxMenuBar *menuBar;
wxMenu *fileMenu;
void OnOpenFile (wxCommandEvent & event);
void OnAbout (wxCommandEvent & event);
void OnExit (wxCommandEvent & event);
DECLARE_EVENT_TABLE()
};
enum
{ BASIC_EXIT = 1,
BASIC_OPEN = 100,
BASIC_ABOUT = 200
};
#endif
main.cpp:
#include <wx/wx.h>
#include "basic.h"
IMPLEMENT_APP(BasicApplication)
bool BasicApplication::OnInit()
{
BasicFrame *frame
= new BasicFrame
("wxWindows Basic Steps - Step 1:"
" A simple application",
50, 50, 200, 200);
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
BasicFrame::BasicFrame
(const wxChar *title,
int xpos, int ypos,
int width, int height)
: wxFrame( (wxFrame *) NULL, -1, title,
wxPoint(xpos, ypos),
wxSize(width, height))
{
theText = (wxTextCtrl *) NULL;
menuBar = (wxMenuBar *) NULL;
fileMenu = (wxMenu *) NULL;
theText
= new wxTextCtrl
( this,
-1,
wxString("This is a text control\n\n"
"The text control supports"
" basic text editing operations\n"
"along with copy, cut, paste, "
"delete, select all and undo.\n\n"
"Right click on the control"
" to see the pop-up menu.\n"
),
wxDefaultPosition,
wxDefaultSize,
wxTE_MULTILINE
);
fileMenu = new wxMenu;
fileMenu->Append(BASIC_OPEN, "&Open file");
fileMenu->Append(BASIC_ABOUT, "&About");
fileMenu->AppendSeparator();
fileMenu->Append(BASIC_EXIT, "E&xit");
menuBar = new wxMenuBar;
menuBar->Append(fileMenu, "&File");
SetMenuBar(menuBar);
SetMenuBar(menuBar);
CreateStatusBar(3);
}
BasicFrame::~BasicFrame()
{
}
BEGIN_EVENT_TABLE (BasicFrame, wxFrame)
EVT_MENU ( BASIC_EXIT, BasicFrame::OnExit)
EVT_MENU ( BASIC_ABOUT, BasicFrame::OnAbout)
EVT_MENU ( BASIC_OPEN, BasicFrame::OnOpenFile)
END_EVENT_TABLE()
void BasicFrame::OnOpenFile (wxCommandEvent & event)
{ wxFileDialog
* openFileDialog =
new wxFileDialog ( this,
"Open file",
"",
"",
FILETYPES,
wxOPEN,
wxDefaultPosition);
if (openFileDialog->ShowModal() == wxID_OK)
{ SetCurrentFilename(openFileDialog->GetFilename());
theText->LoadFile(openFileDialog->GetFilename());
SetStatusText(GetCurrentFilename(), 0);
SetStatusText(openFileDialog->GetDirectory(),1);
}
}
void BasicFrame::OnAbout (wxCommandEvent & event)
{ wxString t = TITLE;
t.append( _T("\nDB 2001"));
wxMessageDialog
aboutDialog
( this, t, "About Basic", wxOK | wxCANCEL);
aboutDialog.ShowModal();
}
void BasicFrame::OnExit (wxCommandEvent & event)
{
Close(TRUE);
}
Koden er tage fra de eksempler som artiklen kommer med. Men når jeg kører dette igennem min compiler, får jeg en fejl i linien:
{ SetCurrentFilename(openFileDialog->GetFilename());
i main.cpp. Den siger at funktionen er "undeclared". Mangler jeg at inkludere nogle filer, eller hvad er der galt?