Delphi 获取浏览器路径 注册表获取默认浏览器、注册表读取IE路径 拼接IE路径

11 篇文章 0 订阅
7 篇文章 0 订阅

Delphi 获取浏览器路径 注册表获取默认浏览器、注册表读取IE路径 拼接IE路径。能想到的挫招都用上了。


function GetBrowserPath:string;
var
  hMyKey      : HKEY;
  sPath       : array [0..Max_Path-1] of char;
  sBrowserPath: string;
  sTemp       : string;
  vType, dLength: DWORD;
begin
  dLength := SizeOf(sPath);
  vType := REG_SZ;
  if RegOpenKeyEx(HKEY_CLASSES_ROOT,
                 'http\shell\open\command',
                 0,
                 KEY_READ,hMyKey) = ERROR_SUCCESS then
  begin
    if RegQueryValueEx(hMyKey,'',nil, @vType, @sPath[0], @dLength)= ERROR_SUCCESS then
    begin
      sBrowserPath := sPath;
      sBrowserPath := Copy(sBrowserPath, Pos('"', sBrowserPath) + 1, Length(sBrowserPath));
      sBrowserPath := Copy(sBrowserPath, 1, Pos('"', sBrowserPath) - 1) ;
    end;
  end;
  if sBrowserPath ='' then
  begin
    if RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                   'Software\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE',
                   0,
                   KEY_READ,
                   hMyKey)=ERROR_SUCCESS then
    begin
      if RegQueryValueEx(hMyKey, '' , nil, @vType, @sPath[0], @dLength) = 0 then
      begin
        sBrowserPath := sPath;
      end;
    end;
  end;
  if sBrowserPath ='' then
  begin
    GetSystemDirectory(sPath, SizeOf(sPath));
    sTemp := string(sPath) + '\';
    Delete(sTemp, Pos(':',sTemp) + 1, Length(sTemp));
    sTemp := Copy(sTemp,0,Pos(':',sTemp));
    sBrowserPath := sTemp + '\Program Files\Internet Explorer\IEXPLORE.EXE';
  end;
  Result := sBrowserPath;
  RegCloseKey(hMyKey);
end;




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi中,要实现拖拽文件夹并获取路径,可以按照以下步骤进行操作: 1. 添加控件:在窗体上添加一个TListBox控件用于显示拖拽的文件夹路径。 2. 设置TListBox为可接受拖拽文件:在TForm的OnCreate事件中添加以下代码,将TListBox的DragMode属性设置为dmAutomatic,使其可以接受文件拖拽操作。 ``` procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.DragMode := dmAutomatic; end; ``` 3. 处理拖拽事件:在TListBox的OnDragDrop事件中添加以下代码,用于处理拖拽文件夹的操作。 ``` procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); var i: Integer; DropFiles: TStrings; begin DropFiles := TStringList.Create; try if Source is TListBox then begin DropFiles.AddStrings(TListBox(Source).Items); for i := 0 to DropFiles.Count - 1 do ListBox1.Items.Add(DropFiles[i]); end; finally DropFiles.Free; end; end; ``` 4. 显示文件夹路径:在TListBox的OnDragOver事件中添加以下代码,用于在拖拽过程中显示文件夹路径。 ``` procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := Source is TListBox; if Accept then begin if State = dsDragEnter then ListBox1.Items.Clear; ListBox1.Items.Add(GetDroppedFileName); end; end; ``` 5. 获取文件夹路径:最后,我们还需要添加一个函数GetDroppedFileName,用于获取文件夹路径。 ``` function TForm1.GetDroppedFileName: string; var DropHandle: THandle; FileCount, i: Integer; FileName: array[0..MAX_PATH] of Char; begin Result := ''; DropHandle := DragQueryFile(DragQueryFile(DragQueryFile(DragQueryFile(Handle, Cardinal(-1), nil, 0), 0, nil, 0), 0, @FileName[0], Length(FileName)), 0, nil, 0); if DropHandle <> Cardinal(-1) then begin FileCount := DragQueryFile(Handle, DragHandle, nil, 0); if FileCount > 0 then begin DragQueryFile(DragHandle, 0, @FileName[0], Length(FileName)); Result := FileName; end; end; DragFinish(DragHandle); end; ``` 以上就是在Delphi中使用拖拽操作获取文件夹路径的步骤和代码。希望能对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值