2009. július 13., hétfő

Changing standard Windows dialogs


Problem/Question/Abstract:

How to change text like "File name:", "File Type" and buttons' text in standard Windows dialogs?

Answer:

Some times 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.

Example below demonstrates the changing all embedded text controls in Open dialog.

First, we need to determine identifiers of dialog's controls, they are following:

const
  // LB_FOLDERS_ID = 65535;
  LB_FILETYPES_ID = 1089; // "File types:" label
  LB_FILENAME_ID = 1090; // "File name:" label
  LB_DRIVES_ID = 1091; // "Look in:" label

Second, we need to send message to dialog window for changing necessary controls, something like following:

procedure TForm1.OpenDialog1Show(Sender: TObject);
const
  // LB_FOLDERS_ID = 65535;
  LB_FILETYPES_ID = 1089;
  LB_FILENAME_ID = 1090;
  LB_DRIVES_ID = 1091;
  Str1 = 'Four';
  Str2 = 'Five';
  Str3 = 'One';
  Str4 = 'Two';
  Str5 = 'Three';
begin
  SendMessage(GetParent(OpenDialog1.Handle), CDM_SETCONTROLTEXT, IDOK,
    LongInt(Pchar(Str1)));
  SendMessage(GetParent(OpenDialog1.Handle), CDM_SETCONTROLTEXT, IDCANCEL,
    LongInt(Pchar(Str2)));
  SendMessage(GetParent(OpenDialog1.Handle), CDM_SETCONTROLTEXT, LB_FILETYPES_ID,
    LongInt(Pchar(Str3)));
  SendMessage(GetParent(OpenDialog1.Handle), CDM_SETCONTROLTEXT, LB_FILENAME_ID,
    LongInt(Pchar(Str4)));
  SendMessage(GetParent(OpenDialog1.Handle), CDM_SETCONTROLTEXT, LB_DRIVES_ID,
    LongInt(Pchar(Str5)));
end;

Nincsenek megjegyzések:

Megjegyzés küldése