this is from a project I got from codeproject.com. I illustrates the use of that and other functions
Code:
void CWallpaperQDlg::ChangeWallpaper(int iRandom)
{
USES_CONVERSION;
int iImageNum = 0;
int iPosition = 1;
CString cstrTileWallpaper;
CString cstrWallpaperStyle;
TCHAR szBuf[MAX_PATH];
// Choose then next image in the list, or choose a random image.
if (iRandom == 1)
{
srand((unsigned)time(NULL));
iImageNum = rand()%m_lbQList.GetCount();
iCurrentImage = iImageNum;
}
else
{
iCurrentImage++;
if (iCurrentImage + 1 > m_lbQList.GetCount()) iCurrentImage = 0;
CRegistry::SetRegDWORD("Software\\JasonSoft\\WallpaperQ", "CurrentImage", (DWORD)iCurrentImage);
iImageNum = iCurrentImage;
}
// Get the image path from the registry by the image number.
iPosition = (int)m_lbQList.GetItemData(iImageNum);
m_lbQList.GetText(iImageNum, szBuf);
if (szBuf[0] != '/0')
{
// If Active Desktop is not available, use the SystemParametersInfo function.
if (pIActiveDesktop == NULL)
{
if (iPosition == 0)
{
// Tiled
cstrTileWallpaper = "1";
cstrWallpaperStyle = "1";
}
else if (iPosition == 1)
{
// Center
cstrTileWallpaper = "0";
cstrWallpaperStyle = "1";
}
else
{
// Stretch
cstrTileWallpaper = "0";
cstrWallpaperStyle = "2";
}
// Set registry values for the wallpaper position.
CRegistry::SetRegString("Control Panel\\Desktop", "TileWallpaper", cstrTileWallpaper);
CRegistry::SetRegString("Control Panel\\Desktop", "WallpaperStyle", cstrWallpaperStyle);
// Change the wallpaper.
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)szBuf,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
}
else
{
WALLPAPEROPT wpOptions;
COMPONENTSOPT compOptions;
compOptions.dwSize = sizeof(COMPONENTSOPT);
compOptions.fActiveDesktop = TRUE;
compOptions.fEnableComponents = TRUE;
pIActiveDesktop->SetDesktopItemOptions(&compOptions, 0);
// Set the wallpaper position.
wpOptions.dwSize = sizeof(WALLPAPEROPT);
if (iPosition == 0)
wpOptions.dwStyle = WPSTYLE_TILE;
else if (iPosition == 1)
wpOptions.dwStyle = WPSTYLE_CENTER;
else
wpOptions.dwStyle = WPSTYLE_STRETCH;
pIActiveDesktop->SetWallpaperOptions(&wpOptions, 0);
// Set the wallpaper image.
pIActiveDesktop->SetWallpaper(T2CW(szBuf), 0);
// Apply all changes.
pIActiveDesktop->ApplyChanges(AD_APPLY_ALL);
}
if (iExitAfter == 1) OnExit();
}
}