如何从activewindow获取SOleUndoManager [英] How to get SOleUndoManager from activewindow

查看:50
本文介绍了如何从activewindow获取SOleUndoManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在活动窗口(.cs文件)上获得SOleUndoManager的有效实例,我尝试了不同的方法,但尚未找到如何获取它的方法. 我正在使用VSPackage,并且具有对EnvDTE的引用,对于活动窗口也具有IVsWindowFrame的引用 拜托,您能告诉我向SOleUndoManager获取有效实例的正确方法是什么? 预先非常感谢您, (如果需要更多信息,我可以提供)

Hi, I'm trying to get a valid instance for SOleUndoManager on active window, (.cs file), I have tried different ways but not found yet how to get it I'm working on a VSPackage and have a reference to EnvDTE, also to IVsWindowFrame for active window Please, can you tell me what is the right way to get a valid instance to SOleUndoManager? Thank you very much in advance, (if you need further information I can provide)

推荐答案

耶稣,

您应该通过调用以下方法为给定的IVsWindowFrame检索IServiceProvider.具有VSFPROPID_SPFrame的IVsWindowFrame.GetProperty.然后,您可以构造一个新的ServiceProvider对象,从中应该可以从该对象调用GetService for SOleUndoManager.

例如,我使用了类似的方法在属性浏览器工具窗口上检索ITrackSelection接口:

Hi Jesus,

You should retrieve the IServiceProvider for the given IVsWindowFrame, by calling IVsWindowFrame.GetProperty with VSFPROPID_SPFrame. You can then construct a new ServiceProvider object, from which you should be able to call GetService for SOleUndoManager.

For example, I used something similar to retrieve the ITrackSelection interface on the property browser toolwindow:

 

IVsUIShell vsShell =( )serviceProvider.GetService( typeof )));
Guid guidPropBrowser = 向导 ( .PropertyBrowser);
vsShell.FindToolWindow((
很细 ) .FTW_fForceCreate, ref 输出 frameProperties);
objFrameSP;
frameProperties.GetProperty((
int ) __ VSFPROPID .VSFPROPID_SPFrame, 输出 objFrameSP);
frameSP = (( IOleServiceProvider
)objFrameSP);
ITrackSelection trackSelection = frameSP.GetService( typeof ( STrackSelection
ITrackSelection ; IOleServiceProvider定义为:

使用 IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop. IServiceProvider ;

   IVsUIShell vsShell = (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell));
   Guid guidPropBrowser = new Guid(ToolWindowGuids.PropertyBrowser);
   vsShell.FindToolWindow((
uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref guidPropBrowser, out frameProperties);

   object
objFrameSP;
   frameProperties.GetProperty((
int)__VSFPROPID.VSFPROPID_SPFrame, out
objFrameSP);
   ServiceProvider frameSP = new ServiceProvider((IOleServiceProvider
)objFrameSP);
   ITrackSelection trackSelection = frameSP.GetService(typeof(STrackSelection)) as ITrackSelection;
where IOleServiceProvider is defined with:

   using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;

Sincerely,  


这篇关于如何从activewindow获取SOleUndoManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆