如何检索 ISearchBoxInfo 接口?
How to retrieve the ISearchBoxInfo interface?
我想捕获 Windows' 搜索框,为此我发现我可以使用 ISearchBoxInfo 界面:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd562062(v=vs.85).aspx
我有 windows 资源管理器的句柄 - 但我不太确定如何获得该界面。如有任何帮助,我们将不胜感激。
function FindSearchBoxInfo(AWnd: HWND): ISearchBoxInfo;
var
ShellWindows: IShellWindows;
ExplorerIndex: Integer;
Dispatch: IDispatch;
WebBrowser2: IWebBrowser2;
ServiceProvider: IServiceProvider;
begin
Result := nil;
if Succeeded(CoCreateInstance(CLASS_ShellWindows, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IShellWindows, ShellWindows)) then
begin
for ExplorerIndex := ShellWindows.Count - 1 downto 0 do
begin
Dispatch := ShellWindows.Item(ExplorerIndex);
if Assigned(Dispatch) then
begin
if Succeeded(Dispatch.QueryInterface(IWebBrowser2, WebBrowser2)) then
begin
if WebBrowser2.HWND = AWnd then
begin
if Succeeded(Dispatch.QueryInterface(IServiceProvider, ServiceProvider)) then
begin
ServiceProvider.QueryService(SID_SSearchBoxInfo, ISearchBoxInfo, Result);
ServiceProvider := nil;
end;
WebBrowser2 := nil;
Dispatch := nil;
ShellWindows := nil;
Exit;
end;
WebBrowser2 := nil;
end;
Dispatch := nil;
end;
end;
ShellWindows := nil;
end;
end;
我想捕获 Windows' 搜索框,为此我发现我可以使用 ISearchBoxInfo 界面:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd562062(v=vs.85).aspx
我有 windows 资源管理器的句柄 - 但我不太确定如何获得该界面。如有任何帮助,我们将不胜感激。
function FindSearchBoxInfo(AWnd: HWND): ISearchBoxInfo;
var
ShellWindows: IShellWindows;
ExplorerIndex: Integer;
Dispatch: IDispatch;
WebBrowser2: IWebBrowser2;
ServiceProvider: IServiceProvider;
begin
Result := nil;
if Succeeded(CoCreateInstance(CLASS_ShellWindows, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IShellWindows, ShellWindows)) then
begin
for ExplorerIndex := ShellWindows.Count - 1 downto 0 do
begin
Dispatch := ShellWindows.Item(ExplorerIndex);
if Assigned(Dispatch) then
begin
if Succeeded(Dispatch.QueryInterface(IWebBrowser2, WebBrowser2)) then
begin
if WebBrowser2.HWND = AWnd then
begin
if Succeeded(Dispatch.QueryInterface(IServiceProvider, ServiceProvider)) then
begin
ServiceProvider.QueryService(SID_SSearchBoxInfo, ISearchBoxInfo, Result);
ServiceProvider := nil;
end;
WebBrowser2 := nil;
Dispatch := nil;
ShellWindows := nil;
Exit;
end;
WebBrowser2 := nil;
end;
Dispatch := nil;
end;
end;
ShellWindows := nil;
end;
end;