Delphi Changes desktop wallpaper by calling COM object implementation

Source: Internet
Author: User

In the past I also use SystemParametersInfo this API to change the desktop wallpaper, a lot of problems, do not know which is wrong, did not dig down. After reading Csdn's post, Taichetaiwu ~ ~
Under XP, SystemParametersInfo only supports BMP format picture, if in other format, it will be black screen? (I remember when I was in this situation and now I'm too lazy to test) throw this API's calling method out:
SystemParametersInfo (spi_setdeskwallpaper, 1, Pointer (Pchar (' c:\a.bmp ')), 0);
Because of the limitations of this API function

Uses Shlobj, comobj;

Procedure Setwp (wp:string);
Var
Hobj:iunknown;
Adesktop:iactivedesktop;
Begin
Hobj: = Createcomobject (Clsid_activedesktop);
Adesktop: = Hobj as IActiveDesktop;
Adesktop.setwallpaper (Pwidechar (widestring (WP)), 0);
Adesktop.applychanges (Ad_apply_all or ad_apply_force);?
End

Calling methods
Setwp (' C:\1.jpg ');

Note: Because a COM object is called, you need to initialize the COM library
If you do not reference a cell like dialogs, you need to call CoInitialize () manually and then release the object when you exit

Uses ActiveX;

Initialization
CoInitialize (nil);

Finalization
CoUninitialize;

Http://www.lsworks.net/article/29.html

Delphi Changes desktop wallpaper by calling COM objects

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.