打开WEBBROWSER的选中文件路径

 
uses CommCtrl, httpApp, ShellApi;
{
 GetWebPath(WebBrowser1);
}
function GetWebPath(web: TWebBrowser): string;
var
  item: TLvItem;
  clsName: array [0 .. MAX_PATH] of char;
  hwndLv: HWND;
  selCount, fileCount, selMark: Integer;
  fileName: array [0 .. MAX_PATH] of char;
begin
  hwndLv := GetWindow(web.Handle, GW_CHILD);
  hwndLv := GetWindow(hwndLv, GW_CHILD);
  GetClassName(hwndLv, clsName, MAX_PATH);
  if (UpperCase(clsName) <> 'SYSLISTVIEW32') then
    Exit;
  Result := web.LocationURL;
  Result := StringReplace(Result, 'file:///', '', [rfIgnoreCase]);
  Result := StringReplace(Result, '/', '\', [rfReplaceAll]);
// Result := StringReplace(Result, '%20', ' ', [rfReplaceAll]);
 
  if (Result[length(Result)] <> '\') then
    Result := Result + '\';
 
  fileCount := ListView_GetItemCount(hwndLv);
  selCount := ListView_GetSelectedCount(hwndLv);
  selMark := ListView_GetSelectionMark(hwndLv);
  if (selCount = 0) or (selMark = -1) then
    Exit;
 
  ListView_GetItemText(hwndLv, selMark, 0, @fileName[0], MAX_PATH);
  Result := HttpDecode(Result + fileName);
end;





你可能感兴趣的:(WebBrowser)