This article contains information on the ActiveDesktop object that is part of the Microsoft?Windows?Shell API. This object, through its IActiveDesktop interface, allows you to add, remove, and change items on the desktop.
Overview of the Active Desktop Interface
The Active Desktop is a feature of Microsoft Internet Explorer 4.0 that allows you to include HTML documents and items (such as ActiveX?Controls and Java applets) directly to your desktop. The IActiveDesktop interface, which is part of the Windows Shell API, is used to programmatically add, remove, and modify the items on the desktop. Active Desktop items can also be added using a Channel Definition Format (CDF) file.
Accessing the Active Desktop
To access the Active Desktop, a client application would need to create an instance of the ActiveDesktop object (CLSID_ActiveDesktop) with the CoCreateInstance function and get a pointer to the object's IActiveDesktop interface.
The following sample shows how to get a pointer to the IActiveDesktop interface.
There are three methods that can be used to add a desktop item: IActiveDesktop::AddDesktopItem, IActiveDesktop::AddDesktopItemWithUI, and IActiveDesktop::AddUrl. Each desktop item added to the Active Desktop must have a different source URL.
The IActiveDesktop::AddDesktopItemWithUI and IActiveDesktop::AddUrl both provide the option to display the various user interfaces that can be displayed before adding a desktop item to the Active Desktop. The interfaces will verify if the user really wants to add the desktop item to their Active Desktop, notify the user of any security risks that are warranted by the URL security zone settings, and ask the user if the user would like to create a subscription for this desktop item. Both methods also provide a way of suppressing the user interfaces. The IActiveDesktop::AddDesktopItem method requires a call to IActiveDesktop::ApplyChanges in order to update the registry. For the IActiveDesktop::AddDesktopItemWithUI, the client application must immediately release the IActiveDesktop interface and then use the CoCreateInstance function to get an interface to an instance of the ActiveDesktop object that includes the newly added desktop item.
The IActiveDesktop::AddDesktopItem method will add the specified desktop item to the Active Desktop without any user interface, unless the URL security zone settings prevent it. If the URL security zone settings do not allow the desktop item to be added without prompting the user, the method will fail. IActiveDesktop::AddDesktopItem also requires a call to IActiveDesktop::ApplyChanges in order to update the registry.
The following sample demonstrates how to add a desktop item with the IActiveDesktop::AddDesktopItem method.
To enumerate the desktop items currently installed on the Active Desktop, the client application needs to get the total number of desktop items installed using the IActiveDesktop::GetDesktopItemCount method and then creating a loop that retrieves the COMPONENT structure for each desktop item by calling the IActiveDesktop::GetDesktopItem method using the desktop item index.
The following sample demonstrates one way to enumerate the desktop items.
지승용님의 도움으로 해결하였습니다.
감사합니다.
unit activedesktop;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,
shlobj, //<- 이것과 (iactivedesktop이 정의되어있습니다.)
comobj; //<- 이것을 선언해 주셔야합니다. (CreateComObject이 정의되어있습니다.)
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure ActiveDesktop_Destroy;
var
ActiveDesktop: IActiveDesktop;
Active_COMPONENTSOPT : _tagCOMPONENTSOPT;
WallPaper_String : String;
WallPaper_Wide : PWideChar;
begin
ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
WallPaper_Wide := AllocMem(MAX_PATH*2);
ActiveDesktop.GetWallpaper(WallPaper_Wide, MAX_PATH*2, 0);
WallPaper_String := WallPaper_Wide;
FreeMem(WallPaper_Wide);
// if WallPaper_String <> (ExtractFilePath(Application.ExeName) + 'pa2.bmp') then
// begin
WallPaper_Wide := AllocMem(MAX_PATH*2); //메모리할당
// StringToWideChar(ExtractFilePath(Application.ExeName) + 'pa2.bmp', WallPaper_Wide, MAX_PATH*2);
StringToWideChar('C:My Documentsdesktop.html', WallPaper_Wide, MAX_PATH*2); //그림또는 html파일명지정
ActiveDesktop.SetWallpaper(WallPaper_Wide, 0); //화면중앙표시, 확대표시 ,바둑판식표시지정...
ActiveDesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);
FreeMem(WallPaper_Wide); //메모리해제
// end;
Active_COMPONENTSOPT.dwSize := SizeOf(_tagCOMPONENTSOPT);
ActiveDesktop.GetDesktopItemOptions(Active_COMPONENTSOPT, 0);
// 여그는 엑티브데스크탑항목을 사용중인지 엑티브데스크탑으로 되어있는지를 검사합니다.
// if (Active_COMPONENTSOPT.fEnableComponents = TRUE) or (Active_COMPONENTSOPT.fActiveDesktop = TRUE) then
// begin
Active_COMPONENTSOPT.fEnableComponents := TRUE; //엑티브데스크탑항목을 사용하도록설정
Active_COMPONENTSOPT.fActiveDesktop := TRUE; //엑티브데스크탑으로 설정..
ActiveDesktop.SetDesktopItemOptions(Active_COMPONENTSOPT,0); //요건 파악을 못했습니다.
ActiveDesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE); //변경사항을 적용시킵니다.
{
위에서 bmp파일을 지정하고 이곳을 실행시키면 일반 바탕화면이 표시됩니다.
Active_COMPONENTSOPT.fEnableComponents := FALSE;
Active_COMPONENTSOPT.fActiveDesktop := FALSE;
ActiveDesktop.SetDesktopItemOptions(Active_COMPONENTSOPT,0);
ActiveDesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);
}
// end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ActiveDesktop_Destroy;
end;
{
////////////////////////////////////
// 배경화면 그림을 바꾸어주는 방법
////////////////////////////////////
Reg := TRegIniFile.Create('Control Panel');
BMP_String := Reg.ReadString('desktop', 'Wallpaper', '');
Reg.WriteString('desktop', 'Wallpaper', ExtractFilePath(Application.ExeName) + 'pa2.bmp');
Reg.WriteString('desktop', 'TileWallpaper', '0');
Reg.Free;
// desktop의 wallpaper를 set하고 다은 window에 알린다
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, nil, SPIF_SENDWININICHANGE);
}
end.