2018-09-05 02:51



#Region "UI Methods"
Public Sub AddCommandMgr()

    Dim cmdGroup As ICommandGroup 'interface 接口 集合封装

    If iBmp Is Nothing Then
        iBmp = New BitmapHandler() '? 实例化
    End If

    Dim thisAssembly As Assembly '无冲突程序集

    Dim cmdIndex0 As Integer, cmdIndex1 As Integer
    Dim Title As String = "VS Addin"
    Dim ToolTip As String = "VB Addin"

    Dim docTypes() As Integer = {swDocumentTypes_e.swDocASSEMBLY, _
                                   swDocumentTypes_e.swDocDRAWING, _
                                   swDocumentTypes_e.swDocPART} '枚举 自定义集合 _e?

    thisAssembly = System.Reflection.Assembly.GetAssembly(Me.GetType())

    Dim cmdGroupErr As Integer = 0
    Dim ignorePrevious As Boolean = False

    Dim registryIDs As Object = Nothing
    Dim getDataResult As Boolean = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, registryIDs) '得到注册ID
    Dim knownIDs As Integer() = New Integer(1) {mainItemID1, mainItemID2}

    If getDataResult Then
        If Not CompareIDs(registryIDs, knownIDs) Then 'if the IDs don't match, reset the commandGroup
            ignorePrevious = True
        End If
    End If

    cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, cmdGroupErr)
    If cmdGroup Is Nothing Or thisAssembly Is Nothing Then
        Throw New NullReferenceException() 'throw 手动抛出异常
    End If

    cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.ToolbarLarge.bmp", thisAssembly) '(位图名称,)
    cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.ToolbarSmall.bmp", thisAssembly)
    cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.MainIconLarge.bmp", thisAssembly)
    cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("SwVBAddin1.MainIconSmall.bmp", thisAssembly)

    Dim menuToolbarOption As Integer = swCommandItemType_e.swMenuItem Or swCommandItemType_e.swToolbarItem

    cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption)
    cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "PMPEnable", mainItemID2, menuToolbarOption)

    cmdGroup.HasToolbar = True '工具窗口有一个工具栏
    cmdGroup.HasMenu = True

    Dim flyGroup As FlyoutGroup '????????????
    flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", _
          cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable")

    flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1")

    flyGroup.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

    For Each docType As Integer In docTypes 'For Each <成员> In <数组>
        Dim cmdTab As ICommandTab = iCmdMgr.GetCommandTab(docType, Title)
        Dim bResult As Boolean

        If Not cmdTab Is Nothing And Not getDataResult Or ignorePrevious Then 'if tab exists, but we have ignored the registry info, re-create the tab.  Otherwise the ids won't matchup and the tab will be blank
            Dim res As Boolean = iCmdMgr.RemoveCommandTab(cmdTab)
            cmdTab = Nothing
        End If

        If cmdTab Is Nothing Then
            cmdTab = iCmdMgr.AddCommandTab(docType, Title)

            Dim cmdBox As CommandTabBox = cmdTab.AddCommandTabBox

            Dim cmdIDs(3) As Integer
            Dim TextType(3) As Integer

            cmdIDs(0) = cmdGroup.CommandID(cmdIndex0)
            TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

            cmdIDs(1) = cmdGroup.CommandID(cmdIndex1)
            TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

            cmdIDs(2) = cmdGroup.ToolbarId
            TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

            bResult = cmdBox.AddCommands(cmdIDs, TextType)

            Dim cmdBox1 As CommandTabBox = cmdTab.AddCommandTabBox()
            ReDim cmdIDs(1) '动态数组
            ReDim TextType(1)

            cmdIDs(0) = flyGroup.CmdID
            TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

            bResult = cmdBox1.AddCommands(cmdIDs, TextType)

            cmdTab.AddSeparator(cmdBox1, cmdIDs(0)) '增加分隔符

        End If

    thisAssembly = Nothing

End Sub

Public Sub RemoveCommandMgr()
    Try '调试可能异常代码
    Catch e As Exception '错误跳入e
    End Try
End Sub

Function AddPMP() As Boolean
    ppage = New UserPMPage '大类UserPMPage
    ppage.Init(iSwApp, Me) '(sw,addin)
End Function

Function RemovePMP() As Boolean
    ppage = Nothing
End Function

Function CompareIDs(ByVal storedIDs() As Integer, ByVal addinIDs() As Integer) As Boolean

    Dim storeList As New List(Of Integer)(storedIDs) '类 List
    Dim addinList As New List(Of Integer)(addinIDs)

    addinList.Sort() '元素排序

    If Not addinList.Count = storeList.Count Then

        Return False

        For i As Integer = 0 To addinList.Count - 1
            If Not addinList(i) = storeList(i) Then

                Return False
            End If
    End If

    Return True
End Function

#End Region

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答