To change desktop wallpaper (when 'activeDesktop' is enabled):
Code:
#include <shlobj.h>
extern const IID IID_IActiveDesktop = {
0xf490eb00,0x1240,0x11d1, {
0x98,0x88,0x00,0x60,0x97,0xde,0xac,0xf9 }
};
extern const IID CLSID_ActiveDesktop = {
0x75048700,0xef1f,0x11d0, {
0x98,0x88,0x00,0x60,0x97,0xDE,0xac,0xf9 }
};
int changeWallpaper(char *strPicPath, DWORD flags)
{
WCHAR tempstr[MAX_PATH];
char str[255]="";
HRESULT hr;
MultiByteToWideChar(CP_ACP, 0, strPicPath, -1, tempstr, sizeof(tempstr) );
IActiveDesktop *pActiveDesktop;
CoInitialize(NULL);
hr = CoCreateInstance(&CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,&IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr == S_OK ) {
hr = pActiveDesktop->SetWallpaper(tempstr, 0);
if(hr!=S_OK) {
return 0;
}
WALLPAPEROPT wpo;
wpo.dwSize = sizeof(WALLPAPEROPT);
wpo.dwStyle = flags;
pActiveDesktop->SetWallpaperOptions(&wpo,0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
CoUninitialize();
return TRUE;
}
else {
return FALSE;
}
}
To use, strPicPath is the path to the image, and flags is either WPSTYLE_CENTER or WPSTYLE_STRETCH. There are more, but I can't remember them for now... You can find them in the docs...
Hope this helps!
Franchie.