Archived

This topic is now archived and is closed to further replies.

dxluvin

inheriting a menu bar?

Recommended Posts

dxluvin    122
Ok I don''t even know if this is possible, but I''d like to create a parent class which has similar win32 menu behaviour as the D3DApplication class (basically it''s just a win32 shell application with a menu bar).. Anyways, *is* it possible to create another class which inherits from this class with the ability to ADD to the existing menu bar?? ie. the parent class has a file->exit and help->about Can I inherit into a child class to have: file->new game file->exit help->directions help->about is this even possible??

Share this post


Link to post
Share on other sites
IndirectX    122
I will assume that you use menus from a resource file, and not creating them at run-time.

In this case, an application class, window class, or any other class for that matter doesn''t "have" a menu that you can extend. They store a LPCTSTR (either a string or a MAKEINTRESOURCE()d int) that points to the appropriate menu resource. Therefore, you can''t "inherit" menus like you can do with classes.

Solution 1 (this is what D3DApp does): Have a HMENU data member that you initialize before you create window using CreateWindow[Ex]. In your base class, you load base class resource; in a derived class, you load another menu resource. This can be done in constructor. You have to have all menu items in each menu resource, however. Derived class must load a menu that has file->exit besides help->about. This is the easier solution.

Solution 2: generate menus at runtime. Use the menu functions in Win32 API (InsertMenuItem, etc.) to add/remove items to menus dynamically. This is a potentially more flexible alternative, especially if you want to do some fancy stuff with menus, but it takes more code to implement. A variation of this method is to create _all_ menus at runtime. Note that you have to provide a way for the base and derived classes to communicate so that both have a chance to add proper menu items during init in the correct order. I''ll stop here in case you''re not at all interested in taking this route.

What is best for you depends on your particular application requirements. Note that if you''re not modifying menus dynamically, your classes don''t have "inheritable" menus; they only work with complete menus as defined in your resource file.

Share this post


Link to post
Share on other sites