Chinaunix首页 | 论坛 | 博客
  • 博客访问: 368471
  • 博文数量: 715
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:46
文章分类

全部博文(715)

文章存档

2011年(1)

2008年(714)

我的朋友

分类:

2008-10-13 16:31:43

如何在Tool window中使用VS.NETCore Editor

       在做VSIP编程的时候,我们会经常建立一些自己的tool window。但是并没有相关方档说明如果在tool window中使用core editor及相应的language service。其实要做到这点还是很简单的。可以将CodeWindow作为WindowPane同级来看,将CodeWindow建立在Tool window中,并hook上相应的language service。做到下面简单几步即可(代码仅为提示性片断)

1、  创建CodeWindow

// Create a std code view (text)

hr = _VxModule.QueryService(

            SID_SLocalRegistry, IID_ILocalRegistry,

            (void **)&srpLocalRegistry);

if(FAILED(hr)) return hr;

hr = srpLocalRegistry->CreateInstance(

            CLSID_VsCodeWindow, NULL, IID_IVsCodeWindow,

            CLSCTX_INPROC_SERVER,

            (void **)&srpCodeWin );

if(FAILED(hr)) return hr;

IfFailRet(srpLocalRegistry->CreateInstance(CLSID_VsTextBuffer, NULL, IID_IVsTextLines, CLSCTX_INPROC_SERVER, (LPVOID*)&srpTextLines));

IfFailRet(srpTextLines->InitializeContent(csText, csText.GetLength()));

IfFailRet(srpCodeWin->SetBuffer(srpTextLines));

IfFailRet(srpCodeWin->SetViewClassID(CLSID_VsTextView));

BSTR    bstrCaption = SysAllocString(_T("[Code]"));

hr = srpCodeWin->SetBaseEditorCaption((LPCOLESTR*)&bstrCaption);

if(FAILED(hr)) return hr;

SysFreeString(bstrCaption);

// Set site of textbuffer, and therefore set language service can work.

CComPtr srpObjWSite;

hr = srpTextLines->QueryInterface( IID_IObjectWithSite, (void **)&srpObjWSite );

if(FAILED(hr))

     return E_FAIL;

hr = srpObjWSite->SetSite( srpEditorSiteSP );

if(FAILED(hr))

     return E_FAIL;

// Set the specific language service for the text buffer

hr = srpTextLines->SetLanguageServiceID(g_languageCLSID); //g_languageCLSID is the language services CLSID

hr = srpCodeWin->SetViewClassID(CLSID_VsTextView);

IfFailRet(hr);

 

2、  建立包含CodeWindowtool window

// Create Tool window using code window build in.

hr = srpVsUIShell->CreateToolWindow(

                                dwCreateToolFlags,

                                0,

                                srpCodeWin,

                                CLSID_NULL,

                                guidToolWindow,

                                GUID_NULL,

                                NULL,

                                csCaption.GetBuffer(),

                                NULL,

                                &srpWindowFrame);

IfFailRet(hr);

//ExpectedExprGo(srpWindowFrame != NULL);   

// Give code window all functions of core editor.

hr = srpWindowFrame->SetGuidProperty(VSFPROPID_InheritKeyBindings, CMDUIGUID_TextEditor);

 


--------------------next---------------------

阅读(323) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~