如何:開啟專案特定的編輯器How to: Open project-specific editors

如果專案開啟的專案檔本質上系結至該專案的特定編輯器,則專案必須使用專案特定的編輯器來開啟檔案。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. 無法將檔案委派給 IDE 用來選取編輯器的機制。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.

IDE 在判斷檔案 OpenItem 應該由特定專案開啟時,會呼叫方法。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. 使用下列指導方針來執行 OpenItem 方法,讓您的專案使用專案特定的編輯器來開啟檔案。Use the following guidelines to implement the OpenItem method to have your project open a file by using a project-specific editor.

若要使用專案特定的編輯器來執行 OpenItem 方法To implement the OpenItem method with a project-specific editor

  1. 呼叫 FindAndLockDocument 方法 (RDT_EditLock) ,以判斷檔 (檔資料物件) 是否已開啟。Call the FindAndLockDocument method (RDT_EditLock) to determine whether the file (document data object) is already open.

    注意

    如需檔資料和檔視圖物件的詳細資訊,請參閱 自訂編輯器中的檔資料和檔查看For more information about document data and document view objects, see Document data and document view in custom editors.

  2. 如果檔案已開啟,請呼叫 IsDocumentOpen 方法並指定參數的 IDO_ActivateIfOpen 值,以 resurface 檔案 grfIDOIf 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. 呼叫 QueryService SLocalRegistry 服務以取得介面的指標 ILocalRegistry2Call QueryService on the SLocalRegistry service to get a pointer to the ILocalRegistry2 interface.

    2. 呼叫 CreateInstance 方法來建立檔視圖類別的實例。Call the CreateInstance method to create an instance of the document view class.

  4. 呼叫 CreateDocumentWindow 方法,並指定您的檔視圖物件。Call the CreateDocumentWindow method, specifying your document view object.

    這個方法會在文件視窗中,以檔視圖物件為網站。This method sites the document view object in a document window.

  5. 對或方法執行適當的呼叫 InitNew LoadPerform 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. 呼叫 Show 方法以顯示並開啟此視圖。Call the Show method to show and open the view.

另請參閱See also