#include <wx/wx.h>
#include <wx/popupwin.h>
class Simple:public wxFrame
{
public:
Simple(const wxString& title);
private:
void OnRightDown(wxMouseEvent& event);
wxPopupTransientWindow* mMyPopup;
};
Simple::Simple(const wxString& title)
:wxFrame(NULL,wxID_ANY,title,wxPoint(-1,-1),wxSize(640,480))
{
mMyPopup = new wxPopupTransientWindow(this,wxBORDER_SIMPLE|wxPU_CONTAINS_CONTROLS|wxBG_STYLE_TRANSPARENT);
mMyPopup->SetBackgroundColour(this->GetBackgroundColour());
auto sizer = new wxBoxSizer(wxVERTICAL);
{
wxArrayString choices;
choices.Add("Fob");
choices.Add("Bar");
auto myComboBox = new wxComboBox(mMyPopup,-1,wxEmptyString,wxPoint(-1,-1),wxSize(-1,-1)
,choices,wxCB_READONLY);
auto myLabel = new wxStaticText(mMyPopup,-1,wxT("请选择"),wxPoint(-1,-1),wxSize(-1,-1));
myLabel->SetBackgroundColour(this->GetBackgroundColour());
sizer->Add(myLabel);
sizer->Add(myComboBox,1,wxALL|wxEXPAND,0);
}
mMyPopup->SetSizerAndFit(sizer);
Bind(wxEVT_RIGHT_DOWN,Simple::OnRightDown,this);
// SetCursor(wxCursor(wxCURSOR_CROSS));
Centre();
}
void Simple::OnRightDown(wxMouseEvent& event)
{
// wxWindow * window = dynamic_cast<wxWindow *>(event.GetEventObject());
// if (nullptr == window)
// return;
// mMyPopup->SetPosition(window->ClientToScreen(event.GetPosition()));
mMyPopup->SetPosition(wxWindow::ClientToScreen(event.GetPosition()));
mMyPopup->Popup();
}