Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding images to form menu's

Posted on 2000-05-11
2
Medium Priority
?
311 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 150 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

886 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