如何检测 Aero Peek 模式是否开启

发布于 2024-10-24 12:33:51 字数 227 浏览 6 评论 0原文

I'm trying to find out how to detect if windows desktop Aero Peek mode is on. In particular I'm need to detect if my window content is shown or drawn as a frame with transparent background. I know I can exclude my window from Aero Peek, but this not what I need at this moment.

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我偏爱纯白色 2024-10-31 12:34:23

如果您从 Windows 注册表中读取信息,您可以在那里找到 Aero Peek 的状态

\HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM

是一个名为 EnableAeroPeek 的 DWORD 值,设置如下:

1 = 已启用
0 = 禁用

只需比较 0 或 1 即可确定 AeroPeek 是否已打开。

在 C# 中,类似这样:

Using Microsoft.Win32;

...

RegistryKey AeroPeek = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\DWM", true);
       if ((int)AeroPeek.GetValue("EnableAeroPeek") == 1)
        {
            MessageBox.Show("Aero Peek is ON");
        }
        else MessageBox.Show("Aero Peek is OFF");

您还可以更改这些值,Aero Peek 状态将立即更改。

If you read from windows Registry, there you can find the status of Aero Peek

\HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM

Is a DWORD value named EnableAeroPeek which is set as following:

1 = Enabled
0 = disabled

Just compare to 0 or 1 to find out if AeroPeek is on.

In C# something like this:

Using Microsoft.Win32;

...

RegistryKey AeroPeek = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\DWM", true);
       if ((int)AeroPeek.GetValue("EnableAeroPeek") == 1)
        {
            MessageBox.Show("Aero Peek is ON");
        }
        else MessageBox.Show("Aero Peek is OFF");

You can also change those values and instantly Aero Peek status will change.

蓝戈者 2024-10-31 12:34:22

这就是你所追求的吗?

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern bool DwmIsCompositionEnabled();

    public bool IsAeroActive()
    {
        // Check if Aero is enabled;
        if (DwmIsCompositionEnabled())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        bool aeroEnabled = IsAeroActive();

        if (aeroEnabled)
        {
            MessageBox.Show("Aero is enabled.");
        }
        else
        {
            MessageBox.Show("Aero is disabled.");
        }
    }

Is this what you are after?

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern bool DwmIsCompositionEnabled();

    public bool IsAeroActive()
    {
        // Check if Aero is enabled;
        if (DwmIsCompositionEnabled())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        bool aeroEnabled = IsAeroActive();

        if (aeroEnabled)
        {
            MessageBox.Show("Aero is enabled.");
        }
        else
        {
            MessageBox.Show("Aero is disabled.");
        }
    }
嗳卜坏 2024-10-31 12:34:22

当用户通过将鼠标悬停在任务栏图标上窥视窗口时,您的桌面将进入“Aero Peek”模式。您可以使用 Windows 事件挂钩跟踪是否显示“任务切换器”对象,结合其上的 DWM 模式应该告诉您用户是否正在查看窗口。下面是我为测试这个想法而制作的一个应用程序(C++,如果将其转换为 C# 时出现问题,请告诉我)。

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <objbase.h>
#include <Oleacc.h>
#include <iostream>

#define THREAD_MESSAGE_EXIT     WM_USER + 2000

HWINEVENTHOOK eventHook;
HWND taskSwitcherHwnd = 0;

// process event
void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 
                             LONG idObject, LONG idChild, 
                             DWORD dwEventThread, DWORD dwmsEventTime)
{
    if (event == EVENT_OBJECT_SHOW) 
    {
        IAccessible* pAcc = NULL;
        VARIANT varChild;       
        HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);  
        if (hr == S_OK && pAcc != NULL)
        {
            BSTR accName;
            pAcc->get_accName(varChild, &accName);
            if (wcscmp(accName, L"Task Switcher")==0)
            {
                std::cout << "Aero Peek on\n";
                taskSwitcherHwnd = hwnd;
            }
            SysFreeString(accName);
            pAcc->Release();
        }
    }
    else if (event == EVENT_OBJECT_HIDE && taskSwitcherHwnd!=0 && taskSwitcherHwnd==hwnd)
    {
        std::cout << "Aero Peek off\n";
        taskSwitcherHwnd = 0;
    }
}

// thread proc for messages processing
// needed for event's hook to work
DWORD WINAPI TreadProc(LPVOID n)
{
    std::cout << "InitializeEventHook\n";
    CoInitialize(NULL);
    eventHook = SetWinEventHook(
        EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE,   
        NULL, HandleWinEvent, 0, 0, 
        WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);   

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.message==THREAD_MESSAGE_EXIT) 
        {
            break;
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    std::cout << "ShutdownEventHook\n";
    UnhookWinEvent(eventHook);
    CoUninitialize();
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "Detect Aero Peek\n";

    DWORD threadId;
    int value = 0;
    HANDLE hThread = CreateThread( NULL, 0, TreadProc, &value, 0, &threadId);

    char a;
    std::cin >> a;

    PostThreadMessage(threadId, THREAD_MESSAGE_EXIT, 0, 0);
    WaitForSingleObject(hThread, 10000);
    CloseHandle(hThread);

    return 0;
}

希望这有帮助,问候

your desktop would go into this "Aero Peek" mode when user is peeking windows by hovering mouse over taskbar icons. You can use windows event hook to trace if "Task Switcher" object is shown, combined with DWM mode on it should tell you if user is peeking a window. Below is an application I made to test this idea (c++, let me know if there are problems converting it to c#).

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <objbase.h>
#include <Oleacc.h>
#include <iostream>

#define THREAD_MESSAGE_EXIT     WM_USER + 2000

HWINEVENTHOOK eventHook;
HWND taskSwitcherHwnd = 0;

// process event
void CALLBACK HandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 
                             LONG idObject, LONG idChild, 
                             DWORD dwEventThread, DWORD dwmsEventTime)
{
    if (event == EVENT_OBJECT_SHOW) 
    {
        IAccessible* pAcc = NULL;
        VARIANT varChild;       
        HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);  
        if (hr == S_OK && pAcc != NULL)
        {
            BSTR accName;
            pAcc->get_accName(varChild, &accName);
            if (wcscmp(accName, L"Task Switcher")==0)
            {
                std::cout << "Aero Peek on\n";
                taskSwitcherHwnd = hwnd;
            }
            SysFreeString(accName);
            pAcc->Release();
        }
    }
    else if (event == EVENT_OBJECT_HIDE && taskSwitcherHwnd!=0 && taskSwitcherHwnd==hwnd)
    {
        std::cout << "Aero Peek off\n";
        taskSwitcherHwnd = 0;
    }
}

// thread proc for messages processing
// needed for event's hook to work
DWORD WINAPI TreadProc(LPVOID n)
{
    std::cout << "InitializeEventHook\n";
    CoInitialize(NULL);
    eventHook = SetWinEventHook(
        EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE,   
        NULL, HandleWinEvent, 0, 0, 
        WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);   

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.message==THREAD_MESSAGE_EXIT) 
        {
            break;
        }
        else
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    std::cout << "ShutdownEventHook\n";
    UnhookWinEvent(eventHook);
    CoUninitialize();
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "Detect Aero Peek\n";

    DWORD threadId;
    int value = 0;
    HANDLE hThread = CreateThread( NULL, 0, TreadProc, &value, 0, &threadId);

    char a;
    std::cin >> a;

    PostThreadMessage(threadId, THREAD_MESSAGE_EXIT, 0, 0);
    WaitForSingleObject(hThread, 10000);
    CloseHandle(hThread);

    return 0;
}

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文