有可能,这只是一条漫长的曲折之路:
ServiceProvider -> IVsOutputWindow -> GetPane( debugwindow ) -> IVsUserData -> GetData( wpftextviewhost ) -> IWpfTextViewHost -> IWpfTextView -> TextBuffer -> 已更改事件。
假设你有一个IServiceProvider
来自其他地方的 VS(vsix 扩展/不管,全球服务提供商),并且没有任何错误检查,它看起来像这样:
IVsOutputWindow outWindow = ServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid debugPaneGuid = VSConstants.GUID_OutWindowDebugPane;
IVsOutputWindowPane pane;
outWindow.GetPane(ref debugPaneGuid, out pane);
// from here up you'll find in lots of other stackoverflow answers,
// the stuff from here down is interesting to this question
IVsUserData userData = (IVsUserData)pane;
object o;
Guid guidViewHost = DefGuidList.guidIWpfTextViewHost;
userData.GetData(ref guidViewHost, out o);
IWpfTextViewHost viewHost = (IWpfTextViewHost)o;
IWpfTextView textView = viewHost.TextView;
textView.TextBuffer.Changed += YourTextChangedHandlerHere;
每次输出窗口获取更多数据时,都会调用您的文本更改处理程序。你不一定会一行一行地得到它,但你可能更有可能得到你需要自己处理的大块。
在 2010 年的 VS 中,很可能以上某些内容甚至不存在。但现在存在!