



class MyMessage:public wxFrame
{
public:
MyMessage(const wxString& title);
protected:
void ShowInfo(wxCommandEvent& event);
void ShowError(wxCommandEvent& event);
void ShowQuestion(wxCommandEvent& event);
void ShowAlert(wxCommandEvent& event);
};
MyMessage::MyMessage(const wxString& title)
:wxFrame(NULL,-1,title)
{
wxPanel* panel = new wxPanel(this,-1);
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
wxGridSizer* gs = new wxGridSizer(2,2,2,2);
wxButton* btnInfo = new wxButton(panel,-1,"Info");
wxButton* btnError = new wxButton(panel,-1,"Error");
wxButton* btnQuestion = new wxButton(panel,-1,"Question");
wxButton* btnAlert = new wxButton(panel,-1,"Exclamation");
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyMessage::ShowInfo,this,btnInfo->GetId());
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyMessage::ShowError,this,btnError->GetId());
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyMessage::ShowQuestion,this,btnQuestion->GetId());
Bind(wxEVT_COMMAND_BUTTON_CLICKED,MyMessage::ShowAlert,this,btnAlert->GetId());
gs->Add(btnInfo,1,wxEXPAND);
gs->Add(btnError,1);
gs->Add(btnQuestion,1);
gs->Add(btnAlert,1);
hbox->Add(gs,0,wxALL,15);
panel->SetSizer(hbox);
Center();
}
void MyMessage::ShowInfo(wxCommandEvent& event)
{
wxMessageDialog* dial = new wxMessageDialog(NULL,"DownLoad completed","Info",wxOK);
dial->ShowModal();
}
void MyMessage::ShowError(wxCommandEvent& event)
{
wxMessageDialog* dial = new wxMessageDialog(NULL,"Error","error",wxOK|wxICON_ERROR);
dial->ShowModal();
}
void MyMessage::ShowQuestion(wxCommandEvent& event)
{
wxMessageDialog* dial = new wxMessageDialog(NULL,"Are you sure?","Quesstion",
wxYES_NO|wxNO_DEFAULT|wxICON_QUESTION);
dial->ShowModal();
}
void MyMessage::ShowAlert(wxCommandEvent& event)
{
wxMessageDialog* dial = new wxMessageDialog(NULL,wxT("警告"),"Exclamation",
wxOK|wxICON_EXCLAMATION);
dial->ShowModal();
}
这段代码展示了如何在wxWidgets框架下创建一个包含不同消息类型的对话框应用。`MyMessage`类继承自`wxFrame`,并实现了展示信息、错误、问题和警告消息的方法。每个方法都会显示一个预定义消息的`wxMessageDialog`,并设置相应的按钮和图标。

701

被折叠的 条评论
为什么被折叠?



