Author: Jonas Bilinkevicius
How to check if Active Desktop is enabled
Answer:
1 uses
2 ComObj, ShlObj, ActiveX;
3
4 {Check if Active Desktop is enabled - Option 1}
5
6 function IsActiveDeskTopOn: Boolean;
7 var
8 h: HWND;
9 begin
10 h := FindWindow('Progman', nil);
11 h := FindWindowEx(h, 0, 'SHELLDLL_DefView', nil);
12 h := FindWindowEx(h, 0, 'Internet Explorer_Server', nil);
13 Result := h <> 0;
14 end;
15
16 {Check if Active Desktop is enabled - Option 2}
17
18 function IsActiveDesktopEnable: Boolean;
19 const
20 CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
21 var
22 ActiveDesk: IActiveDesktop;
23 ComponentsOpt: TComponentsOpt;
24 hr: HRESULT;
25 dwReserved: DWORD;
26 begin
27 ZeroMemory(@ComponentsOpt, SizeOf(TComponentsOpt));
28 ComponentsOpt.dwSize := SizeOf(TComponentsOpt);
29 hr := CoCreateInstance(CLSID_ActiveDesktop, nil, CLSCTX_INPROC_SERVER,
30 CLSID_ActiveDesktop, ActiveDesk);
31 if SUCCEEDED(hr) then
32 begin
33 hr := ActiveDesk.GetDesktopItemOptions(ComponentsOpt, dwReserved);
34 {ActiveDesk._Release;}
35 end;
36 Result := ComponentsOpt.fActiveDesktop;
37 end;
38
39
40 //And here is how to activate the Active Desktop:
41
42
43 procedure TForm1.Button1Click(Sender: TObject);
44 const
45 CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
46 var
47 ActiveDesk: IActiveDesktop;
48 ComponentsOpt: TComponentsOpt;
49 begin
50 ActiveDesk := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
51 with ActiveDesk do
52 begin
53 ComponentsOpt.dwSize := SizeOf(ComponentsOpt);
54 GetDesktopItemOptions(ComponentsOpt, 0);
55 ComponentsOpt.fActiveDesktop := True;
56 SetDesktopItemOptions(ComponentsOpt, 0);
57 ApplyChanges(AD_APPLY_ALL);
58 end;
59 end;
|