Domanda

Sto cercando di scoprire come rilevare se Windows Desktop Aero Peek La modalità è attiva. In particolare, ho bisogno di rilevare se il contenuto della finestra viene mostrato o disegnato come frame con sfondo trasparente. So di poter escludere la mia finestra da Aero Peek, ma non è quello di cui ho bisogno in questo momento.

Tia

È stato utile?

Soluzione

Il tuo desktop andrebbe in questo "Aero Peek"Modalità quando l'utente è sbirciati Windows spingendo il mouse su icone della barra delle applicazioni. Puoi usare Gancio per eventi di Windows tracciare se "Switcher attività"L'oggetto viene mostrato, combinato con la modalità DWM su di esso dovrebbe dirti se l'utente sta sbirciando una finestra. Di seguito è riportata un'applicazione che ho fatto per testare questa idea (C ++, fammi sapere se ci sono problemi a convertirla in 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;
}

Spero che questo aiuti, saluti

Altri suggerimenti

È questo quello che stai cercando?

    [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.");
        }
    }

Se leggi dal registro di Windows, puoi trovare lo stato di Aero Peek

Hkey_current_user software Microsoft Windows DWM

È un valore dword chiamato Abilitaropeek che è impostato come segue:

1 = Abilitato 0 = disabilitato

Basta confrontare con 0 o 1 per scoprire se Aeropeek è acceso.

In C# qualcosa di simile:

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");

Puoi anche modificare quei valori e lo stato di sbirciatore aerodinamico cambierà.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top