[2.0] Reset Desktop Wallpaper?
Hello!
I am currently working on a "wallpaper changer". I am trying to add a feature that'll let you reset the wallpaper
to its original state after closing the application if a checkBox has is checked or not.
My current problem is that if the default background is not an image, but a selected colour instead, my code will not work properly. I haven't figured out when it works and when it doesn't. Sometimes it just does, and others it doesn't.
I have tried to read the registry key of "Wallpaper" in current_user at "Control Panel\Desktop" and then assign the value to a string which will be assigned to the "OriginalImage" at startup.
When the program ends, it should check whether the checkBox is checked or not, if it is, then it should reset the key "Wallpaper" to it's original value (taken from "OriginalImage") and then call SystemParametersInfo() to update the desktop with the old wallpaper...
Anyway, here is my code if anyone feel like taking a look at it:
frmMain.cs: http://monoport.com/5884
frmMain.Designer.cs: http://monoport.com/5886
WallpaperChangerEngine.cs: http://monoport.com/5885
(Could use more comments and it's a bit of.. unproper code usage as well, I guess)
Thank you!
Re: [2.0] Reset Desktop Wallpaper?
If the Value of Wallpaper is nothing or null or not set, whatever you say, then it usually means that some color is set.
Read this value from Background in HKEY_CURRENT_USER\Control Panel\Colors registry entry.
Hope it helps you
Re: [2.0] Reset Desktop Wallpaper?
Ah, thank you for your reply Harsh Gupta!
Are you suggesting that if Wallpaper is set to null I should store the colour of the background instead and then reset Wallpaper to null after my application has finished its work, and then reset the Background color to its default value as well (if it's been in use) upon closing the application?
Cheers,
Zolomon
Re: [2.0] Reset Desktop Wallpaper?
Re: [2.0] Reset Desktop Wallpaper?
Ah, thank you! I'll immediately try this then. ^^
Re: [2.0] Reset Desktop Wallpaper?
Seems like I have come across another problem.
The desktop won't update if I use SystemParametersInfo() and set the path string to null which would then force the desktop to use colors.
Any suggestions?
Re: [2.0] Reset Desktop Wallpaper?
Sorry, my bad!!! You don't need to capture the background color. If you reset the wallpaper to nothing (just pass empty string instead of file path). Since desktop's background color is always set to whatever it is, it means that system just resets the wallpaper to null string.
You don't need to set background color manually, just reset the wallpaper and system will do it for you.
Re: [2.0] Reset Desktop Wallpaper?
Ah, okay, thanks!
Just to clarify again what it is I want to do, mostly for my own sake, I'll write it again in pseudo:
At start:
Check if registry key OriginalImage is set
If true - save path to wallpaper in OriginalImage & set checkBox to checked
If false - save path to wallpaper in OriginalImage (if the checkBox willl be checked in a later stage in runtime)
When checkBox checked state is changed:
If .checked is true - do nothing
If .checked is false - delete OriginalImage registry key
At Exit:
If .checked is true - set Wallpaper key to same value as OriginalImage - call SystemParametersInfo(with the string of OriginalImage);
If .checked is false - delete OriginalImage registry key
That should work, right?