资料重温——自定义对话框(来源于torryPages)

 {
  Sometimes we need to replace some text or something other in standard Windows
  Open/Save dialogs.
  Unfortunately, Delphi's dialogs components don't provide
  the access to all controls placed on Windows common dialogs.
  But we can perform this using Windows API.
  The Example below demonstrates the changing all embedded
  text controls in Open dialog.}

{
  Das Beispiel zeigt, wie man den Text in einem TOpenDialog
  durch eigenen ersetzen kann.
}


uses
  CommDlg;

{...}

procedure TForm1.OpenDialog1Show(Sender: TObject);
{First, we need to determine identifiers of dialog's
 controls, they are following:}
const
  LB_FILETYPES_ID = 1089; // "File types:" label
  LB_FILENAME_ID = 1090;  // "File name:" label
  LB_DRIVES_ID = 1091;    // "Look in:" label

  Str1 = 'Four';
  Str2 = 'Five';
  Str3 = 'One';
  Str4 = 'Two';
  Str5 = 'Three';
var
  hOpenDialog: HWND;
begin
  hOpenDialog := GetParent(OpenDialog1.Handle);
  SendMessage(hOpenDialog, CDM_SETCONTROLTEXT, idOk, Longint(PChar(Str1)));
  SendMessage(hOpenDialog, CDM_SETCONTROLTEXT, idCancel, Longint(PChar(Str2)));
  SendMessage(hOpenDialog, CDM_SETCONTROLTEXT, LB_FILETYPES_ID, Longint(PChar(Str3)));
  SendMessage(hOpenDialog, CDM_SETCONTROLTEXT, LB_FILENAME_ID, Longint(PChar(Str4)));
  SendMessage(hOpenDialog, CDM_SETCONTROLTEXT, LB_DRIVES_ID, Longint(PChar(Str5)));
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    // ...
  end;
end;


// for the Print - Dialog:

procedure TForm1.PrintDialog1Show(Sender: TObject);
begin
  SetWindowText(GetDlgItem(PrintDialog1.Handle, idOk), '&&OK2');
  SetWindowText(GetDlgItem(PrintDialog1.Handle, idCancel), '&Cancel2');
  SetWindowText(GetDlgItem(PrintDialog1.Handle, 1025), '&Properties2');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if PrintDialog1.Execute then
  begin
    // ...
  end;
end;



// to Enumerate Control - IDs:

function EnumProc(wnd: HWND; Lines: TStrings): BOOL; stdcall;
var
  buf, Caption: array [0..255] of char;
begin
  Result := True;
  GetClassname(wnd, buf, 256);
  GetWindowText(wnd, Caption, 256);
  Lines.Add(Format('ID: %d, class: %s, caption: %s',
    [GetDlgCtrlID(wnd), buf, Caption]));
end;

procedure TForm1.PrintDialog1Show(Sender: TObject);
begin
  memo1.Clear;
  EnumChildWindows(Printdialog1.Handle, @EnumProc, Integer(memo1.Lines));
end;




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值