Using Message Box - cnjinhao/nana GitHub Wiki

Introduction

Class msgbox displays a message in a popup dialog.

nana::msgbox msg{"Title"};
msg<<"This is a message box.";
msg.show();

The msgbox is also a function object. It can be applied with function call syntax.

nana::msgbox msg{"Title"};
msg<<"This is a message box.";
msg();

With the function object feature, it is possible to easy to use the msgbox as an event handler.

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

    fm.show();
    exec();
}

Popups a message for user confirming.

#include <nana/gui.hpp>
int main()
{
	using namespace nana;
	form fm;
	fm.events().unload([](const arg_unload& arg){
		msgbox mb{arg.window_handle, "Nana C++ Library", msgbox::yes_no};
		mb.icon(mb.icon_question);
		mb << "Do you really want to exit?";
		//Popups the message and wait for user selecting.
		//If arg.cancel is true, it stops closing the form.
		arg.cancel = (mb.show() != msgbox::pick_yes);
	});
	fm.show();
	exec();
}