Solved

Menu Bar Icons

Posted on 2004-09-01
2
239 Views
Last Modified: 2010-05-02
I want to add icons to the menu bar in my VB application (similar to MSWords disk icon next to the word save and cntl-S).  Does anyone have a way to add icons to the menu bar next to the command name?

Thanks in advance for your help!
0
Comment
Question by:amangle
2 Comments
 
LVL 4

Assisted Solution

by:ChenChen
ChenChen earned 41 total points
ID: 11959470
0
 
LVL 10

Accepted Solution

by:
anv earned 30 total points
ID: 11960318
here's the code


'**************************************
'Windows API/Global Declarations for :Mu
'     ltiple Clickable Bitmaps on a drop menu
'     in a for
'**************************************


Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long


Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos 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
    '***Part of the bonus code**************
    '     ******************


Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    '***************************************
    '     ******************
    Global Const MF_BITMAP = 4
          
'**************************************
' Name: Multiple Clickable Bitmaps on a
'     drop menu in a for
' Description:Very short code! Newly upd
'     ated and it WORKS! Display bitmaps inste
'     ad of text on a drop menu, in a form. Us
'     e the VB Menu Editor to create a menu wi
'     th sub menus, the code does the rest!! S
'     o easy you will slap yourself for using
'     other people's lengthy drawn-out codes.
' By: Patrick K. Bigley
'
'
' Inputs:None
'
' Returns:Places images onto a menu
'
'Assumes:Create a form (Form1)
Add a module (Module1)
Add three image controls (Image1, Image2, Image3)
Assign a small BITMAP for each Image Control in
its picture property.
IMPORTANT: You need to create a Menu, so go to
the VB Menu Editor (Ctrl+E) and create a main menu.
Then create 3 Sub Menus. It doesn't matter what you
name any of the menus or menu options because this
code does the work for you.
Copy and paste the API into a Module (Module1)
Copy and paste the rest of the code into
the form (Form1)

'
'Side Effects:None
'This code is copyrighted and has limite
'     d warranties.
'Please see http://www.Planet-Source-Cod
'     e.com/xq/ASP/txtCodeId.1394/lngWId.1/qx/
'     vb/scripts/ShowCode.htm
'for details.
'**************************************



Private Sub Form_Load()
    Dim hMenu As Long, hSubMenu As Long, MenuID As Long
    '**************Bonus Code Below*********
    '     ********************************
    'This bonus code adds a bitmap to the fo
    '     rm's main drop menu. Click the
    'titlebar with the right mouse button to
    '     see thr effect.
    hMenu = GetMenu(Form1.hwnd)
    hMenu = GetSystemMenu(hwnd, 0)
    MenuID = 0
    'MenuID = &HF120 'This places the bitmap
    '     as first, but looks distorted
    'when the option is not minimized. This
    '     is the "restore" option.
    X% = ModifyMenu(hMenu, MenuID, MF_BITMAP, MenuID, CLng(Image1.Picture))
    '**************Bonus Code above*********
    '     ********************************
    hMenu = GetMenu(Form1.hwnd)
    hSubMenu = GetSubMenu(hMenu, 0) 'The "0" here is for the first menu Item.
    'A "1" can be used for the second and a
    '     "3"
    'for the third and so on...
    'You may not want all menu items to have
    '     images
    'so you can skip a number
   
    MenuID = GetMenuItemID(hSubMenu, 0) 'The "0" here is for the first SUB menu Item.
    'A "1" can be used for the second and a
    '     "3"
    'for the third and so on...
    'You may not want all SUB menu items to
    '     have images
    'so you can skip a number
    X% = ModifyMenu(hMenu, MenuID, MF_BITMAP, MenuID, CLng(Image1.Picture))
    MenuID = GetMenuItemID(hSubMenu, 1)
    X% = ModifyMenu(hMenu, MenuID, MF_BITMAP, MenuID, CLng(Image2.Picture))
    MenuID = GetMenuItemID(hSubMenu, 2)
    X% = ModifyMenu(hMenu, MenuID, MF_BITMAP, MenuID, CLng(Image3.Picture))
    'Note: The entire code above can be copi
    '     ed and pasted below with
    'different numbers for different menus a
    '     nd sub menus
    'REMEMBER, go to the VB Menu editor (Ctr
    '     l+E) and create a menu item.
    'Then create 3 sub menus. It doesn't mat
    '     ter what you
    'name any of the menus or menu options.
    'Tip: Bitmaps work best. GIFs that have
    '     invisible colors do not appear invisible
    '    
    'and icon (*.ico) do not work at all. Us
    '     e Image controls instead
    'of Picture controls to save resources.
    'Comments to opus@bargainbd.com
    'http://bargainbd.com/opusopus/top.htm
End Sub

            


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 67
Looking for VB6 code to read SQL table export it to ascii 8 32
using web browser with BING 40 110
Prevent user closing word document opened with VB6 6 67
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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 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

22 Experts available now in Live!

Get 1:1 Help Now