Set Icon in Menu Using VB 6.0

Untitled

‘———————–Mnue Icon Declaration————————————————————–
Private Declare Function ShellAbout Lib “shell32.dll” Alias “ShellAboutA” (ByVal hWnd As Long, _
ByVal szApp As String, _
ByVal szOtherStuff As String, _
ByVal hIcon As Long) As Long

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&
‘—————————–End Mnue Icon Declaration——————————————————-

Private Sub SetMenuIcon()
On Error Resume Next
Dim hMenu As Long
Dim hSubMenu As Long
Dim Ret As Long
‘Get main menu ID
hMenu = GetMenu(hWnd)


‘MENU FILE

‘Get sub menu 0 (File items)
hSubMenu = GetSubMenu(hMenu, 0)

‘set bitmap to menu item, by ordinal
Ret = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, iNew.Picture, iNew.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, iCut.Picture, iCut.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 2, MF_BYPOSITION, iOpen.Picture, iOpen.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 4, MF_BYPOSITION, iCurrency.Picture, iCurrency.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 5, MF_BYPOSITION, iCopy.Picture, iCopy.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 6, MF_BYPOSITION, iSalaryAdjust.Picture, iSalaryAdjust.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 7, MF_BYPOSITION, iCurrency.Picture, iCurrency.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 8, MF_BYPOSITION, iSalaryAdjust.Picture, iSalaryAdjust.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 9, MF_BYPOSITION, iOpen.Picture, iOpen.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 10, MF_BYPOSITION, iEmp.Picture, iEmp.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 12, MF_BYPOSITION, iSalaryAdjust.Picture, iSalaryAdjust.Picture)
‘Skip the separator (it’s 10)
Ret = SetMenuItemBitmaps(hSubMenu, 14, MF_BYPOSITION, iExit.Picture, iExit.Picture)


‘ MENU EDIT

‘Get sub menu 1 (Edit items)
hSubMenu = GetSubMenu(hMenu, 1)
Ret = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, iEmp.Picture, iEmp.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, iUnit.Picture, iUnit.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 2, MF_BYPOSITION, iDepartment.Picture, iDepartment.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 3, MF_BYPOSITION, iDesig.Picture, iDesig.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 5, MF_BYPOSITION, iAdd.Picture, iAdd.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 6, MF_BYPOSITION, iUnit.Picture, iUnit.Picture)

‘ MENU EDIT

‘Get sub menu 2 (Help items)
hSubMenu = GetSubMenu(hMenu, 2)
Ret = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, iPrint.Picture, iPrint.Picture)

‘Get sub menu 3 (Help items)
hSubMenu = GetSubMenu(hMenu, 3)
Ret = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, iHelp.Picture, iHelp.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, iCut.Picture, iCut.Picture)

End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s