QT透明窗口和远程桌面

5

我正在创建一个使用QML的Qt/C++应用程序。在Windows下,我想要利用扩展框架到客户区域的半透明窗口,就像在我的窗口类中看到的这个片段。

#ifdef Q_WS_WIN
    if ( QSysInfo::windowsVersion() == QSysInfo::WV_VISTA ||
         QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS7 )
    {
        EnableBlurBehindWidget(this, true);
        ExtendFrameIntoClientArea(this);
    }
#else

代码运行良好,但有一个例外。如果关闭透明窗口系统,则背景变为黑色,并且由于我的UI是透明的,因此它也会变暗。当登录到运行该应用程序的远程计算机时,即使立即重新初始化透明窗口系统,背景也会保持黑色,直到再次执行上述代码。这在此图片中得以证明。
问题在于找到一个信号来连接以重新初始化透明窗口,或者更好地检测窗口是否被透明地绘制并相应地绘制UI。欢迎任何替代方案。
2个回答

2
在深入研究Qt和MSDN Aero文档后,我提出了一个两步解决方案。通过重载我的主窗口的winEvent方法,我能够接收每次半透明窗口系统启用或禁用时触发的信号。
#define WM_DWMCOMPOSITIONCHANGED        0x031E

bool MainWindow::winEvent(MSG *message, long *result) {
    if ( message->message == WM_DWMCOMPOSITIONCHANGED ) {
        // window manager signaled change in composition
        return true;
    }
    return false;
}

这让我接近了答案,但是它并没有告诉我DWM当前是否正在绘制透明窗口。通过使用dwmapi.dll,我找到了一个可以精确实现这一点的方法,可以像下面这样访问:

// QtDwmApi.cpp
extern "C"
{
    typedef HRESULT (WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
}

bool DwmIsCompositionEnabled() {
    HMODULE shell;

    shell = LoadLibrary(L"dwmapi.dll");
    if (shell) {
        BOOL enabled;
        t_DwmIsCompositionEnabled is_composition_enabled = \
              reinterpret_cast<t_DwmIsCompositionEnabled>(
                  GetProcAddress (shell, "DwmIsCompositionEnabled")
                  );
        is_composition_enabled(&enabled);

        FreeLibrary (shell);

        if ( enabled ) {
            return true;
        } else {
            return false;
        }
    }
    return false;
}

我的实现现在能够对Aero的变化做出反应,并相应地绘制GUI。当通过远程桌面登录时,窗口也会在可用时使用透明度进行绘制。


0
The function should be written as follows to avoid the GPA failure

// QtDwmApi.cpp
extern "C"
{
    typedef HRESULT (WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
}

bool DwmIsCompositionEnabled() {
    HMODULE shell;
    BOOL enabled=false;

    shell = LoadLibrary(L"dwmapi.dll");
    if (shell) {
        t_DwmIsCompositionEnabled is_composition_enabled = \
              reinterpret_cast<t_DwmIsCompositionEnabled>(
                  GetProcAddress (shell, "DwmIsCompositionEnabled")
                  );
        if (is_composition_enabled)
            is_composition_enabled(&enabled);

        FreeLibrary (shell);
   }
    return enabled;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接