2011-03-20 98 views
2

我想在這裏使用描述的步驟我VSProject打開一個新的文檔(即我創建一個文件):的Visual Studio 2010 SDK開放項目特定的編輯器

然而,我沒有太大的成功 - 上面的鏈接告訴我,我應該打電話IVsUIShell.CreateDocumentWindow但是我得到的返回值爲-2147024809FFFFFFFF80070057),輸出ppWindowFrame爲空。

我在做什麼錯?有沒有關於如何使用此方法創建新文檔窗口的示例?

這是我到目前爲止有:

int retval = rdt.FindAndLockDocument(
    (uint)_VSRDTFLAGS.RDT_EditLock, // dwRDTLockType 
    myDocumentUniqueIdentifier, // pszMkDocument 
    out hierachy, // ppHier 
    out itemId, // pitemid 
    out docData, // ppunkDocData 
    out cookie); // pdwCookie 

IVsWindowFrame windowFrame; 
Guid emptyGuid = Guid.Empty; 
Guid editorType = new Guid(GuidList.VSPackageEditorFactoryString); 

// I know that the document is not open 
retval = shell.CreateDocumentWindow(
    0, // grfCDW 
    myDocumentUniqueIdentifier, // pszMkDocument 
    (IVsUIHierarchy)hierachy, // pUIH 
    itemId, // itemid 
    IntPtr.Zero, // punkDocView 
    docData, // punkDocData 
    ref editorType, // rguidEditorType 
    "MyPhysicalView", // pszPhysicalView 
    ref emptyGuid, // rguidCmdUI 
    this, // psp 
    "New document", // pszOwnerCaption 
    "New document", // pszEditorCaption 
    null, // pfDefaultPosition 
    out windowFrame); // ppWindowFrame 

FindAndLockDocument的返回值是1S_FALSE),我假設意味着該文件沒有被發現。 itemIduint.MaxValue這絕對是一個不好的跡象 - 我需要在調用CreateDocumentWindow之前在運行的文檔表中創建一個條目嗎?如果是這樣,我該怎麼做?

覆蓋上述地面的任何示例或樣本都會非常有幫助。

回答

1

我終於有這個線程的幫助下在MSDN論壇上管理這個:

我的代碼現在使用IVsUIShellOpenDocument接口和OpenDocumentViaProjectWithSpecific方法 - 下面的代碼片段是基本的,但實際上的作品:

IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)GetService(typeof(IVsUIShellOpenDocument)); 

string mkDocument = "MyUniqueDocumentId"; 

// This is the GUID for the editor factory, i.e. the one that appears in the Guid attribute on your 
// editor factory (that implements IVsEditorFactory): [Guid(GuidList.guid_VSPackageEditorFactory)] 
Guid xmlGuid = GuidList.guid_VSPackageEditorFactory; 

string physicalView = null; 
Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary; 
Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP; 
IVsUIHierarchy ppHier; 
uint pitemid; 
IVsWindowFrame ppWindowFrame; 

shellOpenDocument.OpenDocumentViaProjectWithSpecific(
    mkDocument, 
    (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen, 
    ref xmlGuid, 
    physicalView, 
    ref logicalViewGuid, 
    out ppSP, 
    out ppHier, 
    out pitemid, 
    out ppWindowFrame); 

if (ppWindowFrame != null) 
{ 
    ppWindowFrame.Show(); 
} 
+0

我正在做一個ReSharper風格的MEF智能標籤,我不知道如何打電話進入我的強積金項目系統。您的解決方案完美運作謝謝你,先生! – MickyD 2014-11-04 08:45:03

相關問題