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

Recommended Answers

All 8 Replies

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();
}

37 Errors :P :o

ofcourse..:p

You have to include wininet.h and shlobj.h, then compile the program for UNICODE

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);

I know :p...

-> mark as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.