Hello,
I was wondering if anyone can point me in the direction of finding
sample code on creating an ActiveDesktop component on the fly using the
IActiveDesktop interface with the AddDesktopItem() method? I have attached a
copy of the code that I wrote, however, it doesn't create the component. Can
you help me?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShlObj, ComObj, WinINet;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
const
CLSID_ActiveDesktop:TGUID =(
D1:$75048700; D2:$EF1F; D3:$11D0; D4:($98, $88, $00, $60, $97, $DE, $AC,
$F9));
var
wchWallpaperName : array[0..MAX_PATH] of Widechar;
MyObject : IUnknown;
twpoWallpaperOption : TWallPaperOpt;
tadkMyActiveDesktop : IActiveDesktop;
strImage : string;
strDisplayType : string;
begin
// Convert the PChars back to strings;
strImage := 'c:\windows\cloud.gif';
strDisplayType := 'tile';
// Remove any leading and trailing spaces that might exist in the
string.
strImage := Trim(strImage);
strDisplayType := Trim(strDisplayType);
// Convert the string to a widechar so that it works with the interface.
StringtoWideChar(strImage, wchWallpaperName, (MAX_PATH - 1));
MyObject := CreateComObject(CLSID_ActiveDesktop);
tadkMyActiveDesktop := MyObject as IActiveDesktop;
// Assign the wallpaper option to the wallpaper option structure.
twpoWallpaperOption.dwSize := SizeOf(twpoWallpaperOption);
// Use an if...then statement to convert the string option value to an
// integer.
if LowerCase(strDisplayType) = 'stretch' then
twpoWallpaperOption.dwStyle := 2
else if LowerCase(strDisplayType) = 'tile' then
twpoWallpaperOption.dwStyle := 1
else
twpoWallpaperOption.dwStyle := 0;
// Change the wallpaper settings and refresh the desktop.
tadkMyActiveDesktop.SetWallpaperOptions(twpoWallpaperOption, 0);
tadkMyActiveDesktop.SetWallpaper(wchWallpaperName, 0);
tadkMyActiveDesktop.ApplyChanges(AD_APPLY_FORCE OR AD_APPLY_REFRESH OR
AD_APPLY_HTMLGEN OR AD_APPLY_SAVE);
end;
procedure TForm1.Button2Click(Sender: TObject);
const
CLSID_ActiveDesktop:TGUID =(
D1:$75048700; D2:$EF1F; D3:$11D0; D4:($98, $88, $00, $60, $97, $DE, $AC,
$F9));
MyControl = '591A09D0-6299-11D2-845B-00A0C955B0C1';
var
MyObject : IUnknown;
tadkMyActiveDesktop : IActiveDesktop;
twpoComponent : TShComponent;
twpoComponentPos : TCompPos;
twpoComponentOpt : TComponentsOpt;
begin
MyObject := CreateComObject(CLSID_ActiveDesktop);
tadkMyActiveDesktop := MyObject as IActiveDesktop;
with twpoComponentOpt do
begin
// Assign the size of the structure to the structure's size member.
dwSize := SizeOf(twpoComponentOpt);
fEnableComponents := True;
fActiveDesktop := True;
end;
with twpoComponentPos do
begin
// Assign the size of the structure to the structure's size member.
dwSize := SizeOf(twpoComponentPos);
iLeft := 200;
iTop := 200;
dwWidth := 438;
dwHeight := 99;
izIndex := 1000;
fCanResize := False;
fCanResizeX := False;
fCanResizeY := False;
iPreferredLeftPercent := 0;
iPreferredTopPercent := 0;
end;
FillChar(twpoComponent, SizeOf(twpoComponent), 0);
with twpoComponent do
begin
// Assign the size of the structure to the structure's size
member.
dwSize := SizeOf(twpoComponent);
dwID := 0;
iComponentType := COMP_TYPE_CONTROL;
fChecked := True;
fDirty := False;
fNoScroll := True;
cpPos := twpoComponentPos;
// Convert the string to a widechar.
StringtoWideChar('gateway.net button', wszFriendlyName, SizeOf
(wszFriendlyName) div 2);
// Convert the string to a widechar.
StringtoWideChar(MyControl, wszSource, SizeOf(wszSource) div 2);
// Convert the string to a widechar. }
StringtoWideChar(MyControl, wszSubscribedURL, SizeOf
(wszSubscribedURL) div 2);
end;
tadkMyActiveDesktop.SetDesktopItemOptions(twpoComponentOpt, 0);
tadkMyActiveDesktop.AddDesktopItem(twpoComponent, 0);
tadkMyActiveDesktop.ApplyChanges(AD_APPLY_FORCE OR AD_APPLY_REFRESH OR
AD_APPLY_HTMLGEN OR AD_APPLY_SAVE OR
AD_APPLY_ALL);
end;
end.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own