Problem description: staring at the desktop background. It's interesting if the desktop background changes like win7. The alarm generates an idea instantly. Use C # To write an image that dynamically switches the desktop background. After thinking about how to implement this idea, I thought about the following problems:
(1): How can I switch images to better meet customer requirements.
(2): C # what technology is used to switch the background image of the desktop.
(3): how to store and read images.
Solution:
(1): In what way? Console? Winform? Finally, we decided to use windows services for implementation. Because it can be started with windows, and the user changes without knowing it, it is easy to do his own thing silently. I have never worked on windows services before. I searched the internet and understood the principle. So I want to make a simple example. Function example: Write a service and prompt a message regularly. The code is soon written. After registration, the service cannot be started and no information is prompted. The problem is sharp. I only need to set the service attribute after an hour of Search: allow the Service to interact with the desktop. I set it and restarted the service. The prompt message is displayed, but this problem cannot be solved by the customer every time. The online Search solution is provided. The key code is as follows:
Code Private void serviceinstallerpolicafterinstall (object sender, InstallEventArgs e)
{
ConnectionOptions coOptions = new ConnectionOptions ();
CoOptions. Impersonation = ImpersonationLevel. Impersonate;
ManagementScope mgmtScope = new System. Management. ManagementScope (@ "rootCIMV2", coOptions );
MgmtScope. Connect ();
ManagementObject wmiService;
WmiService = new ManagementObject ("Win32_Service.Name =" + this. serviceInstaller1.ServiceName + "");
ManagementBaseObject InParam = wmiService. GetMethodParameters ("Change ");
InParam ["Reply topinteract"] = true;
ManagementBaseObject OutParam = wmiService. InvokeMethod ("Change", InParam, null );
}
The first problem is finally solved.
(2): How to switch the image, Search, it seems that there is a way to call the system API, but the image can only be in BMP format. The Code is as follows:
Code # Region System Innerface
[DllImport ("user32.dll", EntryPoint = "SystemParametersInfo")]
Public static extern int SystemParametersInfo (
Int uAction,
Int uParam,
String lpvParam,
Int fuWinIni
);
# Endregion
# Region Timer Elapsed
Private void dynamicTimer_Elapsed (object sender, System. Timers. ElapsedEventArgs e)
{
If (picIndex <PicturePath. Count)
{
Setmediatoppicture (PicturePath [picIndex]. ToString ());
& Nbs