Delphi调用Windows打开方式对话框示例

Delphi调用Windows打开方式对话框示例_第1张图片


Delphi调用Windows打开方式对话框示例_第2张图片


unit Form_Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    edtFile: TEdit;
    btSelFile: TButton;
    procedure btSelFileClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

uses
  ShellAPI, ShlObj;

procedure TForm2.btSelFileClick(Sender: TObject);
var
  OpenDialog: TOpenDialog;
begin
  OpenDialog := TOpenDialog.Create(Self);
  if OpenDialog.Execute(Handle) then
  begin
    edtFile.Text := OpenDialog.FileName;
  end;
  OpenDialog.Free;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  if edtFile.Text = EmptyStr then
    Exit;
  ShellExecute(Handle, 'open', 'Rundll32.exe',
    PChar('shell32.dll,OpenAs_RunDLL ' + edtFile.Text), nil, SW_SHOWNORMAL);
end;

procedure TForm2.Button2Click(Sender: TObject);
var
  OpenAsInfo: TOpenAsInfo;
begin
  if edtFile.Text = EmptyStr then
    Exit;
  OpenAsInfo.pcszFile := PChar(edtFile.Text);
  OpenAsInfo.pcszClass := nil;
  OpenAsInfo.oaifInFlags := OAIF_ALLOW_REGISTRATION or OAIF_REGISTER_EXT or
    OAIF_EXEC;
  SHOpenWithDialog(Handle, OpenAsInfo);
end;

end.

下载: http://www.400gb.com/file/19999325

你可能感兴趣的:(Delphi调用Windows打开方式对话框示例)