Listing 2
wnd<> w = ...;
// cast to list control - throws on failure
wnd<list_ctrl> list = cast<list_ctrl>(w);
wnd<dialog> dlg = cast<dialog>( parent() );
// same as 'wnd<dialog> dlg = parent<dialog>();'
wnd<button> b = ...;
// find out the real type of this button;
// no try_ function throws
wnd<check_box> c_b = try_cast<check_box>(b);
wnd<radio_button> r_b = try_cast<radio_button>(b);
wnd<group_box> g_b = try_cast<group_box>(b);
if ( c_b != null_wnd) msg_box(0, "check box");
else if ( r_b != null_wnd) msg_box(0, "radio button");
else if ( g_b != null_wnd) msg_box(0, "group box");
// using try_cast, you can use assign-is-condition idiom
if ( wnd<check_box> w = try_cast<check_box>(b))
w->check_state( check_box::indeterminate);
else if ( wnd<radio_button> w = try_cast<radio_button>(b)) w->set_checked();
else if ( wnd<group_box> w = try_cast<group_box>(b)) w->enable(false);