Solved

icons in menus

Posted on 2004-09-25
4
329 Views
Last Modified: 2011-09-20
hi, i have a normal menu, made in menu editor. now this sounds pretty simple, id like to add icons to some menu items. just a normal 16x16 picture from an image list. ive looked around but i cant get anything working
0
Comment
Question by:Tai-San
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Expert Comment

by:anv
ID: 12150020
check this 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.
End Sub

'had copied it from somewhere ... :) for ,my project            
0
 
LVL 2

Author Comment

by:Tai-San
ID: 12150058
theres 2 simple problems with this.
1: i cant see text when image is appended
2: it cant use icons, which i need for the transperancy
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 12150354
0
 
LVL 2

Author Comment

by:Tai-San
ID: 12150635
well i was looking for some api to just put an icon on a menu, but that really beats my expectations :D its great, love the officeXP style :D thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

739 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