天天看点

wxWidgets窗口关闭事件处理一、通用窗口关闭事件处理二、Dialog关闭处理

一、通用窗口关闭事件处理

//窗体构造事件中增加此句

    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();

        }

    }

}