Solved

Adding images to form menu's

Posted on 2000-05-11
2
256 Views
Last Modified: 2008-02-01
When you use the menu bar at the top of the Visual Basic screen, there are 16x16 icons beside some of the menu items. Can icons of this size (presumably bitmaps) be added to the standard menu bar available to VB6 users?
0
Comment
Question by:mi5
2 Comments
 
LVL 9

Accepted Solution

by:
GivenRandy earned 50 total points
Comment Utility
Public Const MF_BYPOSITION = &H400& 'Menu
Public Const MF_BITMAP = &H4&
Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long

'PURPOSE:   Sets bitmap on a menu item
'ARGUMENTS:
'   hWnd:               handle of the window
'   iMenuIndex:         zero based index of the top-level menu item
'   iItemIndex:         zero based index of the menu subitem
'   Bitmap:             bitmap to set (usualy the .Picture property)
'
Public Sub SetMenuBitmap(hwnd As Long, iMenuIndex As Integer, iItemIndex As Integer, Bitmap As Long)
    Dim hMenu As Long
    hMenu = GetMenu(hwnd)
    hMenu = GetSubMenu(hMenu, iMenuIndex)
    ModifyMenu hMenu, iItemIndex, MF_BITMAP Or MF_BYPOSITION, 0, Bitmap
End Sub



0
 
LVL 1

Expert Comment

by:vbWayne
Comment Utility
Found this some time ago..it might help
with what you are after.

'add a picture to a memu item
' Remarks:
' open a new app...add a picture box and a command button
' build a menu with menu editor
' add a bitmap pic to the picture box 13 x 13
' NOT an icon...a bitmap
' if you don't want to make bitmaps there is a freeware icon extractor
' at the site below which will save Icons as bitmaps
' therefore you can use the icon once you convert it to a bitmap

' http://www.ozemail.com.au/~jaesenj/software.html
'
' this will add the pic to your menu item
'
'
'<<<<<  put his code in a bas module  >>>>>>>>>
 
Public Declare Function GetSubMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Public Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long



Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long

Public Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Boolean



Public Const MIIM_ID = &H2
Public Const MIIM_TYPE = &H10
Public Const MFT_STRING = &H0&
Public Const MF_BITMAP = &H4&

Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type
'
' <<<<<<<< put this code in the event you wish to use  >>>>>>>>
'
'Get the menuhandle of your app
hMenu& = GetMenu(Form1.hwnd)

'Get the handle of the first submenu (Hello)
hSubMenu& = GetSubMenu(hMenu&, 0)

'Get the menuId of the first entry (Bitmap)
hID& = GetMenuItemID(hSubMenu&, 0)

'Add the bitmap
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, Picture1.Picture, Picture1.Picture

'You can add two bitmaps to a menu entry one for the checked and one for 'the unchecked state.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now