Thread: SystemParametersInfo

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    1

    SystemParametersInfo

    Hi.

    can anyone please help me find out why this code doesn't work:
    char* nextWpName = "mypic.jpg"
    SystemParametersInfo (SPI_SETDESKWALLPAPER,0,nextWpName,SPIF_UPDATEINIF ILE);

    my wallpaper simply disappears and goes blank.
    help...

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    From msdn:
    ...To specify a wallpaper bitmap, set pvParam to point to a null-terminated string containing the name of a bitmap file....
    So try it with a bitmap and not a jpeg.
    Last edited by Ken Fitlike; 12-28-2002 at 11:53 AM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you wish to use JPEGS or GIFS (as the system does when you change wallpaper manually), you need to roll your sleeves up and use a COM interface - IActiveDesktop

    This code opens a dialog allowing you to shose a BMP,GIF or JPEG......then it sets that as wallpaper and stretches it accross the screen...unfortunately, it is targetted at VC++...if you use a different compiler, come back and I will try again

    Code:
    #include <windows.h>//Essential stuff
    #include <wininet.h>//This has to be here...bug!!!!!!
    #include <shlobj.h>//For IActiveDesktop
    #include <comdef.h>//For neat VC++ COM Classes
    
    
    struct COM_INIT{//To manage COM
    	COM_INIT(){CoInitialize(0);}
    	~COM_INIT(){CoUninitialize();}
    }COM_INIT_;
    
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int){
    	
    	char szFile[MAX_PATH+1] = {0};
    	OPENFILENAME ofn = {sizeof(OPENFILENAME)};
    	ofn.hInstance = GetModuleHandle(0);
    	ofn.lpstrFilter = "BMP\0*.BMP\0JPeg\0*.JPG\0Gif\0*.GIF\0";
    	ofn.lpstrFile = szFile;
    	ofn.nMaxFile = MAX_PATH+1;
    	ofn.lpstrTitle = "Pick Bitmap, JPeg or Gif to replace wallpaper";
    
    	if(!GetOpenFileName(&ofn))return 0;
    
    	try{
    		
    		WALLPAPEROPT wpo = {sizeof(wpo),WPSTYLE_STRETCH};
    		_com_ptr_t<_com_IIID<IActiveDesktop,
    			&__uuidof(IActiveDesktop)> > lpIAD;
    
    		lpIAD.CreateInstance(CLSID_ActiveDesktop);	
    
    		lpIAD->SetWallpaper(_bstr_t(szFile),0);
    
    		lpIAD->SetWallpaperOptions(&wpo,0);
    
    		lpIAD->ApplyChanges(AD_APPLY_ALL);
    
    
    		MessageBox(0,"Wallpaper changed","",MB_OK);
    
    	}
    	catch(_com_error& e){
    		MessageBox(0,(e.Description().length() ? 
    			e.Description() : "COM Error"),0,MB_OK);
    	}
    
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SystemParametersInfo set wallpaper issues
    By A10 in forum Windows Programming
    Replies: 5
    Last Post: 03-14-2008, 07:39 PM