방법: 추가 기능을 바로 가기 메뉴에 표시

업데이트: 2007년 11월

Visual Studio 자동화 모델을 사용하면 최상위 메뉴(예: 도구 메뉴)에 추가 기능 명령을 쉽게 배치할 수 있으며 바로 가기 메뉴와 하위 메뉴에 명령을 추가할 수도 있습니다.

이렇게 하려면 Microsoft Visual Studio 명령 모음 개체 모델을 사용하여 대상 바로 가기 메뉴와 하위 메뉴를 명시적으로 정의해야 합니다. 그런 다음 Visual StudioAddControl 메서드를 호출해야 합니다.

바로 가기 메뉴는 Visual Studio의 다른 메뉴와 비슷합니다. 이 메뉴에 액세스하려면 드롭다운 메뉴에서 아래쪽 화살표를 가리키거나 IDE(통합 개발 환경)에서 항목을 마우스 오른쪽 단추로 클릭합니다.

바로 가기 메뉴(또는 다른 메뉴나 도구 모음)에 명령을 추가하려면 먼저 해당 명령 이름을 알아야 합니다. 이름을 찾으려면 도구 메뉴의 옵션 대화 상자에 있는 키보드 노드를 검색합니다. 사용 가능한 추가 기능 샘플에서 특정 메뉴 항목을 검색한 다음 해당 명령 이름과 기타 관련 정보를 반환합니다. 이 추가 기능 샘플의 이름은 "Command Browse Add-in"이며 Visual Studio Automation Samples 사이트에 있습니다. 추가 기능을 사용하려면 프로젝트의 압축을 풀고 빌드한 다음 포함된 AddinReg.reg 파일을 실행하고 도구 메뉴에서 Command Browser 명령을 클릭합니다.

다음 절차에서는 작업 목록 바로 가기 메뉴에 추가 기능 명령을 추가하는 방법을 보여 줍니다.

참고:

표시되는 대화 상자와 메뉴 명령은 실제 설정이나 버전에 따라 도움말에서 설명하는 것과 다를 수 있습니다. 이러한 절차는 일반 개발 설정을 사용하여 개발되었습니다. 설정을 변경하려면 도구 메뉴에서 설정 가져오기 및 내보내기를 선택합니다. 자세한 내용은 Visual Studio 설정을 참조하십시오.

바로 가기 메뉴에 추가 기능 명령을 추가하려면

  1. 파일 메뉴에서 새로 만들기를 가리킨 다음 프로젝트를 클릭합니다.

  2. 새 프로젝트 대화 상자에서 기타 프로젝트 형식을 확장하고 확장성을 클릭한 다음 템플릿 창에서 Visual Studio 추가 기능을 클릭합니다.

    추가 기능의 이름을 ContextCmd로 지정하고 확인을 클릭하여 Visual Studio 추가 기능 마법사를 시작합니다.

  3. 추가 기능에 사용할 명령 모음 UI를 만드시겠습니까? 상자를 선택하여 추가 기능에 대해 UI(사용자 인터페이스)를 만들기 위한 옵션을 선택합니다.

    이렇게 하면 OnConnection 메서드에 일부 UI 코드가 추가됩니다. 또한 사용자가 추가 기능 명령을 클릭할 때 이벤트를 처리하는 Exec 메서드 및 추가 기능의 상태 정보를 제공하는 QueryStatus 메서드가 추가됩니다.

  4. 코드를 아래와 같이 바꿉니다.

    Imports System
    Imports Microsoft.VisualStudio.CommandBars
    Imports Extensibility
    Imports EnvDTE
    Imports EnvDTE80
    
    Public Class Connect
    
        Implements IDTExtensibility2
        Implements IDTCommandTarget
    
        Dim _applicationObject As DTE2
        Dim _addInInstance As AddIn
    
        Dim cmdBarCtl As CommandBarControl
    
        Public Sub New()
        End Sub
    
        Public Sub OnConnection(ByVal application As Object, ByVal _
          connectMode As ext_ConnectMode, ByVal addInInst As Object, _
          ByRef custom As Array) Implements _
          IDTExtensibility2.OnConnection
            Dim cmd As Command
            Dim cmdBar As CommandBar
    
            _applicationObject = CType(application, DTE2)
            _addInInstance = CType(addInInst, AddIn)
    
            Try
                If CType(ext_ConnectMode.ext_cm_AfterStartup Or _
                  ext_ConnectMode.ext_cm_Startup, Boolean) Then
                    ' If the command does not exist, add it.
                    If cmd Is Nothing Then
                        cmd = _applicationObject.Commands. _
                          AddNamedCommand(_addInInstance, _
                          "newCmd", "newCmd", "Runs the add-in.", _
                          True, 59, Nothing, _
                          vsCommandStatus.vsCommandStatusSupported _
                          Or vsCommandStatus.vsCommandStatusEnabled)
                    End If
    
                    ' Reference the Task List shortcut menu.
                    cmdBar = CType(_applicationObject. _
                      CommandBars.Item("Task List"), _
                      Microsoft.VisualStudio.CommandBars.CommandBar)
    
                    ' Add a command to the Task List's shortcut menu.
                    cmdBarCtl = CType(cmd.AddControl(cmdBar, _
                      cmdBar.Controls.Count + 1), _
                      Microsoft.VisualStudio.CommandBars. _
                      CommandBarControl)
                    cmdBarCtl.Caption = "A New Command"
                End If
            Catch e As System.Exception
                System.Windows.Forms.MessageBox.Show(e.ToString)
            End Try
        End Sub
    
        Public Sub OnDisconnection(ByVal disconnectMode As _
          ext_DisconnectMode, ByRef custom As Array) Implements _
          IDTExtensibility2.OnDisconnection
            Try
                ' Delete the command bar control from the 
                   ' shortcut menu.
                If Not (cmdBarCtl Is Nothing) Then
                    cmdBarCtl.Delete()
                End If
            Catch e As System.Exception
                System.Windows.Forms.MessageBox.Show(e.ToString)
            End Try
        End Sub
    
        Public Sub OnAddInsUpdate(ByRef custom As Array) Implements _
          IDTExtensibility2.OnAddInsUpdate
        End Sub
    
        Public Sub OnStartupComplete(ByRef custom As Array) Implements _
          IDTExtensibility2.OnStartupComplete
        End Sub
    
        Public Sub OnBeginShutdown(ByRef custom As Array) Implements _
          IDTExtensibility2.OnBeginShutdown
        End Sub
    
        Public Sub QueryStatus(ByVal commandName As String, ByVal _
          neededText As vsCommandStatusTextWanted, ByRef status As _
          vsCommandStatus, ByRef commandText As Object) Implements _
          IDTCommandTarget.QueryStatus
            If commandName = "ContextCmd.Connect.newCmd" Then
                status = CType(vsCommandStatus.vsCommandStatusEnabled _
                  + vsCommandStatus.vsCommandStatusSupported, _
                  vsCommandStatus)
            Else
                status = vsCommandStatus.vsCommandStatusUnsupported
            End If
        End Sub
    
        Public Sub Exec(ByVal commandName As String, ByVal _
          executeOption As vsCommandExecOption, ByRef varIn As _
          Object, ByRef varOut As Object, ByRef handled As Boolean) _
          Implements IDTCommandTarget.Exec
            handled = False
            If executeOption = vsCommandExecOption. _
              vsCommandExecOptionDoDefault Then
                If commandName = "ContextCmd.Connect.newCmd" Then
                    handled = True
                    System.Windows.Forms.MessageBox.Show("Add-in _
                      running...")
                End If
            End If
        End Sub
    End Class
    
  5. Exec 절차에서 명령을 클릭할 때 실행할 코드를 추가합니다.

  6. 추가 기능을 빌드한 다음 실행합니다.

  7. 보기 메뉴에서 작업 목록을 클릭하여 작업 목록을 표시합니다.

  8. 도구 메뉴에서 추가 기능 관리자를 클릭합니다.

  9. 추가 기능 관리자에서 ContextCmd 추가 기능 옆에 있는 상자를 선택하여 이 추가 기능을 활성화합니다.

  10. 작업 목록을 마우스 오른쪽 단추로 클릭합니다.

    바로 가기 메뉴에 ContextCmd 추가 기능 명령이 나타납니다.

참고 항목

작업

방법: 추가 기능 관리자를 사용하여 추가 기능 제어

방법: 추가 기능 만들기

연습: 마법사 만들기

개념

도구 모음 및 메뉴에 추가 기능 표시

추가 기능 등록

자동화 개체 모델 차트

참조

Visual Studio 명령 및 스위치

기타 리소스

추가 기능 및 마법사 만들기