如何在C ++/Win32中使用IVirtualDesktopManager接口 [英] How to use the IVirtualDesktopManager interface in C++/Win32

查看:158
本文介绍了如何在C ++/Win32中使用IVirtualDesktopManager接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Win32中搜索最大化的窗口(通过使用EnumWindows),但我也想过滤当前虚拟桌面上的窗口.在MSDN上,我找到了有关

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 found a page about the IVirtualDesktopManager interface but there seems to be no information on how to use this interface.

IVirtualDesktopManager::IsWindowOnCurrentVirtualDesktop(/*args...*/);

引发以下错误:

非静态成员引用必须相对于特定对象

Non static member reference must be relative to a specific object

VirtualDesktopManager mVirtualDeskManager;
mVirtualDesktopManager.IsWindowOnCurrentVirtualDesktop(/args...*/)

引发此错误:

不允许使用不完整的类型

Incomplete type is not allowed

我只发现了在C#中使用IVirtualDesktopManager接口的解决方案.

I have only found solutions on using the IVirtualDesktopManager interface in C# yet.

推荐答案

IVirtualDesktopManager是COM接口.您需要实例化实现该接口的COM对象.

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

基于此博客中的代码,您可以使用IServiceProvider来访问IVirtualDesktopManager(和IVirtualDesktopManagerInternal,其功能要比IVirtualDesktopManager更多),例如:

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();
}

这篇关于如何在C ++/Win32中使用IVirtualDesktopManager接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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