How can I change the border?
I make a simple window with wxwidgets. How can I change the border? Also how can I call the destroy function(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& e开发者_运维百科vent);
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;
}
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()
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.
精彩评论