Private 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
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 GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As _ Long Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" _ (ByVal hMenu As Long, ByVal un As Long, ByVal b As Long, _ lpMenuItemInfo As MENUITEMINFO) As Long Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" _ (ByVal hMenu As Long, ByVal un As Long, ByVal bool As Boolean, _ lpcMenuItemInfo As MENUITEMINFO) As Long
Private Const MIIM_TYPE = &H10 Private Const RGB_STARTNEWCOLUMNWITHVERTBAR = &H20& Private Const MFT_STRING = 0
Function SplitSubMenu(ByVal hWnd As Long, ByVal itemsInSection As Long, _ ParamArray menuPos() As Variant) As Boolean Dim hMenu As Long Dim itemCount As Long Dim itemInfo As MENUITEMINFO Dim index As Long Dim ret As Long hMenu = GetMenu(hWnd) For index = 0 To UBound(menuPos) hMenu = GetSubMenu(hMenu, menuPos(index)) Next itemCount = GetMenuItemCount(hMenu) itemInfo.cbSize = Len(itemInfo) For index = itemsInSection To itemCount Step itemsInSection itemInfo.fMask = MIIM_TYPE itemInfo.fType = MFT_STRING itemInfo.dwTypeData = Space$(128) itemInfo.cch = Len(itemInfo.dwTypeData) ret = GetMenuItemInfo(hMenu, index, True, itemInfo) If ret = 0 Then Exit Function itemInfo.fType = itemInfo.fType Or RGB_STARTNEWCOLUMNWITHVERTBAR ret = SetMenuItemInfo(hMenu, index, True, itemInfo) If ret = 0 Then Exit Function Next SplitSubMenu = True End Function |