问题描述
我正在尝试在活动窗口(.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 itI'm working on a VSPackage and have a reference to EnvDTE, also to IVsWindowFrame for active windowPlease, 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)
推荐答案
IVsUIShell vsShell =( IVsUIShell )serviceProvider.GetService( typeof ( SVsUIShell )));
Guid guidPropBrowser = 新 向导 ( ToolWindowGuids .PropertyBrowser);
vsShell.FindToolWindow(( 很细 ) __ VSFINDTOOLWIN .FTW_fForceCreate, ref guidPropBrowser, 输出 frameProperties);
对象 objFrameSP;
frameProperties.GetProperty(( int ) __ VSFPROPID .VSFPROPID_SPFrame, 输出 objFrameSP);
ServiceProvider frameSP = 新 ServiceProvider (( IOleServiceProvider )objFrameSP);
ITrackSelection trackSelection = frameSP.GetService( typeof ( STrackSelection ))) as 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!