Important alert: (current site time 7/16/2013 4:12:50 AM EDT)
 

VB icon

Multiple Clickable Bitmaps on a drop menu in a for

Email
Submitted on: 2/14/1999
By: Patrick K. Bigley  
Level: Not Given
User Rating: By 100 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 23308
 
     Very short code! Newly updated and it WORKS! Display bitmaps instead of text on a drop menu, in a form. Use the VB Menu Editor to create a menu with sub menus, the code does the rest!! So easy you will slap yourself for using other people's lengthy drawn-out codes.

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Multiple 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
	
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Multiple Clickable Bitmaps on a drop menu in a for
' Description:Very short code! Newly updated and it WORKS! Display bitmaps instead of text on a drop menu, in a form. Use the VB Menu Editor to create a menu with sub menus, the code does the rest!! So easy you will slap yourself for using other people's lengthy drawn-out codes.
' By: Patrick K. Bigley
'
' 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)

'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1394&lngWId=1'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 form'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 copied and pasted below with
'different numbers for different menus and sub menus
'REMEMBER, go to the VB Menu editor (Ctrl+E) and create a menu item.
'Then create 3 sub menus. It doesn't matter 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. Use Image controls instead
'of Picture controls to save resources.
'Comments to opus@bargainbd.com
'http://bargainbd.com/opusopus/top.htm
End Sub


Other 32 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/26/1999 2:23:00 AMnorul

i would like to know how to put the icon besides each of the menu items.

please email me about the procedure or the source code if possible...!!!
(If this comment was disrespectful, please report it.)

 
4/27/1999 7:28:00 PMDW

This is such a cool thing, I have been looking for something like this to put in my program! Thanks!
(If this comment was disrespectful, please report it.)

 
8/22/1999 1:46:00 AMEugene

It is nice code. Thanks!
(If this comment was disrespectful, please report it.)

 
8/23/1999 1:31:00 AMRob

Excellent !! Can you tell me how to show both text and pictures ?? What other constants are there ?? e.g. shadow text
(If this comment was disrespectful, please report it.)

 
8/23/1999 10:13:00 AMPeter Ormsby

When I run the code this i get an error on this line in form1 :-

hMenu = GetMenu(Form1.hwnd)


Compile Error:
Invalid Outside Procedure.

Can you help?

(If this comment was disrespectful, please report it.)

 
3/19/2001 8:56:07 AMVasilis Sagonas

EXCELLENT! Can I please know if I can add a bitmap on the left side of the menu (like the Start menu) ... PLEASE email me vasilis@lar.forthnet.gr. Thanks
(If this comment was disrespectful, please report it.)

 
2/20/2003 3:30:19 PMajay kumar

HI This is what i wa finding (have more But not for only this purpose) Thanx ya i will meke context menu thumbnail viewer now
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.