看了看MSDN里的一个关于IActiveDesktop例子:
// ActiveDesktopTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Objbase.h>
#include <Unknwn.h>
#include <Shlobj.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = NULL;
CoInitialize(NULL);
IActiveDesktop *pActiveDesktop;
//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
WCHAR wszWallpaper [MAX_PATH];
if (SUCCEEDED(hr))
{
pActiveDesktop->GetWallpaper(wszWallpaper, MAX_PATH, 0);
std::wcout << L"Wallpaper path is:\n " << wszWallpaper << std::endl;
}
pActiveDesktop->Release();
CoUninitialize();
return 0;
}
在过程中同样出现了很多人遇到的编译不过的问题, 然后在stdafx.h 头文件里添加:
#include <Windows.h>
#include <wininet.h>
#include <stdio.h>
运行结果: