Hi, thanks for the input. I don't think that is the problem though as I've tried numerous different IDs and setups. Here is the working code for one button. I think my sizers are wrong as well. I'd like the second button directly below or next to the first.
PersonDialog.h
Code:
#ifndef PERSONDIALOG_H
#define PERSONDIALOG_H
class PersonDialog : public wxDialog
{
public:
//---Constructor. Creates a new dialog
PersonDialog(wxWindow* parent, const wxString& title);
//---Destructor
~PersonDialog();
//---Processes Click Button
void OnButtonClick(wxCommandEvent &event);
protected:
DECLARE_EVENT_TABLE()
private:
wxTextCtrl *name;
wxTextCtrl *social;
wxTextCtrl *hours;
wxTextCtrl *wage;
enum
{
ID_BUTTON_CLICK = 1000
};
};
PersonDialog.cpp
Code:
#include <wx/wx.h>
#include <string>
#include "PersonDialog.h"
using namespace std;
PersonDialog::PersonDialog(wxWindow* parent, const wxString& title)
: wxDialog(parent, -1, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
//Constructing a vertical sizer
wxBoxSizer *dialogSizer = new wxBoxSizer(wxVERTICAL);
name = new wxTextCtrl(this, -1);
social = new wxTextCtrl(this, -1);
hours = new wxTextCtrl(this, -1);
wage = new wxTextCtrl(this, -1);
//Constructing a grid sizer with 5 rows and 2 columns (use 10 pixels
wxFlexGridSizer *textSizer = new wxFlexGridSizer(5, 2, 10, 10);
//Adding static text control
textSizer->Add(new wxStaticText(this, -1, "Name: "),
1, //make vertically stretchable
wxEXPAND); //make horizontally stretchable
textSizer->Add(name, 1, wxEXPAND);
textSizer->Add(new wxStaticText(this, -1, "Social no: "), 1, wxEXPAND);
textSizer->Add(social, 1, wxEXPAND);
textSizer->Add(new wxStaticText(this, -1, "Hours worked: "), 1, wxEXPAND);
textSizer->Add(hours, 1, wxEXPAND);
textSizer->Add(new wxStaticText(this, -1, "Hourly wage: "), 1, wxEXPAND);
textSizer->Add(wage, 1, wxEXPAND);
//Adding button control
wxButton *button = new wxButton(this, ID_BUTTON_CLICK, "Display");
dialogSizer->Add(textSizer, 0, wxALIGN_CENTER);
dialogSizer->Add(button,
0, //make vertically unstretchable
wxALIGN_CENTER | wxALL, 10); //center horizontally and set border width to 10
SetSizer(dialogSizer); //use dialog sizer for layout
dialogSizer->Fit(this); //fit dialog to components
}
PersonDialog::~PersonDialog()
{
}
BEGIN_EVENT_TABLE(PersonDialog, wxDialog)
EVT_BUTTON(ID_BUTTON_CLICK, PersonDialog::OnButtonClick)
END_EVENT_TABLE()
void PersonDialog::OnButtonClick(wxCommandEvent &event)
{
string n = name->GetValue().c_str();
string s = social->GetValue().c_str();
string h = hours->GetValue().c_str();
string w = wage->GetValue().c_str();
string text = "Hello " + n + " (" + s + "). Your earnings for this week are " + h + "*" + w + ".";
wxMessageDialog *dlg = new wxMessageDialog(this, text.c_str(),
"Message Dialog", wxOK | wxCENTER | wxICON_INFORMATION, wxDefaultPosition);
dlg->ShowModal();
dlg->Destroy();
}
Here are the other two files needed to run the program:
PersonDlgApp.h
Code:
#ifndef PERSONDLGAPP_H
#define PERSONDLGAPP_H
class PersonDialogApp : public wxApp
{
public:
//initialise the application
virtual bool OnInit();
};
DECLARE_APP(PersonDialogApp)
#endif //TEXTEDITORAPP_H
PersonDlgApp.cpp
Code:
#include <wx/wx.h>
#include "PersonDlgApp.h"
#include "PersonDialog.h"
IMPLEMENT_APP(PersonDialogApp)
bool PersonDialogApp::OnInit()
{
PersonDialog *dlg = new PersonDialog(NULL,"Worker details");
dlg->ShowModal();
dlg->Destroy();
return true;
}
The output is just a test at the moment. I'll do the converting strings to integers stuff later.
Any help greatly appreciated
thanks,
sam