-
January 10th, 2008, 02:16 PM
#1
Change Wallpaper
I am using SystemParametersInfo(SPI_SETDESKWALLPAPER,0,path,SPIF_SENDCHANGE);
to change the desktop in C++.
My question is how to set the wallpaper options Position(Stretched or Centered or Titled)
Last edited by skpskpskp; January 10th, 2008 at 02:20 PM.
-
January 10th, 2008, 02:34 PM
#2
Re: Change Wallpaper
One way:
Code:
USES_CONVERSION; // First line in your function
...
IActiveDesktop *pActiveDesktop = NULL;
HRESULT hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
if (hr == S_OK)
{
WALLPAPEROPT wallpaperopt = {0};
wallpaperopt.dwSize = sizeof(WALLPAPEROPT);
wallpaperopt.dwStyle = WPSTYLE_TILE;
pActiveDesktop->SetWallpaperOptions(&wallpaperopt, NULL);
LPWSTR wstrImg = T2W(pszFile);
pActiveDesktop->SetWallpaper(wstrImg, NULL);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
}
-
January 10th, 2008, 02:45 PM
#3
Re: Change Wallpaper
Thanks,but because i have been learning WinAPI since last week and I understand 90% of your code and if you have time to explain every line and function i will be very grateful
Can you give me some links with more informations about it to read
Last edited by skpskpskp; January 10th, 2008 at 02:55 PM.
-
January 10th, 2008, 03:17 PM
#4
Re: Change Wallpaper
Well, the first line "USES_CONVERSION" is needed because I'm using T2W. See MSDN for the T2W explanation.
Then I get a IActiveDesktop interface using CoCreateInstance. Again, see MSDN for more information on CoCreateInstance.
Once you have your interface, we can start calling functions on it and one of its functions is SetWallpaperOptions which accepts a WALLPAPEROPT structure with information.
Then I use the SetWallpaper function to set the actual wallpaper and use ApplyChanges to instruct Windows to apply the changes and refresh the desktop.
When you're finished with an interface obtained through CoCreateInstance you should call Release on it.
-
February 17th, 2008, 09:57 AM
#5
Re: Change Wallpaper
i couldn't figure out, is including shlobj.h enough for that?
-
February 17th, 2008, 11:46 AM
#6
Re: Change Wallpaper
Yes, you have to include shlobj.h.
Do you have any compilation errors?
-
February 17th, 2008, 12:28 PM
#7
Re: Change Wallpaper
yes i did have some, it said "error C2065: 'IActiveDesktop' : undeclared identifier" for example, but i figured out the problem about SystemParametersInfo, so everythings ok now.
by the way, thank you for your interest in my problem, and your replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|