0

我想捕获 Windows 的搜索框,因为我发现我可以使用 ISearchBoxInfo 界面:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd562062(v=vs.85).aspx

我有 Windows 资源管理器的句柄 - 但我不确定如何获得该界面。任何帮助将不胜感激。

4

1 回答 1

1
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;
于 2018-02-06T11:21:44.937 回答