Bitmaps in Menus

 

horizontal rule

Back Home Next

Author Aart Onkenhout
Date 28-09-2000

 

With the appearance of every new version of MS Office, new GUI 'features' are added to them. With Office 97, buttons were added to the menus. In PowerBuilder you don't have an option of putting a button to the left of a menu-item.

To make it possible to add buttons to a PowerBuilder menu, I wrote a C++-dll to establish it. The dll takes over the painting of the menu. Via a non-visual userobject the bitmaps or StockItems that must be shown to the left of the menuitems are added to an ImageList (created within the dll). Furthermore, messages sent to the application Window are intercepted by the dll and handled if menu-painting is concerned. All other messages are sent through to the application window.

 

Usage

 

To use the dll put it in your application directory or system-direcory. The nonvisual userobject (n_coolmenu) contains a couple of functions you can call.

 

bullet

of_SetRequestor( Ref Window aw_Requestor ) Returns Integer. Registers the window requesting the 'service'.

bullet

of_SetMenu( String as_Menu ) Returns Integer. Must be called to determine the bitmaps that must be shown to the left of the menuitems. Some points:
bullet

when a menu has descendants, call of_SetMenu with the last descendant. In this way it's certified that all bitmaps and stockitems are registered with the dll.

bullet

bitmaps are associated with menuitems by using the menuitemtext. When building the imagelist, another list is made which associates an imagelist-id with the menuitemtext. This means that when you change a menuitemtext at runtime, the dll can no longer show the right bitmap. Secondly, when you have two menuitems with the same text but with another bitmap, the bitmap that is associated with the first menuitem that the of_SetMenu function encounters is used for both menuitems. To handle this you can add a space to the end of the text of one of the menuitems or let one have a shortcut key.

bullet

of_SetButtonOn( Boolean ab_Switch ) Returns Integer. With this function you can give the user the opportunity to switch between menus with or without bitmaps.

bullet

of_ToolbarVisibleOnly( Boolean ab_Switch ) Returns Integer. By using this function you can tell the of_SetMenu function to just show bitmaps that are visible on the toolbars. So you must call this one before calling of_SetMenu.

 

The dll works with StockItems, .bmp and .ico files. The stockitems are all included within the dll (PowerBuilder versions 6, 7 and 8).

 

Sample Script

 

You can code the following in the Open-event of your MDI- or Main Window.

 

inv_CoolMenu.of_SetRequestor( This )
inv_CoolMenu.of_ToolbarVisibleOnly( False )
inv_CoolMenu.of_SetMenu( 'm_coolmenu' )

 

 

Sample Screen

 

 

Download

 

The usage of this dll is at your own risk. I developed it in my spare time and aren't asking any money for it. So it's not a commercial product. As far as I know (but I couldn't test it on every Windows-version that exists) it works very well. If you find any problems in using this dll you can e-mail me. I will try to fix problems as soon as I can. But remember, it was meant for one of my own applications, and I decided to put it on my website so you can use it if you like to. But every responsibility for using it is for yourselfs (I know this all sounds a bit paranoid, but one never knows).

You can download the dll and a sample application (PB7) here.

 

Download coolmenu.zip