找到了虚拟桌面的一些资料,不过貌似IVirtualDesktop的IID有问题,资料如下:大侠们,请赐教!
#ifndef INCLUDED_VISUALDESKTOPUTIL_H_
#define INCLUDED_VISUALDESKTOPUTIL_H_
//#include "stdafx.h"
#include <objbase.h>
//#include <ObjectArray.h>
#include <iostream>
const CLSID CLSID_ImmersiveShell = {
0xC2F03A33, 0x21F5, 0x47FA, 0xB4, 0xBB, 0x15, 0x63, 0x62, 0xA2, 0xF2, 0x39 };
const IID IID_IServiceProvider = {
0x6D5140C1, 0x7436, 0x11CE, 0x80, 0x34, 0x00, 0xAA, 0x00, 0x60, 0x09, 0xFA };
const CLSID CLSID_VirtualDesktopAPI_Unknown = {
0xC5E0CDCA, 0x7B6E, 0x41B2, 0x9F, 0xC4, 0xD9, 0x39, 0x75, 0xCC, 0x46, 0x7B };
const IID IID_IVirtualDesktopManagerInternal = {
0xAF8DA486, 0x95BB, 0x4460, 0xB3, 0xB7, 0x6E, 0x7A, 0x6B, 0x29, 0x62, 0xB5 };
struct IApplicationView : public IUnknown
{
public:
};
//namespace ABI {
// namespace Windows {
// namespace UI {
// namespace ViewManagement {
//
// MIDL_INTERFACE("D222D519-4361-451E-96C4-60F4F9742DB0")
// IApplicationView : public IInspectable
// {
// public:
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Orientation(
// /* [out][retval] */ __RPC__out ABI::Windows::UI::ViewManagement::ApplicationViewOrientation *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AdjacentToLeftDisplayEdge(
// /* [out][retval] */ __RPC__out boolean *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_AdjacentToRightDisplayEdge(
// /* [out][retval] */ __RPC__out boolean *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsFullScreen(
// /* [out][retval] */ __RPC__out boolean *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsOnLockScreen(
// /* [out][retval] */ __RPC__out boolean *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsScreenCaptureEnabled(
// /* [out][retval] */ __RPC__out boolean *value) = 0;
//
// virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_IsScreenCaptureEnabled(
// /* [in] */ boolean value) = 0;
//
// virtual /* [propput] */ HRESULT STDMETHODCALLTYPE put_Title(
// /* [in] */ __RPC__in HSTRING value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Title(
// /* [out][retval] */ __RPC__deref_out_opt HSTRING *value) = 0;
//
// virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Id(
// /* [out][retval] */ __RPC__out INT32 *value) = 0;
//
// virtual HRESULT STDMETHODCALLTYPE add_Consolidated(
// /* [in] */ __RPC__in_opt __FITypedEventHandler_2_Windows__CUI__CViewManagement__CApplicationView_Windows__CUI__CViewManagement__CApplicationViewConsolidatedEventArgs *handler,
// /* [out][retval] */ __RPC__out EventRegistrationToken *token) = 0;
//
// virtual HRESULT STDMETHODCALLTYPE remove_Consolidated(
// /* [in] */ EventRegistrationToken token) = 0;
//
// };
//
// extern const __declspec(selectany) IID & IID_IApplicationView = __uuidof(IApplicationView);
//
//
// } /* end namespace */
// } /* end namespace */
// } /* end namespace */
// } /* end namespace */
EXTERN_C const IID IID_IVirtualDesktop;
MIDL_INTERFACE("FF72FFDD-BE7E-43FC-9C03-AD81681E88E4")
IVirtualDesktop : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE IsViewVisible(
IApplicationView *pView,
int *pfVisible) = 0;
virtual HRESULT STDMETHODCALLTYPE GetID(
GUID *pGuid) = 0;
};
enum AdjacentDesktop
{
LeftDirection = 3,
RightDirection = 4
};
EXTERN_C const IID IID_IVirtualDesktopManagerInternal;
MIDL_INTERFACE("AF8DA486-95BB-4460-B3B7-6E7A6B2962B5")
IVirtualDesktopManagerInternal : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetCount(
UINT *pCount) = 0;
virtual HRESULT STDMETHODCALLTYPE MoveViewDesktop(
IApplicationView *pView,
IVirtualDesktop *pDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentDesktop(
IVirtualDesktop** desktop) = 0;
/*virtual HRESULT STDMETHODCALLTYPE GetDesktops(
IObjectArray **ppDesktops) = 0;*/
virtual HRESULT STDMETHODCALLTYPE GetAdjacentDesktop(
IVirtualDesktop *pDesktopReference,
AdjacentDesktop uDirection,
IVirtualDesktop **ppAdjacentDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE SwitchDesktop(
IVirtualDesktop *pDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateDesktopW(
IVirtualDesktop **ppNewDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE RemoveDesktop(
IVirtualDesktop *pRemove,
IVirtualDesktop *pFallbackDesktop) = 0;
//10240
virtual HRESULT STDMETHODCALLTYPE CanViewMoveDesktops(
IApplicationView *pView,
int *pfCanViewMoveDesktops) = 0;
virtual HRESULT STDMETHODCALLTYPE FindDesktop(
GUID *desktopId,
IVirtualDesktop **ppDesktop) = 0;
};
EXTERN_C const IID IID_IVirtualDesktopManager;
MIDL_INTERFACE("a5cd92ff-29be-454c-8d04-d82879fb3f1b")
IVirtualDesktopManager : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE IsWindowOnCurrentVirtualDesktop(
/* [in] */ __RPC__in HWND topLevelWindow,
/* [out] */ __RPC__out BOOL *onCurrentDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE GetWindowDesktopId(
/* [in] */ __RPC__in HWND topLevelWindow,
/* [out] */ __RPC__out GUID *desktopId) = 0;
virtual HRESULT STDMETHODCALLTYPE MoveWindowToDesktop(
/* [in] */ __RPC__in HWND topLevelWindow,
/* [in] */ __RPC__in REFGUID desktopId) = 0;
};
EXTERN_C const IID IID_IVirtualDesktopNotification;
MIDL_INTERFACE("C179334C-4295-40D3-BEA1-C654D965605A")
IVirtualDesktopNotification : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE VirtualDesktopCreated(
IVirtualDesktop *pDesktop) = 0;
virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyBegin(
IVirtualDesktop *pDesktopDestroyed,
IVirtualDesktop *pDesktopFallback) = 0;
virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyFailed(
IVirtualDesktop *pDesktopDestroyed,
IVirtualDesktop *pDesktopFallback) = 0;
virtual HRESULT STDMETHODCALLTYPE VirtualDesktopDestroyed(
IVirtualDesktop *pDesktopDestroyed,
IVirtualDesktop *pDesktopFallback) = 0;
virtual HRESULT STDMETHODCALLTYPE ViewVirtualDesktopChanged(
IApplicationView *pView) = 0;
virtual HRESULT STDMETHODCALLTYPE CurrentVirtualDesktopChanged(
IVirtualDesktop *pDesktopOld,
IVirtualDesktop *pDesktopNew) = 0;
};
EXTERN_C const IID IID_IVirtualDesktopNotificationService;
MIDL_INTERFACE("0CD45E71-D927-4F15-8B0A-8FEF525337BF")
IVirtualDesktopNotificationService : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Register(
IVirtualDesktopNotification *pNotification,
DWORD *pdwCookie) = 0;
virtual HRESULT STDMETHODCALLTYPE Unregister(
DWORD dwCookie) = 0;
};
void PrintGuid(const GUID &guid)
{
std::wstring guidStr(40, L'\0');
::StringFromGUID2(guid, const_cast<LPOLESTR>(guidStr.c_str()), guidStr.length());
std::wcout << guidStr.c_str();
}
//HRESULT EnumVirtualDesktops(IVirtualDesktopManagerInternal *pDesktopManager)
//{
// std::wcout << L"<<< EnumDesktops >>>" << std::endl;
//
// IObjectArray *pObjectArray = nullptr;
// HRESULT hr = pDesktopManager->GetDesktops(&pObjectArray);
//
// if (SUCCEEDED(hr))
// {
// UINT count;
// hr = pObjectArray->GetCount(&count);
//
// if (SUCCEEDED(hr))
// {
// std::wcout << L"Count: " << count << std::endl;
//
// for (UINT i = 0; i < count; i++)
// {
// IVirtualDesktop *pDesktop = nullptr;
//
// if (FAILED(pObjectArray->GetAt(i, __uuidof(IVirtualDesktop), (void**)&pDesktop)))
// continue;
//
// GUID id = { 0 };
// if (SUCCEEDED(pDesktop->GetID(&id)))
// {
// std::wcout << L"\t #" << i << L": ";
// PrintGuid(id);
// std::wcout << std::endl;
// }
//
// pDesktop->Release();
// }
// }
//
// pObjectArray->Release();
// }
//
// std::wcout << std::endl;
// return hr;
//}
HRESULT GetCurrentVirtualDesktop(IVirtualDesktopManagerInternal *pDesktopManager, GUID *id)
{
IVirtualDesktop *pDesktop = NULL;
HRESULT hr = pDesktopManager->GetCurrentDesktop(&pDesktop);
if (SUCCEEDED(hr))
{
GUID desktopId = { 0 };
hr = pDesktop->GetID(&desktopId);
if( SUCCEEDED(hr) )
{
id = &desktopId;
}
pDesktop->Release();
}
return hr;
}
HRESULT EnumAdjacentDesktops(IVirtualDesktopManagerInternal *pDesktopManager)
{
std::wcout << L"<<< EnumAdjacentDesktops >>>" << std::endl;
IVirtualDesktop *pDesktop = NULL;
HRESULT hr = pDesktopManager->GetCurrentDesktop(&pDesktop);
if (SUCCEEDED(hr))
{
GUID id = { 0 };
IVirtualDesktop *pAdjacentDesktop = NULL;
hr = pDesktopManager->GetAdjacentDesktop(pDesktop, AdjacentDesktop::LeftDirection, &pAdjacentDesktop);
std::wcout << L"At left direction: ";
if (SUCCEEDED(hr))
{
if (SUCCEEDED(pAdjacentDesktop->GetID(&id)))
PrintGuid(id);
pAdjacentDesktop->Release();
}
else
std::wcout << L"NULL";
std::wcout << std::endl;
pAdjacentDesktop = NULL;
hr = pDesktopManager->GetAdjacentDesktop(pDesktop, AdjacentDesktop::RightDirection, &pAdjacentDesktop);
std::wcout << L"At right direction: ";
if (SUCCEEDED(hr))
{
if (SUCCEEDED(pAdjacentDesktop->GetID(&id)))
PrintGuid(id);
pAdjacentDesktop->Release();
}
else
std::wcout << L"NULL";
std::wcout << std::endl;
pDesktop->Release();
}
std::wcout << std::endl;
return hr;
}
HRESULT ManageVirtualDesktops(IVirtualDesktopManagerInternal *pDesktopManager)
{
std::wcout << L"<<< ManageVirtualDesktops >>>" << std::endl;
std::wcout << L"Sleep period: 2000 ms" << std::endl;
::Sleep(2000);
IVirtualDesktop *pDesktop = NULL;
HRESULT hr = pDesktopManager->GetCurrentDesktop(&pDesktop);
if (FAILED(hr))
{
std::wcout << L"\tFAILED can't get current desktop" << std::endl;
return hr;
}
std::wcout << L"Creating desktop..." << std::endl;
IVirtualDesktop *pNewDesktop = NULL;
hr = pDesktopManager->CreateDesktopW(&pNewDesktop);
if (SUCCEEDED(hr))
{
GUID id;
hr = pNewDesktop->GetID(&id);
if (FAILED(hr))
{
std::wcout << L"\tFAILED GetID" << std::endl;
pNewDesktop->Release();
return hr;
}
std::wcout << L"\t";
PrintGuid(id);
std::wcout << std::endl;
std::wcout << L"Switching to desktop..." << std::endl;
hr = pDesktopManager->SwitchDesktop(pNewDesktop);
if (FAILED(hr))
{
std::wcout << L"\tFAILED SwitchDesktop" << std::endl;
pNewDesktop->Release();
return hr;
}
::Sleep(2000);
std::wcout << L"Removing desktop..." << std::endl;
if (SUCCEEDED(hr))
{
hr = pDesktopManager->RemoveDesktop(pNewDesktop, pDesktop);
pDesktop->Release();
if (FAILED(hr))
{
std::wcout << L"\tFAILED RemoveDesktop" << std::endl;
pNewDesktop->Release();
return hr;
}
}
}
return hr;
}
/*
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IServiceProvider* pServiceProvider = nullptr;
HRESULT hr = ::CoCreateInstance(
CLSID_ImmersiveShell, NULL, CLSCTX_LOCAL_SERVER,
__uuidof(IServiceProvider), (PVOID*)&pServiceProvider);
if (SUCCEEDED(hr))
{
IVirtualDesktopManagerInternal* pDesktopManagerInternal = nullptr;
hr = pServiceProvider->QueryService(CLSID_VirtualDesktopAPI_Unknown, &pDesktopManagerInternal);
if (SUCCEEDED(hr))
{
EnumVirtualDesktops(pDesktopManagerInternal);
GetCurrentVirtualDesktop(pDesktopManagerInternal);
EnumAdjacentDesktops(pDesktopManagerInternal);
ManageVirtualDesktops(pDesktopManagerInternal);
pDesktopManagerInternal->Release();
pDesktopManagerInternal = nullptr;
}
std::wcout << L"<<< Desktop for current window >>>" << std::endl;
IVirtualDesktopManager *pDesktopManager = nullptr;
hr = pServiceProvider->QueryService(__uuidof(IVirtualDesktopManager), &pDesktopManager);
if (SUCCEEDED(hr))
{
GUID desktopId = { 0 };
hr = pDesktopManager->GetWindowDesktopId(GetConsoleWindow(), &desktopId);
if (SUCCEEDED(hr))
{
std::wcout << L"\t";
PrintGuid(desktopId);
std::wcout << std::endl;
}
pDesktopManager->Release();
pDesktopManager = nullptr;
std::wcout << std::endl;
}
pServiceProvider->Release();
}
std::wcout << L"End. Press enter to end...";
std::wcin.get();
return 0;
}
*/
HRESULT moveWindowToCurrentVirtualDesktop(HWND hwndMoved, HWND hwndSrc)
{
::CoInitialize(NULL);
IServiceProvider* pServiceProvider = NULL;
HRESULT hr = ::CoCreateInstance(
CLSID_ImmersiveShell, NULL, CLSCTX_LOCAL_SERVER,
__uuidof(IServiceProvider), (PVOID*)&pServiceProvider);
GUID desktopId = { 0 };
if (SUCCEEDED(hr))
{
IVirtualDesktopManagerInternal* pDesktopManagerInternal = NULL;
hr = pServiceProvider->QueryService(CLSID_VirtualDesktopAPI_Unknown, &pDesktopManagerInternal);
if (SUCCEEDED(hr))
{
IVirtualDesktop *pDesktop = NULL;
IVirtualDesktop *pAdjacentDesktop = NULL;
//hr = pDesktopManagerInternal->GetCurrentDesktop(&pDesktop);
UINT pCount = 0;
pDesktopManagerInternal->GetCount( &pCount);
if (SUCCEEDED(hr))
{
//hr = pDesktop->GetID(&desktopId);
if (SUCCEEDED(hr))
{
IVirtualDesktopManager *pDesktopManager = NULL;
hr = pServiceProvider->QueryService(__uuidof(IVirtualDesktopManager), &pDesktopManager);
if (SUCCEEDED(hr))
{
pDesktopManager->GetWindowDesktopId(hwndSrc, &desktopId);
//pDesktopManagerInternal->FindDesktop(&desktopId, &pDesktop);
//pDesktopManagerInternal->GetAdjacentDesktop(pDesktop, AdjacentDesktop::RightDirection, &pAdjacentDesktop);
//pAdjacentDesktop->GetID(&desktopId);
hr = pDesktopManager->MoveWindowToDesktop( hwndMoved, desktopId );
pDesktopManager->Release();
pDesktopManager = NULL;
}
}
//pDesktop->Release();
}
pDesktopManagerInternal->Release();
pDesktopManagerInternal = NULL;
}
pServiceProvider->Release();
}
return hr;
}
BOOL isWindowOnCurrentVirtualDesktop(HWND hwnd)
{
BOOL bOnCurVirtualDesktop = 0;
::CoInitialize(NULL);
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))
{
hr = pDesktopManager->IsWindowOnCurrentVirtualDesktop( hwnd, &bOnCurVirtualDesktop );
if (SUCCEEDED(hr))
bOnCurVirtualDesktop = 1;
pDesktopManager->Release();
pDesktopManager = NULL;
}
pServiceProvider->Release();
}
return bOnCurVirtualDesktop;
}
#endif //