//check if the ActiveDesktop is ON function IsActiveDeskTopOn: Boolean; var h: hWnd; begin h := FindWindow('Progman', nil); h := FindWindowEx(h, 0, 'SHELLDLL_DefView', nil); h := FindWindowEx(h, 0, 'Internet Explorer_Server', nil); Result := h <> 0; end;
...check if the ActiveDesktop is activ? uses ComObj, ShlObj, ActiveX; // Check if Active Desktop is enabled (1) function IsActiveDeskTopOn: Boolean; var h: HWND; begin h := FindWindow('Progman', nil); h := FindWindowEx(h, 0, 'SHELLDLL_DefView', nil); h := FindWindowEx(h, 0, 'Internet Explorer_Server', nil); Result := h <> 0; end; // Check if Active Desktop is enabled (2) function IsActiveDesktopEnable: Boolean; const CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}'; var ActiveDesk: IActiveDesktop; ComponentsOpt: TComponentsOpt; hr: HRESULT; dwReserved: DWORD; begin ZeroMemory(@ComponentsOpt, SizeOf(TComponentsOpt)); ComponentsOpt.dwSize := SizeOf(TComponentsOpt); hr := CoCreateInstance(CLSID_ActiveDesktop, nil, CLSCTX_INPROC_SERVER, CLSID_ActiveDesktop, ActiveDesk); if SUCCEEDED(hr) then begin hr := ActiveDesk.GetDesktopItemOptions(ComponentsOpt, dwReserved); // ActiveDesk._Release; end; Result := ComponentsOpt.fActiveDesktop; end;
function IsActiveDeskTopOn: Boolean;
var
h: hWnd;
begin
h := FindWindow('Progman', nil);
h := FindWindowEx(h, 0, 'SHELLDLL_DefView', nil);
h := FindWindowEx(h, 0, 'Internet Explorer_Server', nil);
Result := h <> 0;
end;
uses
ComObj, ShlObj, ActiveX; // Check if Active Desktop is enabled (1)
function IsActiveDeskTopOn: Boolean;
var
h: HWND;
begin
h := FindWindow('Progman', nil);
h := FindWindowEx(h, 0, 'SHELLDLL_DefView', nil);
h := FindWindowEx(h, 0, 'Internet Explorer_Server', nil);
Result := h <> 0;
end;
// Check if Active Desktop is enabled (2)
function IsActiveDesktopEnable: Boolean;
const
CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
var
ActiveDesk: IActiveDesktop;
ComponentsOpt: TComponentsOpt;
hr: HRESULT;
dwReserved: DWORD;
begin
ZeroMemory(@ComponentsOpt, SizeOf(TComponentsOpt));
ComponentsOpt.dwSize := SizeOf(TComponentsOpt);
hr := CoCreateInstance(CLSID_ActiveDesktop, nil, CLSCTX_INPROC_SERVER,
CLSID_ActiveDesktop, ActiveDesk);
if SUCCEEDED(hr) then
begin
hr := ActiveDesk.GetDesktopItemOptions(ComponentsOpt, dwReserved);
// ActiveDesk._Release;
end;
Result := ComponentsOpt.fActiveDesktop;
end;
应该使用ShellAPI中的SHGetSettings()函数.
另外本人还发现, 调用你们所写的代码函数时,在执行结束时,也就是执行到给Result赋值时会弹出错误, 看上去应该不是代码的毛病, 具体什么原因我还不清楚, 有谁遇到过这种问题吗?
特别是在Delphi里调用COM接口函数时.
在Delphi中调用COM组件时,需要在开始时候执行OleInitialize()为OLE做初始化,会不会是
因为这个原因导致上面错误的产生呢?我的调用方法是在Form创建时执行“OleInitialize(nil);”
还想问一个,Release()动作在什么地方做比较合适?
那只能說你找到第三種可能的方法而已,
上面的代碼是沒有問題的
OleInitialize(nil);finalization
try
OleUninitialize;
except
end;这几句话放在主窗口所有语句之后,“end.”之前