Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Images in Menu


Message #1 by "_Back From The Death" <memanishjain@y...> on Wed, 27 Feb 2002 23:17:49 -0800
Hi 
I posted this a couple of days ago for someone else. This uses the
standard vb menu....

There are a couple of API's you can use, I found this example from Dan
Fox, author of Pure Visual Basic. This technique replaces the caption
with an image (please note only BMP file types can be used).

Public Declare Function WinGetMenu Lib "user32" Alias "GetMenu"(byval
hwnd as long) as long

Public declare Function WinGetSubMenu Lib "User32" Alias "GetsubMenu"
(byval hMenu as long, byval nPos as long) as long

Public declare function WinModifymenu 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

Public const MF_BYPOSITION = &H400&
Public Const MF_BITMAP = &H4&

Public function AddmenuImage(pForm as Form, byval pMenuNum as long,
byval pMenuItemNum as long, byval pImageHandle as long) as boolean

Dim lngMenuID as long
Dim lngMenuHandle as long
Dim lngSubMenuHandle as long
Dim lngRet as long

AddmenuImage = False
On error resume Next

'get a handle on the forms menu
lngMenuHandle = WinGetMenu(pForm.hwnd)
If lngMenuHandle = 0 then exit function

'get a handle to the top level menu using its position lngSubMenuHandle
= WinGetSubMenu(lngMenuHandle, pMenuNum) If lngSubMenuHandle = 0 then
exit function

'place the bitmap on the menu
LngRet = winModifyMenu(lngSubMenuHandle, pMenuItemNum, MF_BITMAP OR
MF_BYPOSITION, 0 , pImangeHandle)

If lngRet > 0 then 
	addmenuimage = true
End if


End function 


If you require to keep the caption and provide an image to the left of
it then you need to investigate the SetMenuItemBitmaps API function,
sorry no example code.


The another alternative is the Active Bar from Datadynamics, much easier
and more functionality....


Duncan MCP,MCSD,AMIAP


  Return to Index