class MyCustomDialog:public wxDialog
{
public:
MyCustomDialog(const wxString& title);
protected:
void OnClose(wxCommandEvent& event);
void OnCloseWindow(wxCloseEvent& event);
};
MyCustomDialog::MyCustomDialog(const wxString& title)
:wxDialog(NULL,-1,title,wxDefaultPosition,wxDefaultSize)
{
//为较低分辨率的屏幕调整对话框.自动滚屏
wxDialog::EnableLayoutAdaptation(true);
wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer(wxVERTICAL,this,"Colors");
wxRadioButton* rb256 = new wxRadioButton(this,-1,"256 Colors");
wxRadioButton* rbCus = new wxRadioButton(this,-1,"custom");
sbSizer->Add(rb256,1,wxEXPAND|wxALL,5);
sbSizer->Add(rbCus,1,wxEXPAND|wxALL,5);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
wxButton* btnOK = new wxButton(this,-1,"OK");
wxButton* btnClose = new wxButton(this,-1,"Close");
hbox->Add(btnOK,1,wxALL,5);
hbox->Add(btnClose,1,wxALL,5);
wxBoxSizer *szMain = new wxBoxSizer(wxVERTICAL);
szMain->Add(sbSizer,1,wxEXPAND|wxALL,10);
szMain->Add(hbox,1,wxALIGN_RIGHT,10);
SetSizer(szMain);
Bind(wxEVT_CLOSE_WINDOW,MyCustomDialog::OnCloseWindow,this);
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyCustomDialog::OnClose,this,btnClose->GetId());
Centre();
ShowModal();
Destroy();
}
void MyCustomDialog::OnClose(wxCommandEvent& event)
{
//生成一个wxCloseEvent
Close(false);
// PostMessage((HWND__ *)this->GetHandle(),WM_CLOSE,0,0);
}
void MyCustomDialog::OnCloseWindow(wxCloseEvent& event)
{
if(event.CanVeto())
{
if ( wxMessageBox(wxT("确定要退出吗"), wxT("请确认"),
wxICON_QUESTION | wxYES_NO) == wxYES )
{
event.Skip();
}
else
{
event.Veto();
}
}
}