Option Explicit
′菜单信息结构说明
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'所需的API函数和常数
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) _
  As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
  ByVal nPos As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias _
  "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
  ByVal b As Boolean, lpmii As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias _
  "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, _
  ByVal fByPosition As Long, lpmii As MENUITEMINFO) As LongConst MIIM_TYPE = &H10
Const RGB_STARTNEWCOLUMNWITHVERTBAR = &H20&
Const MFT_STRING = &H0&
  在窗体中添加一个命令按钮,Caption=“分割菜单”,双击写如下代码:Private Sub Command1_Click()
  Dim rv As Long
  Dim hSubMenu As Long
  Dim mnuItemCount As Long
  Dim mInfo As MENUITEMINFO
  Dim pad As Long
  '获取菜单项句柄和子菜单项数
  hSubMenu=GetSubMenu(GetMenu(Me.hwnd), 0)
  mnuItemCount=GetMenuItemCount(hSubMenu)
  '将子菜单项分成两部分
  If mnuItemCount Mod 2<>0 Then pad=1
  '取得当前菜单信息
  mInfo.cbSize=Len(mInfo)
  mInfo.fMask=MIIM_TYPE
  mInfo.fType=MFT_STRING
  mInfo.dwTypeData=Space$(256)
  mInfo.cch=Len(mInfo.dwTypeData)
  rv=GetMenuItemInfo(hSubMenu, (mnuItemCount\2)+pad, True, mInfo)
  '按新格式显示菜单
  mInfo.fType=RGB_STARTNEWCOLUMNWITHVERTBAR
  mInfo.fMask=MIIM_TYPE
  rv=SetMenuItemInfo(hSubMenu, (mnuItemCount\2)+pad, True, mInfo)
  If rv Then MsgBox "分割完毕"
End Sub