一、通用視窗關閉事件處理
//窗體構造事件中增加此句
Bind(wxEVT_CLOSE_WINDOW,wxCloseEventHandler(MyFrame::OnClose),this);
//事件代碼 如下
void MyFrame::OnClose(wxCloseEvent& event)
{
wxMessageDialog* dial = new wxMessageDialog(NULL
,"Are you sure to quit?"
,"Question"
,wxYES_NO|wxNO_DEFAULT|wxICON_QUESTION
);
int ret = dial->ShowModal();
dial->Destroy();
if(ret == wxID_YES)
{
Destroy();
}else{
event.Veto();
}
}
二、Dialog關閉處理
主窗體增加的語句
Bind(wxEVT_CLOSE_WINDOW,MyCustomDialog::OnCloseWindow,this);
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyCustomDialog::OnClose,this,btnClose-
事件處理程式
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();
}
}
}