// stdafx.h : 标准系统包含文件的包含文件,
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的
#include <atlbase.h>
#include <atlstr.h>
#include "stdafx.h"
#include <windows.h>
#include <comdef.h>
#include <objbase.h>
#include <wininet.h>
#include <shlobj.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
WCHAR wszWallpaper[MAX_PATH];
CString strPath;
HRESULT hr;
IActiveDesktop* pIAd;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pIAd);
if (SUCCEEDED(hr)){
hr = pIAd->GetWallpaper(wszWallpaper, MAX_PATH, AD_GETWP_LAST_APPLIED);
if (SUCCEEDED(hr)){
std::wcout << _T("Wallpaper path is:
")<< wszWallpaper << std::endl;
}
else
{
std::wcout << _T("GetWallpaper() Failed.") << std::endl;;
}
pIAd->Release();
}
else
{
std::wcout << _T("CoCreateInstance() failed.") << std::endl;
}
CoUninitialize();
return 0;
}