Hey :D

I wanna make a small program which changes the Desktop Wallpaper.

Ok ehm. I found many things but nothing is working!

Maybe because of my os: Win 7 x64

Ok here is the code which should run when someone click on the button.

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,"C:\\wallpaper.bmp", SPIF_SENDCHANGE);

Tried it with different 4th parameters but nothing works.

Maybe its because of my os as i said above.
Someone now a better function?

// Using Visual C++ Express Edition 2008

Thx!
Daniel

try this..;)

VOID SetWallpaper(TCHAR *szFilename,INT nStyle)
{
	CoInitializeEx(0,COINIT_APARTMENTTHREADED);
	IActiveDesktop* iADesktop;
	HRESULT status = CoCreateInstance(CLSID_ActiveDesktop,NULL,CLSCTX_INPROC_SERVER,IID_IActiveDesktop,(void**)&iADesktop);
	WALLPAPEROPT wOption;
	ZeroMemory(&wOption, sizeof(WALLPAPEROPT));
	wOption.dwSize=sizeof(WALLPAPEROPT);
	switch(nStyle)
	{
	case 0:
		{
			wOption.dwStyle = WPSTYLE_STRETCH;
		}break;
	case 1:
		{
			wOption.dwStyle = WPSTYLE_TILE;
		}break;
	case 2:
		{
			wOption.dwStyle = WPSTYLE_CENTER;
		}break;
	default:
		wOption.dwStyle = WPSTYLE_STRETCH;
	}
	status = iADesktop->SetWallpaper(szFilename,0);
	status = iADesktop->SetWallpaperOptions(&wOption,0);
	status = iADesktop->ApplyChanges(AD_APPLY_ALL);
	iADesktop->Release();
	CoUninitialize();
}

Edited 6 Years Ago by cikara21: n/a

Hey thx :)

btw I got my other code working too :P

... It was a problem with unicode -.-..

SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,"C:\\wallpaper.bmp", SPIF_SENDCHANGE);

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,_T("C:\\wallpaper.bmp"), SPIF_SENDCHANGE);

Tadaaa both working!

tadaa this working too..

SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,L"C:\\wallpaper.bmp", SPIF_SENDCHANGE);

Hey thx :)

btw I got my other code working too :P

... It was a problem with unicode -.-..

SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,"C:\\wallpaper.bmp", SPIF_SENDCHANGE);

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,_T("C:\\wallpaper.bmp"), SPIF_SENDCHANGE);

Tadaaa both working!

Tadaaa -- when compiled for UNICODE those two are identical.

tadaa this working too..

SystemParametersInfoW(SPI_SETDESKWALLPAPER,0,L"C:\\wallpaper.bmp", SPIF_SENDCHANGE);
This question has already been answered. Start a new discussion instead.