In some cases using a toolbox resource directly as it is
in the Res
file does not give enough flexibility.
This most often occcurs if you need to add some new gadgets to
a window or new menu items to a menu.
TBX provides a res namespace that allows you
to load and manipulate toolbox resources in memory. Each toolbox
object/gadget and menu item has a class prefixed with "Res" that
allows you to create and manipulate a toolbox resource template for
it. e.g. The tbx::Menu
class has a corresponding
tbx::res::ResMenu
class.
Objects can then be created with the constructor that takes this
res object, gadgets can be added to windows using the add_gadget
method and
menu items can be added to menus with add
method.
Two classes exist to use a resource file tbx::res::ResFile
which provides read-only access to a resource file and tbx::res::ResEditor
which allows a resource file to created, loaded and saved.
However in most cases you are likely to want to create a resource based
on one already existing in your normal Res
file. Any resource
template can be retrieved from the tbx::Application
class using the resource
method.
Example 11.1. Adding some extra menu items to a menu
tbx::res::ResMenu res_menu = tbx::app()->resource("RecentMenu"); tbx::res::ResMenuItem new_item = res_menu.item(0); while (i < num) { new_item.text(get_file_leaf_name(i).c_str()); new_item.component_id(i); _menu.add(new_item); i++; }