Link to home
Start Free TrialLog in
Avatar of jumpy
jumpy

asked on

Menu bar with images

How can I add an image to a menu Bar item (just like in WORD, Excel etc.)
I don't see any way doing it with the Menu Editor.
Avatar of Dalin
Dalin

jumpy,
Try this. Let me know if you have any questions
Regards
Dalin


'This code sample will change the actual menu bitmaps size,
'     'font size, color, and caption. Run the application and 'sel
'     ect the BitMenu and view the selections. Then click 'the for
'     m and revisit the BitMenu. '--------------------------------
'     ------------------------- Sub Command2_Click ()
'     '* Example to create a dynamic menu system
hMenu% = GetMenu(hWnd)
hSubMenu% = GetSubMenu(hMenu%, 0)

For i% = 0 To Number_of_Menu_Selections - 1
       '     '* Place some text into the menu.
        SubMenu(i%).Caption = Picture3(i%).FontName +
       Str$(Picture3(i%).FontSize) + " Pnt"
       '     '* 1. Must be AutoRedraw for Image().
       '     '* 2. Set Backcolor of Picture control to that of the
       '     '*current system Menu Bar color, so Dynamic bitmaps
       '     '*will appear as normal menu items when menu bar
       '     '*color is changed via the control panel
       '     '* 3. See the bitmaps on screen, this could all be done
       '     '*at design time.
        Picture3(i%).AutoRedraw = TRUE
        Picture3(i%).BackColor = CLR_MENUBAR
       '     '* You can uncomment this
       '     '* Picture3(i%).Visible = FALSE
       '     '* Set the width and height of the Picture controls
       '     '* based on their corresponding Menu items caption,
       '     '* and the Picture controls Font and FontSize.
       '     '* DoEvents() is necessary to make new dimension
       '     '* values to take affect prior to exiting this Sub.
       Picture3(i%).Width = Picture3(i%).TextWidth(SubMenu(i%).Caption)
       Picture3(i%).Height = Picture3(i%).TextHeight(SubMenu(i%).Caption)
       Picture3(i%).Print SubMenu(i%).Caption
       '     '* - Set picture controls backgroup picture (Bitmap) to
       '     '*its Image.
        Picture3(i%).Picture = Picture3(i%).Image
        x% = DoEvents()
Next i%

'     '* Get handle to forms menu.
hMenu% = GetMenu(Form1.hWnd)
'     '* Get handle to the specific menu in top level menu.
hSubMenu% = GetSubMenu(hMenu%, 0)

For i% = 0 To Number_of_Menu_Selections - 1
       '     '* Get ID of sub menu
        menuId% = GetMenuItemID(hSubMenu%, i%)
       '     '* Replace menu text w/bitmap from corresponding picture
       '     '* control
        x% = ModifyMenu(hMenu%, menuId%, MF_BITMAP, menuId%,
        CLng(Picture3(i%).Picture)) 'append this to previous line
       '     '* Replace bitmap for menu check mark with custom check
       '     '* bitmap
        x% = SetMenuItemBitmaps(hMenu%, menuId%, 0, 0, CLng(picture2.Picture))
Next i%

End Sub
Avatar of jumpy

ASKER

Running your function I get an error on this line:
SubMenu(i%).Caption = Picture3(i%).FontName +
           Str$(Picture3(i%).FontSize) + " Pnt"

After changing "SubMenu(i%)" to "hSubMenu(i%)" I get an error: "Expected Array".

Can you Please send a simple Working Example ?
ASKER CERTIFIED SOLUTION
Avatar of Dalin
Dalin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial