Share via


방법: 도구 창 만들기 및 제어

업데이트: 2007년 11월

Visual Studio의 창은 두 가지 범주인 문서 창이나 도구 창 중 하나로 표시됩니다. 문서 창에는 텍스트 파일, HTML 또는 클래스 내의 코드 등과 같이 코드 편집기를 사용하여 편집할 수 있는 내용이 포함됩니다. 도구 창에는 단추, 텍스트, 콤보 상자 등과 같은 하나 이상의 컨트롤이 포함됩니다. Visual Studio IDE(통합 개발 환경)에서는 옵션 설정, 오류 보기, 프로젝트 요소 편집 등의 작업을 수행하는 데 컨트롤을 사용합니다. 출력 창, 작업 목록, 도구 상자 등을 예로 들 수 있습니다. 도구 상자는 IDE에서 자유롭게 위치를 옮길 수 있고 다른 도구 창에 고정할 수도 있습니다. 또한 LinkedWindows 컬렉션을 사용하여 IDE의 도구 창을 프로그래밍 방식으로 연결하거나 연결을 해제할 수 있습니다. 자세한 내용은 방법: 창 특성 변경을 참조하십시오.

자동화를 사용하여 기존의 도구 창을 조작할 수 있을 뿐만 아니라 Windows2 컬렉션의 CreateToolWindow2 메서드를 사용하여 고유한 사용자 지정 도구 창을 만들 수도 있습니다.

참고:

Visual Studio 2005에 새로 도입된 이 메서드는 Visual Studio 2002와 Visual Studio 2003에서 사용되던 CreateToolWindow 메서드를 대신합니다.

고유한 사용자 지정 도구 창을 만들면 작업을 수행하는 데 필요한 유용한 컨트롤을 이 창에 배치할 수 있습니다. 예를 들어, 사용자 지정 도구 창을 사용하여 코드 형식을 지정하는 데 도움이 되는 특별한 도구를 표시하거나, 변수 설정을 추적 및 변경하거나, 고급 디버깅 작업 또는 소스 프로파일링을 수행할 수 있습니다.

사용자 지정 도구 창을 만드는 절차는 다음과 같습니다.

  • Windows 컨트롤 라이브러리 프로젝트를 사용하여 사용자 정의 컨트롤을 만듭니다.

  • 단추, 입력란 등과 같은 필요한 컨트롤을 폼과 코드에 추가합니다.

  • 프로젝트를 DLL로 컴파일합니다.

  • 새 Visual Studio 추가 기능 프로젝트나 Windows 응용 프로그램 프로젝트 등의 다른 프로젝트를 만듭니다.

  • CreateToolWindow2 메서드를 사용하여 새 사용자 정의 컨트롤을 호스팅할 도구 창을 만듭니다.

CreateToolWindow2를 호출하여 새 도구 창을 만들기 전에 사용자 정의 컨트롤(ControlObject)을 추가 기능과 같은 어셈블리로 이동하거나 사용자 정의 컨트롤의 모든 특성을 COM에 완전히 표시되도록 설정해야 합니다. 예를 들어, 프로젝트의 컴파일 옵션에 있는 COM Interop 등록 옵션을 선택합니다. 이렇게 하지 않으면 컨트롤이 제대로 마샬링되지 않고 CreateToolWindow2는 null 값을 반환합니다.

아래에 나와 있는 예제 이외에도 Automation Samples for Visual Studio 웹 사이트에서는 각 언어별 도구 창 샘플과 기타 코드 예제를 추가로 제공합니다.

참고:

도구 창을 표시하지 않은 채 높이, 너비 또는 위치 같이 새 도구 창의 표시 상태를 설정하려고 하면 오류가 발생합니다. 이러한 속성을 설정하려면 먼저 창을 표시해야 합니다.

참고:

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

사용자 지정 도구 창 만들기

다음 예제에서는 Visual Basic 및 Visual C#에서 도구 창을 만드는 방법을 보여 줍니다.

참고:

다음 코드는 추가 기능에서 실행되어야 하며 매크로에서는 실행할 수 없습니다.

사용자 지정 도구 창을 만들려면

  1. Windows 컨트롤 라이브러리 프로젝트를 사용하여 사용자 정의 컨트롤을 만듭니다. 기본 이름인 "WindowsControlLibrary1"을 적용하거나 Windows 컨트롤 라이브러리 프로젝트의 이름과 일치하도록 아래 코드에서 asmPath 매개 변수의 이름을 변경합니다.

    또는 코드에서 기존의 사용자 정의 컨트롤을 참조할 수 있습니다.

  2. 새 추가 기능 프로젝트를 만듭니다.

    자세한 내용은 방법: 추가 기능 만들기를 참조하십시오.

  3. 추가 기능의 OnConnection 메서드를 다음과 같이 바꿉니다.

    Public Sub OnConnection(ByVal application As Object, ByVal _
    connectMode As ext_ConnectMode, ByVal addInInst As Object, _
    ByRef custom As Array) Implements IDTExtensibility2.OnConnection
        Try
            ' ctlProgID - the ProgID for your user control.
            ' asmPath - the path to your user control DLL.
            ' guidStr - a unique GUID for the user control.
            Dim ctlProgID, asmPath, guidStr As String
            ' Variables for the new tool window that will hold
            ' your user control.
            Dim toolWins As EnvDTE80.Windows2
            Dim toolWin As EnvDTE.Window
            Dim objTemp As Object = Nothing
    
            _applicationObject = CType(application, DTE2)
            _addInInstance = CType(addInInst, AddIn)
            ctlProgID = "WindowsControlLibrary2.UserControl1"
            ' Replace the <Path to VS Project> with the path to
            ' the folder where you created the WindowsCotrolLibrary.
            ' Remove the line returns from the path before 
            ' running the add-in.
            asmPath = "<Path to VS Project>\My _
              Documents\Visual Studio 2005\Projects\ _
              WindowsControlLibrary2\WindowsControlLibrary2\_
              bin\Debug\WindowsControlLibrary2.dll"
            guidStr = "{E9C60F2B-F01B-4e3e-A551-C09C62E5F584}"
    
            toolWins = CType(_applicationObject.Windows, Windows2)
            ' Create the new tool window, adding your user control.
            toolWin = toolWins.CreateToolWindow2(_addInInstance, _
              asmPath, ctlProgID, "MyNewToolwindow", guidStr, objTemp)
            ' The tool window must be visible before you do anything 
            ' with it, or you will get an error.
            If Not toolWins Is Nothing Then
                toolWin.Visible = True
            End If
               ' Uncomment the code below to set the new tool window's
               ' height and width, and to close it.
            ' MsgBox("Setting the height to 500 and width to 400...")
            ' toolWin.Height = 500
            ' toolWin.Width = 400
            ' MsgBox("Closing the tool window...")
            ' toolWin.Close(vsSaveChanges.vsSaveChangesNo)
    
        Catch ex As Exception
            MsgBox("Exception: " & ex.ToString)
        End Try
    End Sub
    
    // Before running, add a reference to System.Windows.Forms, 
    // using System.Windows.Forms, to the top of the class.
    public void OnConnection(object application, 
    ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        try
        {
            // ctlProgID - the ProgID for your user control.
            // asmPath - the path to your user control DLL.
            // guidStr - a unique GUID for the user control.
            string ctlProgID, asmPath, guidStr;
            // Variables for the new tool window that will hold
            // your user control.
            EnvDTE80.Windows2 toolWins;
            EnvDTE.Window toolWin;
            object objTemp = null;
    
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            ctlProgID = "WindowsControlLibrary2.UserControl1";
            // Replace the <Path to VS Project> with the path to
            // the folder where you created the WindowsCotrolLibrary.
            // Remove the line returns from the path before 
            // running the add-in.
            asmPath = @"c:\My Documents\Visual Studio 2005\Projects\
              WindowsControlLibrary2\WindowsControlLibrary2\bin\
              Debug\WindowsControlLibrary2.dll";
            guidStr = "{E9C60F2B-F01B-4e3e-A551-C09C62E5F584}";
    
            toolWins = (Windows2)_applicationObject.Windows;
            // Create the new tool window, adding your user control.
            toolWin = toolWins.CreateToolWindow2(_addInInstance, 
              asmPath, ctlProgID, "MyNewToolwindow", guidStr, 
              ref objTemp);
            // The tool window must be visible before you do anything 
            // with it, or you will get an error.
            if (toolWins == null)
            {
                toolWin.Visible = true;
            }
            // Uncomment the code below to set the new tool window's
            // height and width, and to close it.
            // System.Windows.Forms.MessageBox.Show("Setting the height 
            // to 500 and width to 400...");
            // toolWin.Height = 500;
            // toolWin.Width = 400;
            // System.Windows.Forms.MessageBox.Show
            //   ("Closing the tool window...");
            // toolWin.Close(vsSaveChanges.vsSaveChangesNo);
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Exception: " 
              + ex.Message);
        }
    }
    
  4. 프로젝트를 빌드하여 실행합니다.

  5. 도구 메뉴에서 추가 기능 관리자를 클릭하여 추가 기능을 활성화합니다.

위치가 고정되지 않은 새 도구 창이 IDE에 나타납니다. 이 창을 임의의 위치로 옮기거나 다른 도구 창에 연결하여 고정할 수 있습니다.

참고 항목

작업

방법: 창 특성 변경

방법: 추가 기능 만들기

연습: 마법사 만들기

개념

옵션 설정 제어

자동화 개체 모델 차트

기타 리소스

환경 창 만들기 및 제어

추가 기능 및 마법사 만들기

자동화 및 확장성 참조