I am trying to understand how to add custom buttons to my very basic app,
i have managed to add the custom button tutorial to the app in vs2013, all appears good,
untill i try to debug at which point it throws the errors in the post title the more detailed
description is as follows.
i am certain i either have something in the wrong place, or have missed something like a decalaration outmain.h(10): error C2143: syntax error : missing ';' before '*'
main.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
but dont know what, hopefully one of you can spot it as i have searched but cant find a solution due my inexperience.
custombutton.h
Code: Select all
#include <wx\wx.h>
class wxCustomButton : public wxWindow
{
bool pressedDown;
wxString text;
static const int buttonWidth = 200;
static const int buttonHeight = 50;
public:
wxCustomButton(wxFrame* parent, wxString text);
void paintEvent(wxPaintEvent & evt);
void paintNow();
void render(wxDC& dc);
DECLARE_EVENT_TABLE()
// some useful events
void mouseMoved(wxMouseEvent& event);
void mouseDown(wxMouseEvent& event);
void mouseWheelMoved(wxMouseEvent& event);
void mouseReleased(wxMouseEvent& event);
void rightClick(wxMouseEvent& event);
void mouseLeftWindow(wxMouseEvent& event);
void keyPressed(wxKeyEvent& event);
void keyReleased(wxKeyEvent& event);
};
BEGIN_EVENT_TABLE(wxCustomButton, wxPanel)
EVT_MOTION(wxCustomButton::mouseMoved)
EVT_LEFT_DOWN(wxCustomButton::mouseDown)
EVT_LEFT_UP(wxCustomButton::mouseReleased)
EVT_RIGHT_DOWN(wxCustomButton::rightClick)
EVT_LEAVE_WINDOW(wxCustomButton::mouseLeftWindow)
EVT_KEY_DOWN(wxCustomButton::keyPressed)
EVT_KEY_UP(wxCustomButton::keyReleased)
EVT_MOUSEWHEEL(wxCustomButton::mouseWheelMoved)
// catch paint events
EVT_PAINT(wxCustomButton::paintEvent)
END_EVENT_TABLE()
Code: Select all
#include "CustomButton.h"
wxCustomButton::wxCustomButton(wxFrame* parent, wxString text) :
wxWindow(parent, wxID_ANY)
{
SetMinSize(wxSize(buttonWidth, buttonHeight));
this->text = text;
pressedDown = false;
};
void wxCustomButton::paintEvent(wxPaintEvent & evt)
{
wxPaintDC dc(this);
render(dc);
};
void wxCustomButton::paintNow()
{
wxClientDC dc(this);
render(dc);
};
void wxCustomButton::render(wxDC& dc)
{
if (pressedDown)
dc.SetBrush(*wxRED_BRUSH);
else
dc.SetBrush(*wxGREY_BRUSH);
dc.DrawRectangle(0, 0, buttonWidth, buttonHeight);
dc.DrawText(text, 20, 15);
};
void wxCustomButton::mouseDown(wxMouseEvent& event)
{
pressedDown = true;
paintNow();
};
void wxCustomButton::mouseReleased(wxMouseEvent& event)
{
pressedDown = false;
paintNow();
wxMessageBox(wxString("You pressed a custom button"));
};
void wxCustomButton::mouseLeftWindow(wxMouseEvent& event)
{
if (pressedDown)
{
pressedDown = false;
paintNow();
}
};
// currently unused events
void wxCustomButton::mouseMoved(wxMouseEvent& event) {}
void wxCustomButton::mouseWheelMoved(wxMouseEvent& event) {}
void wxCustomButton::rightClick(wxMouseEvent& event) {}
void wxCustomButton::keyPressed(wxKeyEvent& event) {}
void wxCustomButton::keyReleased(wxKeyEvent& event) {}
Code: Select all
#include <wx\wx.h>
class Main : public wxApp
{
public:
virtual bool OnInit();
wxFrame *frame;
wxCustomButton *btnexit;
};
DECLARE_APP(Main)
Code: Select all
#include "Main.h"
#include "CustomButton.h"
IMPLEMENT_APP(Main)
bool Main::OnInit()
{
wxInitAllImageHandlers();
frame = new wxFrame(NULL, wxID_ANY, wxString("Title"), wxPoint(wxDefaultPosition), wxSize(0, 0));
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
wxCustomButton *btnexit = new wxCustomButton(frame, "my button");
sizer->Add(btnexit);
frame->SetSizerAndFit(sizer);
frame->Center();
frame->Show();
return true;
};
thanks