Solved

Adding images to form menu's

Posted on 2000-05-11
2
286 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
ID: 2800250
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
ID: 2800419
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

679 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