#include <wx/richtext/richtextctrl.h>
// text.h class myRichTextCtrl : public wxRichTextCtrl { public: myRichTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, long style ); ~myRichTextCtrl(); void OnContextMenu(wxContextMenuEvent& event); // 重载函数 OnContextMenu DECLARE_EVENT_TABLE() };
// text.cpp BEGIN_EVENT_TABLE(myRichTextCtrl, wxRichTextCtrl) EVT_CONTEXT_MENU(myRichTextCtrl::OnContextMenu) END_EVENT_TABLE()
myRichTextCtrl::myRichTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, long style ) :wxRichTextCtrl(parent,id, value)
{
}
myRichTextCtrl::~myRichTextCtrl() {
}
void myRichTextCtrl::OnContextMenu(wxContextMenuEvent& event) { if (event.GetEventObject() != this) // 这句很关键,只有当鼠标wxRichTextCtrl在内才能弹出右菜单 { event.Skip(); return; }
wxPoint point = event.GetPosition(); point = ScreenToClient(point); wxMenu menu; menu.Append(idMenuCopy,_T("Copy")); menu.Append(idMenuCut,_T("Cut")); menu.Append(idMenuPaste,_T("Paste")); menu.Append(idMenuDel,_T("Delete")); menu.AppendSeparator(); menu.Append(idMenuQuit,_T("E&xit"));
PopupMenu(&menu, point.x, point.y); }
|