2

我正在尝试使用此处描述的步骤在我的 VSProject 中打开一个新文档(我正在创建的文档):

但是我没有取得太大的成功 - 上面的链接告诉我应该调用IVsUIShell.CreateDocumentWindow但是我得到-2147024809( FFFFFFFF80070057) 的返回值并且输出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我认为这意味着未找到该文档。itemId这绝对是uint.MaxValue一个坏信号 - 在调用之前我是否需要在运行的文档表中创建一个条目CreateDocumentWindow?如果是这样,我该怎么做?

任何涵盖上述内容的示例或样本都会非常有帮助。

4

1 回答 1

2

我终于在 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();
}
于 2011-03-21T08:09:53.433 回答