Share via


How to: Open project-specific editors

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

If an item file being opened by a project is intrinsically bound to the particular editor for that project, the project must open the file by using a project-specific editor. The file cannot be delegated down to the IDE's mechanism for selecting an editor. For example, instead of using a standard bitmap editor, you can use this project-specific editor option to specify a specific bitmap editor that recognizes information in the file that is unique to your project.

The IDE calls the OpenItem method when it determines that a file should be opened by a specific project. For more information, see Display files by using the Open File command. Use the following guidelines to implement the OpenItem method to have your project open a file by using a project-specific editor.

To implement the OpenItem method with a project-specific editor

  1. Call the FindAndLockDocument method (RDT_EditLock) to determine whether the file (document data object) is already open.

    Note

    For more information about document data and document view objects, see Document data and document view in custom editors.

  2. If the file is already open, resurface the file by calling the IsDocumentOpen method and specifying a value of IDO_ActivateIfOpen for the grfIDO parameter.

    If the file is open and the document is owned by a project other than the calling project, a warning will be displayed to the user that the editor being opened is from another project. The file window is then surfaced.

  3. If your text buffer (document data object) is already open and you want to attach another view to it, you are responsible for hooking up that view. The recommended approach to instantiating a view (document view object) from the project, is as follows:

    1. Call QueryService on the SLocalRegistry service to get a pointer to the ILocalRegistry2 interface.

    2. Call the CreateInstance method to create an instance of the document view class.

  4. Call the CreateDocumentWindow method, specifying your document view object.

    This method sites the document view object in a document window.

  5. Perform the appropriate calls to either the InitNew or the Load methods.

    At this point, the view should be fully initialized and ready to be opened.

  6. Call the Show method to show and open the view.

See also