Intro: How to Create a Simple Power Control Application for Desktop
Hi, today i am gonna teach you "How to create your own power control app for your computer"
The main purpose of the Power Control app is, it will help you to have an instant access to your actual hidden power controls which are not appeared in the shutdown menu of your computer.
1. Visual Studio 2008/2010/2012/2013 (any visual studio you like but i am using visual studio 2010) 2. A virtual machine (optional)
NO ANY PROGRAMMING SKILLS ARE REQUIRED JUST SOME SIMPLE SKILLS FOR KNOWING HOW TO ADD FORM OR BUTTON AND RESIZE THEM IN VISUAL STUDIO
Step 1: Creating Your First Project
Now simply open visual studio and click on "new project" and then name it yourself. (i am naming it "power control")
The project must be a windows forms application with C# language selected in the left side menu !
Step 2: Creating UI "user Interface" A
First you will see a windows styled small 300x300 form !
Resize it by the small dots around its corners.
Step 3: Creating UI "User Interface" B
Now focus on the menu on the lower right size of the visual studio.
Change the settings there.
Step 4: Creating UI "User Interface" C
Now head to the tool box on the left side of the visual studio.
now add 4 buttons by "drag and drop" action.
Step 5: Creating UI "User Interface" D
Now resize the buttons by selecting all of them and change the size to 128x128 in the properties menu.
Step 6: Creating UI "User Interface" E
Now change the name of the button to
button 1 = shutdown
button 2 = restart
button 3 = lock
button 4 = sleep
Step 7: Adding Codes "A"
First double-click on the button 1 = shutdown (some codes will appear)
then write the following code
FOR BUTTON 1 = SHUTDOWN
Process.Start("shutdown", "/s /t 0");
FOR FUTURE USE ADD THESE ABOVE BUTTON 1
[DllImport("user32")] public static extern void LockWorkStation() [DllImport("user32")] public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
FOR ALL PROCESSES ADD THESE CODES IN THE SHOWN LOCATION ABOVE IN THE PICTURE
using System.Diagnostics; using System.Runtime.InteropServices;
Step 8: Adding Codes "B"
Now double-click the restart button and add these codes to it
Process.Start("shutdown","/r /t 0");
Step 9: Adding Codes "C"
Now double click the lock button and add these codes
Step 10: Adding Codes "D"
now double click the sleep button and add these codes
ADD THIS DLL ABOVE SLEEP BUTTON = BUTTON 4
[DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
ADD THIS TO THE ACTUAL SLEEP BUTTON
SetSuspendState(false, true, true);
Step 11: ALL DONE
Now head back to your designer "Form 1" , and then debug/run the application !
Just try the lock button to test the codes are working ! or else if you try the restart or sleep button, you might lose your current work.
I suggest you to try this application in virtual machine.
Now publish your app and use it the way you like and if you want more good UI then add your creativity in it !
Step 12: Extra Stuff
If you like this tutorial then please visit
www.visionveb.blogspot.com and download awesome applications by Vision™
this Power Control was inspired from their Power™ application ! download it for free by clicking HERE !
please follow me on twitter and share and tweet the posts by Vision™ because Vision is awesome ! :)
Follow on twitter @SafeerAhmedAbro