Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
New Feature: Community Sites:
Create your own .NET community website and start earning from Google AdSense !
It's Free !
|
A Compact Executable Briefcase Wallpaper
|
A Compact Executable Briefcase Wallpaper This small application that I have made was purely to cater to my own necessity. Since it has a couple of P/Invoke and creating an independant image file from its own embedded assembly, I just thought I would share the codesnippets with other peer developers as well.
The Need 1) I normally prefer my desktop to be adored with my favorite Lord, who also occupies my profile photo in Dotnetspider. Sometimes when I occupy a shared PC (like in an Internet Kiosk of an airport or library), I feel irritated to sit there for long particularly when the wallpaper displays obscene images. I needed a quick tool to restore the desktop to my preference in one click. 2) Once upon a time, I just wanted to play a bit with Windows Forms. This application helped me in that too.
As usual, I am not going to share the entire windows application. I am just trying to outline only the significant utility functions which anyone can use it for their own convenience in their applications.
For Windows Forms developers, the preparatory steps might look bit amateurish. Let me know your feedback on how you would like to go about them.
Preparatory Steps 1) Create a simple Windows Forms application. 2) Add the image to the project and from the properties pane, make it as an 'Embedded Resource'.
Extracting the Embedded Image as a File System Entity
string strStreamName = this.GetType().Namespace +"."+"mywallpaper.jpg"; Stream strInStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(strStreamName); BinaryReader objInReader = new BinaryReader(strInStream); byte[] objInBytes = new byte[strInStream.Length]; objInReader.Read(objInBytes, 0, objInBytes.Length); FileStream fStream = new FileStream(strWallPaperPath, FileMode.OpenOrCreate); //set this path to something you wish before you use. BinaryWriter objOutWriter = new BinaryWriter(fStream); objOutWriter.Write(objInBytes, 0, objInBytes.Length); objOutWriter.Flush(); objOutWriter.Close(); fStream.Close(); strInStream.Close(); //Set all objects to null
Now setting the WallPaper 1) Following three constant definitions are needed:
const int SPI_SETDESKWALLPAPER = 20; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDWININICHANGE = 0x02;
2) P/Invoke Library:
[DllImport("user32.dll", SetLastError=true, CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
3)Now when you are ready setting the wallpaper, just call
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strWallPaperPath,SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Conclusion
I hope this seemingly long tip wouldn't have bored you (the reader). The purpose of this tip is two fold:
1)Share an interesting experience of 'Indigenous Mobile Briefcase with a simple Windows Forms Applications'. 2)A novice example to P/Invoke Library 3)A beginners exposure to Resource Files and Assembly Manipulation
Let me know your feedback on the same.
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|