It's very simple program, but very difficult for me at that time.
cause, I'm newbie.
i made this to use wxWidget sample project layout.
//============================================================================
// Name : prjEx02.cpp
// Author : stekilove@gmail.com
// Version :
// Copyright : Copy right stekilove@gmail.com.
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wx/statline.h"
class MainApp: public wxApp
{
public:
virtual bool OnInit();
};
class MainFrame: public wxFrame
{
public:
MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
wxButton *btnOk;
wxTextCtrl * wtcOutput;
wxTextCtrl * wtcAnswer;
void onQuit(wxCommandEvent &event);
void onButtonOk(wxCommandEvent &event);
void onTextAnswerEnter(wxCommandEvent &event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
ID_MAINWIN_QUIT = wxID_HIGHEST+1
, ID_BUTTON_OK
, ID_BUTTON_NEXT
, ID_TEXT_ANSWER_ENTER
};
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(ID_MAINWIN_QUIT, MainFrame::onQuit)
EVT_BUTTON(ID_BUTTON_OK, MainFrame::onButtonOk)
EVT_TEXT_ENTER(ID_TEXT_ANSWER_ENTER, MainFrame::onTextAnswerEnter)
END_EVENT_TABLE()
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit()
{
MainFrame *win = new MainFrame(_("Frame"), wxPoint (100, 100), wxSize(450, 340));
win->Show(TRUE);
SetTopWindow(win);
return TRUE;
}
MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame((wxFrame *) NULL, -1, title, pos, size)
{
wxMenu *FileMenu = new wxMenu;
wxMenuBar *MenuBar = new wxMenuBar;
FileMenu->Append(ID_MAINWIN_QUIT, _("&Quit 종료."));
MenuBar->Append(FileMenu, _("&File"));
SetMenuBar(MenuBar);
CreateStatusBar(2);
SetStatusText(_("Welcome my steki world!"));
//=====================================================
//TODO: steki's coding...
// make main panel..
wxPanel *p = new wxPanel(this,-1);
// make component..
wxStaticBox *sb = new wxStaticBox(p, wxID_ANY, _T("Image or picture"));
wxStaticText *st = new wxStaticText( p, wxID_ANY, _T("Steki and Tong loves each other!!"));
wtcOutput = new wxTextCtrl( p, wxID_ANY, _T("some output text.."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE );
wxStaticLine *sl = new wxStaticLine( p, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL);
wxStaticText *stAnswer = new wxStaticText(p, wxID_ANY, _T("Label"));
wtcAnswer = new wxTextCtrl(p, ID_TEXT_ANSWER_ENTER, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
wxButton *btnNext = new wxButton( p, ID_BUTTON_NEXT, _T("Next"));
btnOk = new wxButton( p, ID_BUTTON_OK, _T("Ok"));
// add component into layout..
wxBoxSizer *statsizer = new wxStaticBoxSizer( sb , wxVERTICAL );
statsizer->Add ( st , wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL, 30));
wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5);
gridsizer->Add( stAnswer , wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
gridsizer->Add( wtcAnswer , wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL );
button_box->Add( btnOk , wxSizerFlags().Border(wxALL, 7));
button_box->Add( btnNext , wxSizerFlags().Border(wxALL, 7));
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( statsizer , wxSizerFlags(1).Expand().Border(wxALL & ~wxBOTTOM, 10));
topsizer->Add( wtcOutput , wxSizerFlags(1).Expand().Border(wxALL, 5) );
topsizer->Add( sl ,wxSizerFlags().Expand());
topsizer->Add( gridsizer , wxSizerFlags().Expand().Expand().Border(wxALL, 1) );
topsizer->Add( button_box , wxSizerFlags().Center() );
p->SetSizer( topsizer );
topsizer->SetSizeHints( this );
}
void MainFrame::onQuit(wxCommandEvent & WXUNUSED(event))
{
int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO, this);
if (answer == wxYES)
Close(TRUE);
}
void MainFrame::onButtonOk(wxCommandEvent & WXUNUSED(event))
{
int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO | wxCANCEL, this);
if (answer == wxYES)
Close(TRUE);
}
void MainFrame::onTextAnswerEnter(wxCommandEvent & WXUNUSED(event))
{
wtcOutput->AppendText( wtcAnswer->GetValue().Append("\n") );
wtcAnswer->Clear();
}
cause, I'm newbie.
i made this to use wxWidget sample project layout.
//============================================================================
// Name : prjEx02.cpp
// Author : stekilove@gmail.com
// Version :
// Copyright : Copy right stekilove@gmail.com.
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wx/statline.h"
class MainApp: public wxApp
{
public:
virtual bool OnInit();
};
class MainFrame: public wxFrame
{
public:
MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
wxButton *btnOk;
wxTextCtrl * wtcOutput;
wxTextCtrl * wtcAnswer;
void onQuit(wxCommandEvent &event);
void onButtonOk(wxCommandEvent &event);
void onTextAnswerEnter(wxCommandEvent &event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
ID_MAINWIN_QUIT = wxID_HIGHEST+1
, ID_BUTTON_OK
, ID_BUTTON_NEXT
, ID_TEXT_ANSWER_ENTER
};
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(ID_MAINWIN_QUIT, MainFrame::onQuit)
EVT_BUTTON(ID_BUTTON_OK, MainFrame::onButtonOk)
EVT_TEXT_ENTER(ID_TEXT_ANSWER_ENTER, MainFrame::onTextAnswerEnter)
END_EVENT_TABLE()
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit()
{
MainFrame *win = new MainFrame(_("Frame"), wxPoint (100, 100), wxSize(450, 340));
win->Show(TRUE);
SetTopWindow(win);
return TRUE;
}
MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
: wxFrame((wxFrame *) NULL, -1, title, pos, size)
{
wxMenu *FileMenu = new wxMenu;
wxMenuBar *MenuBar = new wxMenuBar;
FileMenu->Append(ID_MAINWIN_QUIT, _("&Quit 종료."));
MenuBar->Append(FileMenu, _("&File"));
SetMenuBar(MenuBar);
CreateStatusBar(2);
SetStatusText(_("Welcome my steki world!"));
//=====================================================
//TODO: steki's coding...
// make main panel..
wxPanel *p = new wxPanel(this,-1);
// make component..
wxStaticBox *sb = new wxStaticBox(p, wxID_ANY, _T("Image or picture"));
wxStaticText *st = new wxStaticText( p, wxID_ANY, _T("Steki and Tong loves each other!!"));
wtcOutput = new wxTextCtrl( p, wxID_ANY, _T("some output text.."), wxDefaultPosition, wxSize(100,60), wxTE_MULTILINE );
wxStaticLine *sl = new wxStaticLine( p, wxID_ANY, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL);
wxStaticText *stAnswer = new wxStaticText(p, wxID_ANY, _T("Label"));
wtcAnswer = new wxTextCtrl(p, ID_TEXT_ANSWER_ENTER, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
wxButton *btnNext = new wxButton( p, ID_BUTTON_NEXT, _T("Next"));
btnOk = new wxButton( p, ID_BUTTON_OK, _T("Ok"));
// add component into layout..
wxBoxSizer *statsizer = new wxStaticBoxSizer( sb , wxVERTICAL );
statsizer->Add ( st , wxSizerFlags().Align(wxALIGN_LEFT).Border(wxALL, 30));
wxGridSizer *gridsizer = new wxGridSizer(2, 5, 5);
gridsizer->Add( stAnswer , wxSizerFlags().Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL));
gridsizer->Add( wtcAnswer , wxSizerFlags(1).Align(wxGROW | wxALIGN_CENTER_VERTICAL));
wxBoxSizer *button_box = new wxBoxSizer( wxHORIZONTAL );
button_box->Add( btnOk , wxSizerFlags().Border(wxALL, 7));
button_box->Add( btnNext , wxSizerFlags().Border(wxALL, 7));
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( statsizer , wxSizerFlags(1).Expand().Border(wxALL & ~wxBOTTOM, 10));
topsizer->Add( wtcOutput , wxSizerFlags(1).Expand().Border(wxALL, 5) );
topsizer->Add( sl ,wxSizerFlags().Expand());
topsizer->Add( gridsizer , wxSizerFlags().Expand().Expand().Border(wxALL, 1) );
topsizer->Add( button_box , wxSizerFlags().Center() );
p->SetSizer( topsizer );
topsizer->SetSizeHints( this );
}
void MainFrame::onQuit(wxCommandEvent & WXUNUSED(event))
{
int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO, this);
if (answer == wxYES)
Close(TRUE);
}
void MainFrame::onButtonOk(wxCommandEvent & WXUNUSED(event))
{
int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO | wxCANCEL, this);
if (answer == wxYES)
Close(TRUE);
}
void MainFrame::onTextAnswerEnter(wxCommandEvent & WXUNUSED(event))
{
wtcOutput->AppendText( wtcAnswer->GetValue().Append("\n") );
wtcAnswer->Clear();
}