Nana C++ Library  

An open-source C++ framework project
The Programmer's Guide 
nana::gui::msgbox

Description

The class msgbox is used for displaying a modal dialog box to prompt a brief message that inform and instruct the user.

Model of

None

Public base classes

None

Typedefs

enum icon_t{ icon_none, icon_information, icon_warning, icon_error, icon_question}; The identifier of icons, default is icon_none.
enum button_t{ok, yes_no, yes_no_cancel}; The identifier of buttons, default is ok.
enum pick_t{pick_ok, pick_yes, pick_no, pick_cancel}; The identifier of buttons that user clicked.

Members

msgbox(); The construction.
msgbox(const nana::string& title); The construction.
msgbox(window owner, const nana::string& title); The construction.
msgbox(window owner, const nana::string& title, button_t buttons); The construction.
void clear(); Clears the message.
void icon(icon_t ico); Sets the icon for displaying.
pick_t show() const; Displays the message that buffered in the stream.
msgbox& operator<<(const nana::string&); Writes a string to the stream.
msgbox& operator<<(const nana::char_t*); Writes a string to the stream.
msgbox& operator<<(std::ostream& (*)(std::ostream&)); Calls a manipulator to the stream.
template<typename T>
msgbox& operator<<(const T&);
Writes to the stream.
pick_t operator()() const; Equal to show().

File

nana/gui/wvl.hpp

Examples

The following code example shows how to use class msgbox to inform the user.

int main()
{
    using namespace nana::gui;
    form fm;
    fm.make_event<events::unload>(
            msgbox(fmx, STR("Form closing")).icon(msgbox::icon_information)<<STR("The form is closing now")
        );

    fm.show();
    exec();
}

The following code example shows how to ask user yes or no question and make a decision based on the respone.

void when_exit(const nana::gui::eventinfo& ei)
{
    using namespace nana::gui;
    msgbox mb(ei.window, STR("Nana C++ Library"), msgbox::yes_no);
    mb.icon(mb.icon_question);
    ei.unload.cancel = (mb.show() != msgbox::pick_yes);
}

int main()
{
    using namespace nana::gui;
    form fm;
    fm.make_event<events::unload>(when_exit);
    fm.show();
    exec();
}

Notes

1, The msgbox::operator() is equal to msgbox::show().

See also

None.


Move to The Nana Programmer's Guide Main Page