|
-
Jul 2nd, 2002, 03:23 AM
#1
Thread Starter
Lively Member
Adding icons to Menus????
Morning everyone,
Does anyone know how to add icons to menus? I have tried using the 'Adding Bitmaps to Menus' example on VB World but I could only get a bitmap image to appear next to the first item on my form menu.
My form menu structure is as follows:
File: New, Open, Close, Exit
Edit: Cut, Copy, Paste
What I need to do is add icons to the 'New, Open, Exit' items under the file menu and to 'Cut, Copy & Paste' under the edit menu.
The code I am using at the moment is the code from vb world:
The code below is in a code module
Code:
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&
The code below is in a Form
Code:
hMenu& = GetMenu(Form1.hwnd)
hSubMenu& = GetSubMenu(hMenu&, 0)
hID& = GetMenuItemID(hSubMenu&, 0)
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
Picture1.Picture, Picture1.Picture
Thanks in advance for any help,
Xan
-
Jul 2nd, 2002, 04:30 AM
#2
Frenzied Member
Try the control on VbSmart. There is alsoa tutorial on how to use the control and an example app which uses it.
Hopethishelpsyou
-
Jul 2nd, 2002, 04:31 AM
#3
VB Code:
Option Explicit
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&
Private Sub Form_Load()
Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
mHandle = GetMenu(Me.hwnd)
sHandle = GetSubMenu(mHandle, 0)
'--NEW
I1.Picture = imlToolbarIcons.ListImages(1).Picture
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, I1.Picture, I1.Picture)
'--VIEW
I1.Picture = imlToolbarIcons.ListImages(2).Picture
lRet = SetMenuItemBitmaps(sHandle, 1, MF_BYPOSITION, I1.Picture, I1.Picture)
'--DELETE
I1.Picture = imlToolbarIcons.ListImages(3).Picture
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, I1.Picture, I1.Picture)
'--SAVE
I1.Picture = imlToolbarIcons.ListImages(4).Picture
lRet = SetMenuItemBitmaps(sHandle, 3, MF_BYPOSITION, I1.Picture, I1.Picture)
'--PRINT
I1.Picture = imlToolbarIcons.ListImages(5).Picture
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, I1.Picture, I1.Picture)
'--CLEAR
I1.Picture = imlToolbarIcons.ListImages(6).Picture
lRet = SetMenuItemBitmaps(sHandle, 5, MF_BYPOSITION, I1.Picture, I1.Picture)
'--CLOSE
I1.Picture = imlToolbarIcons.ListImages(7).Picture
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, I1.Picture, I1.Picture)
End Sub
imlToolbarIcons.ListImages(7).Picture
is imagelist attached to toolbar...
u can use picture1.picture
-
Jul 2nd, 2002, 04:31 AM
#4
Frenzied Member
Oh and to post code, use [vbcode] [/vbcode] tags instead of the code tags to give the color formating
-
Jul 2nd, 2002, 04:39 AM
#5
-
Jul 2nd, 2002, 07:03 AM
#6
Lively Member
There is also a full-source module you can add in, found here. It works for single window apps, MDI, and toolbar buttonmenus.
Visit EliteVB for slimy subclassing tricks and GDI32 goodness.
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
|