Visual Studio 2010 - 半透明浮动窗口 [英] Visual Studio 2010 - Semi-Transparent Floating Windows

查看:60
本文介绍了Visual Studio 2010 - 半透明浮动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Visual Studio 2010 中使浮动窗口半透明?我希望能够浮动编辑器窗口并降低其上的 alpha 级别.能否使用修改股票编辑器窗口的扩展程序创建此功能?

Is it possible to make floating windows in Visual Studio 2010 semi-transparent? I would like to be able to float an editor window and reduce the alpha level on it. Could this functionality be created with an extension that modifies the stock editor window?

如果不是扩展,是否有合适的第三方应用程序能够修改 Visual Studio 2010 中特定子窗口的属性?

If not an extension, are there decent third party applications which would be capable of modifying the properties of specific child windows in Visual Studio 2010?

推荐答案

主要问题是,它取决于工具窗口,因为 Visual Studio 并没有太多关于工具窗口实际呈现方式的规定.

The main the problem is, it depends on the tool window, because Visual Studio does not mandate much about how the tool window is actually rendered.

如果工具窗口有 HNWD 可以玩,您可以使用 SetLayeredWindowAttributes 函数.如果工具窗口是WPF,可以使用其他技巧.

If the tool window has an HNWD to play with, you can set transparency using the SetLayeredWindowAttributes function. If the tool window is WPF, you can use other tricks.

现在,问题是要掌握一些有用的东西...只需在 Visual Studio 2010 上启动 SPY++,您就会看到周围没有多少可见的 HWND.一些包使用非托管代码,一些包使用 .NET + Winforms,而且最近的包越来越多地使用 .NET + WPF.

Now, the problem is to get a hold on something useful... Just launch SPY++ over Visual Studio 2010 and you will see there are not many visible HWND around. Some package use unmanaged code, some packages use .NET + Winforms, and more and more, recent packages use .NET + WPF.

UISpy(另一个间谍工具,但基于 UI 自动化) 看到所有工具窗口,但不显示任何本机窗口句柄(UI 的标准属性之一自动化可以读取)这不是个好消息.

UISpy (another spy tool, but based on UI Automation) sees all tool windows but it does not show any Native WIndow Handle (one of the standard property that UI automation can read) which is not good news.

Visual Studio 使用 IVsWindowPane 界面,特别是 CreatePaneWindow 方法来创建宿主窗口,但没有任何官方可以获取任何 HWND 句柄.

Visual Studio uses the IVsWindowPane interface and specifically the CreatePaneWindow method to create the host window, but there is nothing official to get any HWND handle back to play with.

嗯!如果您有想要调整的特定工具窗口,我们可以深入了解,但我认为编写 100% 通用的工具很难.

Hmm! If you have a specific tool window you want to tweak, we can have a deeper look, but I think it's difficult to write a 100% generic tool.

编辑:我进一步搜索了.这是一个枚举当前 Visual Studio 实例的所有窗口框架(停靠或浮动)的代码:

EDIT: I have searched further more. Here is a code that enumerates all windows frames (docked or floating) of the current Visual Studio instance:

// WindowFrame needs Microsoft.VisualStudio.Platform.WindowManagement.dll
public static IEnumerable<WindowFrame> EnumWindowFrames(Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp, __WindowFrameTypeFlags frameTypes)
{
    if (sp == null)
        throw new ArgumentNullException("sp");

    ServiceProvider serviceProvider = new ServiceProvider(sp);
    IVsUIShell4 shell = (IVsUIShell4)serviceProvider.GetService(typeof(SVsUIShell)); // VS 2010 only

    IEnumWindowFrames framesEnum;
    IVsWindowFrame[] frames = new IVsWindowFrame[1];
    uint numFrames;
    shell.GetWindowEnum((uint)frameTypes, out framesEnum);
    if (framesEnum == null)
        yield break;

    while ((framesEnum.Next(1, frames, out numFrames) == VSConstants.S_OK) && (numFrames == 1))
    {
        WindowFrame frame = frames[0] as WindowFrame;
        if (frame != null)
            yield return frame;
    }
}

这将给出 WindowFrame 实例的列表.WindowFrame 没有记录,但它是公开的(位于 Microsoft.VisualStudio.Platform.WindowManagement.dll 中),因此您可以使用它.每个 WindowFrame 实例都有一个 FrameView 属性,该属性具有一个 Content 属性.大多数情况下,根据我的发现,此 Content 属性是 WPF 的 Panel 元素.该面板下方的层次结构将取决于窗口的实际实现方式.

This will give a list of WindowFrame instances. WindowFrame is not documented but it's public (located in Microsoft.VisualStudio.Platform.WindowManagement.dll) , so you can play with it. Each WindowFrame instance has a FrameView property that has a Content property. This Content property is, most of the time from my findings, a WPF's Panel element. The hierarchy below that panel will then be dependent on how the window is actually implemented.

如果它是非托管或 Winforms(例如,.SQL 编辑器),则面板的子集合中将有一个 HwndHost.我曾尝试使用它(使用 SetLayeredWindowAttributes),但它似乎不起作用...

If it's an unmanaged or Winforms (example, the .SQL editor), there will be an HwndHost in the panel's children collection. I have tried to play with it (using SetLayeredWindowAttributes), but it does not seem to work...

如果它是一个 WPF(例如,全新的 C#/VB 编辑器),将会有一个巨大的 WPF hiearchy,最终会归结为一个 IWfpTextView 实现.您可以在此层次结构中更改许多内容,有些内容会起作用(例如 Background 属性),但是...关于透明度,我认为这是不可能的,因为根窗口不允许这样做(它具有 AllowTransparency 设置为 false,不能显示后更改).例如,设置 Opacity = 0.5 有效,但由于没有透明度,效果只是使窗口变暗...

If it's a WPF (example, the brand new C#/VB editor), there will be a huge WPF hiearchy, that will eventually go down to an IWfpTextView implementation. You can change many things along in this hierarchy, and some will work (such as the Background property), but... concerning the transparency, I don't think it's possible because the root window does not allow it (it has AllowTransparency set to false, and it can't be changed once it's displayed). Setting Opacity = 0.5 for example works, but since there is no transparency, the effect is just dimmed windows...

这篇关于Visual Studio 2010 - 半透明浮动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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