首页  编辑  

自定义公用对话框的一些Label

Tags: /超级猛料/VCL/Common.Dialog.通用对话框和控件/   Date Created:

自定义公用对话框的一些Label:

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 . Button1Click ( Sender : TObject );

begin

 OpenDialog1 . Execute ;

end ;

***********

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 ;

// 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;

注意,OpenDialog.Handle不是那个窗口的Handle,需要用GetParent(OpenDialog.Handle)来获取真正的Handle。

因此EnumChildWindows对于OpenDialog来说,应该是:

EnumChildWindows(GetParent(OpenDialog1.Handle),@EnumProc,Integer(Memo1.Lines));

{ Win2K OpenDialog的ID和Class信息:

ID: 1091, class: Static, caption: 查找范围(&I):

ID: 1137, class: ComboBox, caption:

ID: 1088, class: Static, caption:

ID: 1088, class: ToolbarWindow32, caption:

ID: 1120, class: ListBox, caption:

ID: 1090, class: Static, caption: 文件名(&N):

ID: 1148, class: ComboBoxEx32, caption:

ID: 1148, class: ComboBox, caption:

ID: 1148, class: Edit, caption:

ID: 1089, class: Static, caption: 文件类型(&T):

ID: 1136, class: ComboBox, caption:

ID: 1040, class: Button, caption: 以只读方式打开(&R)

ID: 1, class: Button, caption: 打开(&O)

ID: 2, class: Button, caption: 取消

ID: 1038, class: Button, caption: 帮助(&H)

ID: -1, class: ScrollBar, caption:

ID: 0, class: #32770, caption:

}

img_16506.bmp (763.2KB)