Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to define the icons in menu bar?

Status
Not open for further replies.

PankajAgr

Technical User
Jul 30, 2003
52
0
0
IN
Hi Guys,

I want to attach the icons in menu bar. There is no way to attach the icons with menu in Menu Editor.

Is there any alternative solution is available to define the icons?

Please suggest me some solutions...

Thanks
Pankaj
 
Search this forum for adding bitmaps to menus. You can't add an icon but you can add a 13x13 bitmap.

Good Luck

Matt
 
Heres some code that does the trick not mine but it works a treat

Code:
Option Explicit

' MenuBmp sample by Matt Hart - mhart@taascforce.com
' [URL unfurl="true"]http://www.webczar.com/defcon/mh/vbhelp.html[/URL]
' [URL unfurl="true"]http://www.webczar.com/defcon/mh[/URL]
'
' This sample shows you how to add bitmaps to your
' menu items.  First, you must retrieve the VB menu handle
' with the GetMenu API call.  Then, you set the Unchecked and
' Checked bitmaps (I don't differentiate between the two
' with this example - usually you would put a checkmark in
' the bitmap and use that for Checked).
'
' Note that the Picture property of an Image control (or
' a Picture control) is the Bitmap Handle, this the Image
' controls can be used like a bitmap resource.
'
' I also have one sub menu so that you can see how getting
' submenu handles and item positions works.

Private Declare Function GetMenu Lib "user32" _
   (ByVal hwnd As Long) As Long

Private Declare Function GetSubMenu Lib "user32" _
   (ByVal hMenu As Long, ByVal nPos As Long) As Long

Private 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

Const MF_BYPOSITION = &H400&

' VB 5 doesn't need this declration, but VB 4 does.
' Private Declare Function VarPtr Lib "VB40032.DLL" (variable As Any) As Long

Private Sub Form_Load()
    Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
    mHandle = GetMenu(hwnd)
    sHandle = GetSubMenu(mHandle, 0)
    lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, imOpen.Picture, imOpen.Picture)
    lRet = SetMenuItemBitmaps(sHandle, 1, MF_BYPOSITION, imSave.Picture, imSave.Picture)
    lRet = SetMenuItemBitmaps(sHandle, 3, MF_BYPOSITION, imPrint.Picture, imPrint.Picture)
    lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, imPrintSetup.Picture, imPrintSetup.Picture)
    sHandle = GetSubMenu(mHandle, 1)
    sHandle2 = GetSubMenu(sHandle, 0)
    lRet = SetMenuItemBitmaps(sHandle2, 0, MF_BYPOSITION, imCopy.Picture, imCopy.Picture)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top