且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按下wxYES_NO中的按钮时,如何执行功能?

更新时间:2023-12-03 20:31:23

我建议使用wxEvtHandler::Bind<>()函数,如

I would suggest using the wxEvtHandler::Bind<>() function as detailed in the wxWidgets documentaton at https://docs.wxwidgets.org/3.0/overview_events.html. The Bind() function allows dynamic binding of events and the syntax is one line of code as compared to setting up tables to link events to objects.

另外请参阅此wxWidgets用户论坛线程,其中包含有关调用成员和非成员方法的详细说明 https://forums.wxwidgets.org/viewtopic.php?t=39817

Additionally see this wxWidgets user forum thread which has detailed explanation for calling member and nonmember methods https://forums.wxwidgets.org/viewtopic.php?t=39817

wxYES_NO是一个样式标志,它告诉wxWidgets框架您希望对话框中的是和否按钮.检查ShowModal()的返回值是否等于定义为wxYESwxNO的内置宏之一.

wxYES_NO is a style flag that tells wxWidgets framework that you want both yes and no buttons in your dialog. Check if the return value of ShowModal() is equal to one of the builtin macros defined as wxYES and wxNO.

有关宏的定义,请参见此处 https://docs.wxwidgets.org/trunk/defs_8h .html

See here for the macro definitions https://docs.wxwidgets.org/trunk/defs_8h.html

您应该阅读wxDiaglog.从此处开始 https://docs.wxwidgets.org/trunk/classwx_dialog.html

And you should read up on wxDiaglog. Start here https://docs.wxwidgets.org/trunk/classwx_dialog.html

是否要将值返回给Quit::Quit()的调用者?构造函数不返回值,您可以将成员变量设置为该值,但是请记住,如果对象被破坏,那么您的成员变量也将消失.您没有提供足够的信息来知道Quit()时需要执行的清理工作,因此,我将为您提供检查返回值的代码,只需在案例正文中填写所需的内容即可.

Do you want to return the value to the caller of Quit::Quit()? Constructors do not return values, you can set a member variable to the value but remember that if the object is destroyed then your member variable is gone too. You have not provided enough information to know what needs to be done for cleanup when you Quit() so I will provide you with the code to check the return value, just fill in what you need in the case body.

以下是检查返回值的方法:

Here is how you would check the return value:

class Quit : public wxFrame
{
public:
    Quit(const wxString& tekst);
};
Quit::Quit(const wxString& tekst)
{
    int dialog_return_value = wxNO; // initialize to a sane default value
    wxMessageDialog* dial = new wxMessageDialog(NULL, _("Do you really want to quit?"), _("Quit"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
    dialog_return_value = dial->ShowModal();
    // You do not have cancel button so only check wxYES and wxNO
    switch( dialog_return_value) // Use switch, scales to more buttons later
    {
        case wxYES :
        /* do something */
        break;
        case wxNO :
        /* do something */
        break;
        default : /* ignore or handle error */ ;
    };
}

您正在执行一项技术任务,因此可以合理预期将学习技术"字词.

You are doing a technical task, it is reasonable to expect that learning "technical" words will be involved.