How to use the IVirtualDesktopManager interface in C++/Win32

后端 未结 1 852
挽巷
挽巷 2021-01-23 01:22

I need to search for maximized windows from Win32 (by using EnumWindows) but I also want to filter for windows which are on the current virtual desktop. On MSDN, I

相关标签:
1条回答
  • 2021-01-23 02:15

    IVirtualDesktopManager is a COM interface. You need to instantiate the COM object that implements the interface.

    Based on code from this blog, you can use IServiceProvider to access IVirtualDesktopManager (and IVirtualDesktopManagerInternal, which has much more functionality than IVirtualDesktopManager has), eg:

    IServiceProvider* pServiceProvider = NULL;
    HRESULT hr = ::CoCreateInstance(
        CLSID_ImmersiveShell, NULL, CLSCTX_LOCAL_SERVER,
        __uuidof(IServiceProvider), (PVOID*)&pServiceProvider);
    
    if (SUCCEEDED(hr))
    {
        IVirtualDesktopManager *pDesktopManager = NULL;
        hr = pServiceProvider->QueryService(__uuidof(IVirtualDesktopManager), &pDesktopManager);
    
        if (SUCCEEDED(hr))
        {
            BOOL bIsOnCurrentDesktop = FALSE;
            hr = pDesktopManager->IsWindowOnCurrentVirtualDesktop(hWnd, &bIsOnCurrentDesktop);
    
            if (SUCCEEDED(hr))
            {
                // use bIsOnCurrentDesktop as needed...
            }
    
            pDesktopManager->Release();
        }
    
        pServiceProvider->Release();
    }
    
    0 讨论(0)
提交回复
热议问题