|
-
Sep 15th, 2001, 03:13 PM
#1
Problem With Menu Bitmaps
I used the following code to put bitmaps in my popupmenu:
Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Declare Function GetSubMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPos As Long) As Long
Declare Function GetMenuItemID Lib "user32" _
(ByVal hMenu As Long, ByVal nPos As Long) As Long
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
Public Const MF_BITMAP = &H4&
Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Declare Function GetMenuItemInfo Lib "user32" _
Alias "GetMenuItemInfoA" (ByVal hMenu As Long, _
ByVal un As Long, ByVal b As Boolean, _
lpMenuItemInfo As MENUITEMINFO) As Boolean
Public Const MIIM_ID = &H2
Public Const MIIM_TYPE = &H10
Public Const MFT_STRING = &H0&
Public Sub SetMenuIcon(frmForm As Form, mnuIndex As Integer, mnuPos As Integer, picChecked As PictureBox, picUnchecked As PictureBox)
Dim hMenu As Long
Dim hSubMenu As Long
Dim hID As Long
'Get the menuhandle of your app
hMenu& = GetMenu(frmForm.hWnd)
'Get the handle of the first submenu (Hello)
hSubMenu& = GetSubMenu(hMenu&, mnuIndex)
'Get the menuId of the first entry (Bitmap)
hID& = GetMenuItemID(hSubMenu&, mnuPos)
'Add the bitmap
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
picUnchecked.Picture, _
picChecked.Picture
'You can add two bitmaps to a menuentry
'One for the checked and one for the unchecked
'state.
End Sub
frmForm is the form to edit, mnuIndex is what menu to edit, mnuIndex is the index of that menu you want to add the bitmap to. It works great, except when it gets to an index where there is a sub menu. It seems to stop working all together when it tries to add a bitmap to a submenu index. Is there a way to fix this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|