我想动态的加载activebar 的菜单项,还要加一些bitmap,谁能帮我解决???

解决方案 »

  1.   

    Option ExplicitPrivate Sub ab_ToolClick(ByVal Tool As ActiveBar2LibraryCtl.Tool)
        Debug.Print Tool.Name
        If Tool.Name = "miFExit" Then Unload Me
    End SubPrivate Sub Form_Load()
        CreateTools
        CreateBands
    End SubPrivate Sub CreateTools()
    Dim Tool As ActiveBar2LibraryCtl.Tool
    Dim iCat As Integer
    Dim keys(0) As New ShortCut    iCat = 100
        Set Tool = ab.Tools.Add(iCat + 1, "mnuFile")
        Tool.Caption = "&File": Tool.SubBand = "mnuFile": Tool.Category = "Menus"
        Set Tool = ab.Tools.Add(iCat + 2, "mnuEdit")
        Tool.Caption = "&Edit": Tool.SubBand = "mnuEdit": Tool.Category = "Menus"
        Set Tool = ab.Tools.Add(iCat + 3, "mnuView")
        Tool.Caption = "&View": Tool.SubBand = "mnuView": Tool.Category = "Menus"
        Set Tool = ab.Tools.Add(iCat + 4, "mnuHelp")
        Tool.Caption = "&Help": Tool.SubBand = "mnuHelp": Tool.Category = "Menus"    iCat = 200
        Set Tool = ab.Tools.Add(iCat + 1, "miFNew")
        Tool.Caption = "&New...": Tool.Category = "File"
        keys(0) = "Control+N"
        Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\FileNew.bmp")
        Tool.ShortCuts = keys
        
        Set Tool = ab.Tools.Add(iCat + 2, "miFOpen")
        Tool.Caption = "&Open": Tool.Category = "File"
    '    Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\FileOpen.bmp")
        keys(0) = "Control+O"
        Tool.ShortCuts = keys
        
        Set Tool = ab.Tools.Add(iCat + 3, "miFSave")
        Tool.Caption = "&Save": Tool.Category = "File"
    '    Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\FileSave.bmp")
        keys(0) = "Control+S"
        Tool.ShortCuts = keys    Set Tool = ab.Tools.Add(iCat + 4, "miFExit")
        Tool.Caption = "E&xit": Tool.Category = "File"
        keys(0) = "Alt+F4"
        Tool.ShortCuts = keys    iCat = 300
        Set Tool = ab.Tools.Add(iCat + 3, "miECut")
        Tool.Caption = "C&ut": Tool.Category = "Edit"
    '    Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\EditCut.bmp")
        keys(0) = "Control+X"
        Tool.ShortCuts = keys
        
        Set Tool = ab.Tools.Add(iCat + 1, "miECopy")
        Tool.Caption = "&Copy": Tool.Category = "Edit"
    '    Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\EditCopy.bmp")
        keys(0) = "Control+C"
        Tool.ShortCuts = keys
        
        Set Tool = ab.Tools.Add(iCat + 2, "miEPaste")
        Tool.Caption = "&Open": Tool.Category = "Edit"
        ' Tool.SetPicture ddITNormal, LoadPicture(App.Path & "\icons\EditPsate.bmp")
        keys(0) = "Control+V"
        Tool.ShortCuts = keys
        
        iCat = 400
        Set Tool = ab.Tools.Add(iCat + 1, "miVToolbar")
        Tool.Caption = "&Toolbar": Tool.Category = "View"
        
        Set Tool = ab.Tools.Add(iCat + 2, "miVStatusBar")
        Tool.Caption = "&Statusbar": Tool.Category = "View"
        
        iCat = 500
        Set Tool = ab.Tools.Add(iCat + 1, "miHAbout")
        Tool.Caption = "&About": Tool.Category = "Help"
        keys(0) = "F1"
        Tool.ShortCuts = keys
    End SubPrivate Sub CreateBands()
    Dim b As ActiveBar2LibraryCtl.Band    Set b = ab.Bands.Add("mnuFile"): b.Type = ddBTPopup
        With b.Tools
            .Insert .Count, ab.Tools("miFNew")
            .Insert .Count, ab.Tools("miFOpen")
            .Insert .Count, ab.Tools("miFSave")
            .Insert .Count, ab.Tools("miFExit")
        End With    Set b = ab.Bands.Add("mnuEdit"): b.Type = ddBTPopup
        With b.Tools
            .Insert .Count, ab.Tools("miECut")
            .Insert .Count, ab.Tools("miECopy")
            .Insert .Count, ab.Tools("miEPaste")
        End With    Set b = ab.Bands.Add("mnuView"): b.Type = ddBTPopup
        With b.Tools
        .Insert .Count, ab.Tools("miVToolbar")
        .Insert .Count, ab.Tools("miVStatusBar")
        End With    Set b = ab.Bands.Add("mnuHelp"): b.Type = ddBTPopup
        b.Tools.Insert b.Tools.Count, ab.Tools("miHAbout")
        
        Set b = ab.Bands.Add("mnuMain"): b.Type = ddBTMenuBar
        
        ab.Tools("mnuFile").SubBand = "mnuFile"
        ab.Tools("mnuEdit").SubBand = "mnuEdit"
        ab.Tools("mnuView").SubBand = "mnuView"
        ab.Tools("mnuHelp").SubBand = "mnuHelp"
        
        With b.Tools
            .Insert .Count, ab.Tools("mnuFile")
            .Insert .Count, ab.Tools("mnuEdit")
            .Insert .Count, ab.Tools("mnuView")
            .Insert .Count, ab.Tools("mnuHelp")
        End With
        
        ab.RecalcLayout
        ab.Refresh
    End Sub