none
vb6 Menu 切割 SetMenuItemInfo API 的問題 RRS feed

  • 一般討論

  • 請問各位前輩, 小弟有一個Menu 有一個一級menu1 一個是二級的menu2

    我在二級的選單中加入 50個選項,由於50選項太長,小弟有上網找到API可以切割表單

    ,只是小弟欲到一些問題

    一開始的men的遠本樣子

    M1

    ..M11

    ..M12

    ..M13

    ...

    ...M50

     

    小弟寫出來的結果變成

    M1  

    M11 | M11 | M11

    M12 | M22 | M32

    M13 | M23 | M33

    ...   | ...

    M20| M30

    小弟的第一個Item 都變成第一個,請問各位前輩是哪裡有問題??

    程式碼如下

    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

    Private Const MF_MENUBARBREAK = &H20& ' columns with a separator line
    Private Const MF_MENUBREAK = &H40&    ' columns w/o a separator line
    Private Const MF_STRING = &H0&
    Private Const MF_HELP = &H4000&
    Private Const MFS_DEFAULT = &H1000&

    Private Const MIIM_ID = &H2
    Private Const MIIM_SUBMENU = &H4
    Private Const MIIM_TYPE = &H10
    Private Const MIIM_DATA = &H20
    Const MFT_STRING = &H0&

     

    Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long

    Private Declare Function GetMenuItemInfo Lib "user32" _
       Alias "GetMenuItemInfoA" _
       (ByVal hMenu As Long, ByVal un As Long, ByVal B As Boolean, _
       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 Declare Function DrawMenuBar 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 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, 0, True, mInfo)
      
       mInfo.fType = mInfo.fType Or MF_MENUBREAK
       mInfo.fMask = MIIM_TYPE
       rv = SetMenuItemInfo(hSubMenu, 10, True, mInfo)
      
      
       mInfo.fType = mInfo.fType Or MF_MENUBREAK
       mInfo.fMask = MIIM_TYPE
       rv = SetMenuItemInfo(hSubMenu, 20, True, mInfo)
      
     
       rv = SetMenuItemInfo(hSubMenu, 30, True, mInfo)
       
       DrawMenuBar (Me.hwnd)
         
    End Sub

    Private Sub Form_Load()

       Dim i As Integer
      
       For i = 1 To 50
        Load T15(i)
        T15(i).Caption = "T" & CStr(i + 15)
        T15(i).Visible = True
       Next
       
    End Sub

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
       If Button = vbRightButton Then
          PopupMenu T2   ' Use the name of one of your menus.
       End If
    End Sub

    2010年11月8日 上午 07:07

所有回覆

  • 超過預設內建的功能時,請自己建立 Windows Form ,若仍不敷使用,只能靠 VC 來建立底層 OCX 類別給 VB6 用。


    T.L. Cheng
    2010年11月20日 下午 12:37
    版主