C # switching between dynamic desktop background images

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.