zoukankan      html  css  js  c++  java
  • 使 SaveDialog 对话框的文件名选择变灰 回复 "delphan" 的问题


    问题来源: http://www.cnblogs.com/del/archive/2009/03/18/1410030.html#1480550

    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        SaveDialog1: TSaveDialog;
        procedure Button1Click(Sender: TObject);
        procedure SaveDialog1SelectionChange(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    const
      FileName = 'ABC.txt';
    
    {变灰并维持指定的文件名}
    procedure EnableFileName(h: HWND; name: string);
    var
      hc: HWND;
      buf: array[Byte] of Char;
    begin
      h := GetWindow(h, GW_HWNDFIRST);
      while h <> 0 do
      begin
        if GetParent(h) = Form1.Handle then
        begin
          hc := GetWindow(h, GW_CHILD);
          while hc <> 0 do
          begin
            GetClassName(hc, buf, SizeOf(buf));
            if buf = 'ComboBoxEx32' then
            begin
              EnableWindow(hc, False);
              SetWindowText(hc, name);
              Exit;
            end;
            hc := GetWindow(hc, GW_HWNDNEXT);
          end;
        end;
        h := GetWindow(h, GW_HWNDNEXT);
      end;
    end;
    
    {其实变灰只是假象, 使用时还需要调整下}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      path: string;
    begin
      SaveDialog1.FileName := FileName;
      SaveDialog1.OptionsEx := [ofExNoPlacesBar];
      if SaveDialog1.Execute(Handle) then {注意这里 Execute 参数是当前窗口的句柄}
      begin
        path := SaveDialog1.FileName;
        path := ExtractFilePath(path) + FileName;
        ShowMessage(path);
      end;
    end;
    
    {在 SaveDialog 的 OnSelectionChange 事件中调用上面的自定义过程 EnableFileName}
    procedure TForm1.SaveDialog1SelectionChange(Sender: TObject);
    begin
      EnableFileName(Handle, FileName);
    end;
    
    end.
    

    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 129
      ClientWidth = 225
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Button1: TButton
        Left = 128
        Top = 83
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
      object SaveDialog1: TSaveDialog
        OnSelectionChange = SaveDialog1SelectionChange
        Left = 24
        Top = 16
      end
    end
    

  • 相关阅读:
    如何把phpStorm打造成自己的专属IDE?
    PHP伪造referer突破网盘禁止外链(附115源码)
    PHP实现删除非站内外部链接实例代码
    Http Referer的一些总结
    jquery 选择器(name,属性,元素)大全
    Invoke 和 BeginInvoke 的真正涵义
    C# HashSet集合类型使用介绍
    Dev系列控件的AJAX使用Demo
    如何进行SVN数据迁移并保存版本号数据
    Window及document对象
  • 原文地址:https://www.cnblogs.com/del/p/1415934.html
Copyright © 2011-2022 走看看