VB打造超酷个性化菜单(二)(3)
中华网科技 http://tech.china.com
2005-07-01 13:31:33
|
|
|
‘ 创建弹出式菜单
Public Sub CreateMenu()
preMenuWndProc = SetWindowLong(frmMenu.hwnd, GWL_WNDPROC, AddressOf MenuWndProc)
hMenu = CreatePopupMenu()
Me.Style = STYLE_WINDOWS
End Sub
‘ 插入菜单项并保存自定义菜单项数组, 设置Owner_Draw自绘菜单
Public Sub AddItem(ByVal itemAlias As String, ByVal itemIcon As StdPicture, ByVal itemText As String, ByVal itemType As MenuItemType, Optional ByVal itemState As MenuItemState)
Static ID As Long, i As Long
Dim ItemInfo As MENUITEMINFO
‘ 插入菜单项
With ItemInfo
.cbSize = LenB(ItemInfo)
.fMask = MIIM_STRING Or MIIM_FTYPE Or MIIM_STATE Or MIIM_SUBMENU Or MIIM_ID Or MIIM_DATA
.fType = itemType
.fState = itemState
.wID = ID
.dwItemData = True
.cch = lstrlen(itemText)
.dwTypeData = itemText
End With
InsertMenuItem hMenu, ID, False, ItemInfo
‘ 将菜单项数据存入动态数组
ReDim Preserve MyItemInfo(ID) As MyMenuItemInfo
For i = 0 To UBound(MyItemInfo)
If MyItemInfo(i).itemAlias = itemAlias Then
Class_Terminate
Err.Raise vbObjectError + 513, "cMenu", "菜单项别名相同."
End If
Next i
With MyItemInfo(ID)
Set .itemIcon = itemIcon
.itemText = itemText
.itemType = itemType
.itemState = itemState
.itemAlias = itemAlias
End With
‘ 获得菜单项数据
With ItemInfo
.cbSize = LenB(ItemInfo)
.fMask = MIIM_DATA Or MIIM_ID Or MIIM_TYPE
End With
GetMenuItemInfo hMenu, ID, False, ItemInfo
‘ 设置菜单项数据
With ItemInfo
.fMask = .fMask Or MIIM_TYPE
.fType = MFT_OWNERDRAW
End With
SetMenuItemInfo hMenu, ID, False, ItemInfo
‘ 菜单项ID累加
ID = ID + 1
End Sub
首页 上页 | 1 | 2 | 3 | 4 | 下页 尾页 共 4 页
|