Posted by: nanaproject | May 16, 2012

Tutorial of Release 0.2.3

This release makes a great improvement for X11 support, such as Drag and Drop event and dataexch(clipboard), this indicates the Nana C++ Library should be work well with Linux(X11). In addition, there are new features in this release.

class msgbox
class msgbox is used for displaying a modal dialog box to prompt a biref message. A brief example.

nana::gui::msgbox m(STR(“msgbox example”));
m<<STR(“This is a msgbox example.”);

The msgbox is a C++ stream style, so we can easy to display strings, numbers and all the objects whose type overloads an operator<<() for std::ostream.

Sometimes, the application should ask user for a decision, for example, ask user whether to exit.

void when_exit(const nana::gui::eventinfo& ei)
    nana::gui::msgbox m(ei.window, STR(“msgbox example”), nana::gui::msgbox::yes_no);
    m<<STR(“Are you sure you want to exit the game?”);
    ei.unload.cancel = (m() != m.pick_yes);

int main()
    using namespace nana::gui;
    form fm;

Window Icon
There are two interfaces to set an icon for a window which is a root_widget, such as form and nested_form, thay are defined in namespace nana::gui::API.

void window_icon_default(const nana::paint::image&);
void window_icon(nana::gui::window, const nana::paint::image&);

window_icon_default() sets a default icon, and after calling it, all windows will set the default icon automatically while they are creating.

Although the Nana C++ Library is aimed for cross-platform, there is a distinction in Nana between Windows and Linux(X11). The icon of a window only could be an ICON file in Windows. If cross-platform is desired, the code should be treated differently.

using namespace nana::gui;
form fm;
#if defined(NANA_WINDOWS)
API::window_icon(fm, nana::paint::image(STR(“icon.ico”)));
API::window_icon(fm, nana::paint::image(STR(“icon.bmp”)));

Under Windows, the icon of window is the icon of exe file usually, the icon file is stored in the exe file as a resouce. To set the icon resouce for the window, we just open the exe with class image in this way.
API::window_icon(a_form_object, nana::paint::image(STR(“program.exe”)));


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: