您现在的位置:首页 >> VCL >> VCL >> 内容

Delphi用EnableWindow使OpenDialog对话框的文件类型选择变灰

时间:2011/9/3 16:25:09 点击:

  核心提示:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,...

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure OpenDialog1SelectionChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure EnableFileName(H,P: HWND);
var
  hc: HWND;
  buf: array[Byte] of Char;
begin
  h := GetWindow(h, GW_HWNDFIRST);
  while h <> 0 do
  begin
    hc := GetWindow(h, GW_CHILD);
    while hc <> 0 do
    begin
      GetClassName(hc, buf, SizeOf(buf));
      if buf = 'ComboBox' then
      begin
        GetWindowText(hc,buf,MAX_PATH);
        if buf='可执行文件' then
        begin
          EnableWindow(hc, False);
          Exit;
        end;
      end;
      hc := GetWindow(hc, GW_HWNDNEXT);
    end;
    h := GetWindow(h, GW_HWNDNEXT);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenDialog1.Filter:='可执行文件|*.exe';
  OpenDialog1.OptionsEx := [ofExNoPlacesBar];//去掉左栏
  if OpenDialog1.Execute then
  begin
    ShowMessage(OpenDialog1.FileName);
  end;
end;

procedure TForm1.OpenDialog1SelectionChange(Sender: TObject);
begin
  EnableFileName(Self.Handle,Self.Handle);
end;

end.
600) this.width = 600;">

作者:站长 来源:原创
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号