tags:

views:

52

answers:

2

Hello. I make a simle window with wxwidgets. How can i change the border? Also how can i call the destroy fuction(OnClose) with the right arrow button press?

#include <wx/wx.h>

class _Frame: public wxFrame
{
    public:
        _Frame(wxFrame *frame, const wxString& title);
    private:
    void OnClose(wxCloseEvent& event);
        DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(_Frame, wxFrame)
END_EVENT_TABLE()

_Frame::_Frame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{}

void _Frame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

class _App : public wxApp
{
    public:
        virtual bool OnInit();
};

IMPLEMENT_APP(_App);

bool _App::OnInit()
{
    _Frame* frame = new _Frame(0L, _("wxWidgets Application Template"));
    frame->Show();

    return true;
}
+1  A: 

To close the window on right-arrow you need to trap EVT_CHAR or EVT_KEY_DOWN like so:

header file:

void OnChar(wxKeyEvent& event);

source file:

void _Frame::OnChar(wxKeyEvent& event) 
{
  if (event.GetKeyCode() == WXK_RIGHT)
  {
    wxCommandEvent close(wxEVT_CLOSE_WINDOW);
    AddPendingEvent(close);
  }
  event.Skip();
}

BEGIN_EVENT_TABLE(_Frame, wxFrame)
   EVT_CHAR(_Frame::OnChar)
END_EVENT_TABLE()
RickNotFred
+1  A: 

Changing the border (by setting a different wxBORDER_XXX style) doesn't work for all windows/under all platforms after the initial window creation so you'd better recreate the window if you really, really need to do this.

VZ