Dialógy s vlastnými komponentami
Modifikácia štandardných dialógov a pridávanie nových komponentov do nich.
unit TestDialog; interface uses Windows, Messages, SysUtils, CommDlg, Classes, Graphics, Controls, Forms, StdCtrls, Dialogs, ComCtrls, ExtCtrls, Dlgs, CommCtrl; type TTestDialog = class(TOpenDialog) private FPanel: TPanel; FStatus: TStatusBar; protected procedure DoShow; override; procedure WndProc(var Message: TMessage); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation constructor TTestDialog.Create(AOwner: TComponent); begin inherited Create(AOwner); Template := 'YOURDLGTEMPLATE'; Options := [ofHideReadOnly,ofFileMustExist]; FPanel := TPanel.Create( Self ); FStatus := TStatusBar.Create( Self ); end; destructor TTestDialog.Destroy; begin FPanel.Free; FStatus.Free; inherited Destroy; end; procedure TTestDialog.DoShow; var rc: TRect; begin GetClientRect(Handle, Rc); FPanel.BoundsRect := Rc; FPanel.Left := 424; FPanel.BevelOuter := bvNone; FPanel.Width := (Rc.Right - Rc.Left) - FPanel.Left; FPanel.Caption := 'Hello !'; FPanel.ParentWindow := Handle; FStatus.Align := alNone; FStatus.BoundsRect := Rc; FStatus.Top := FStatus.Top + FStatus.Height - 30; FStatus.Height := 30; FStatus.Width := FStatus.Width - FPanel.Width - 2; FStatus.SimplePanel := True; FStatus.ParentWindow := Handle; end; procedure TTestDialog.WndProc(var Message: TMessage); function ExtractFileNameOnly( s: String ): String; var tmp: String; begin Result := ExtractFilename( s ); tmp := ExtractFileExt( Result ); if tmp <> '' then Result := Copy( Result, 1, Length( Result ) - length( tmp ) ); end; const AddSize = 150; cNum = 7; Control: Array [0..cNum-1] of integer = ( stc3, stc2, //The two label ctrls edt1, cmb1, //Edit and combo ctrls IDOK, IDCANCEL, //The dialog buttons lst1 ); //The Explorer window var pLV,LV: HWND; Style: Longint; I,pos: integer; buf: array[0..254] of char; S: String; wndDlg,wndCtrl: HWND; Rc,cRc: TRect; begin Message.Result := 0; case Message.Msg of WM_INITDIALOG: begin wndDlg := GetParent(Handle); // Get a pointer to the parent window. GetWindowRect(wndDlg,Rc); //Get rect of parent window // Change the size of parent window according to SetWindowPos( wndDlg, HWND(NiL), 0, 0, Rc.right - Rc.left, Rc.bottom - Rc.top + AddSize, SWP_NOMOVE ); //Move all controls to a compensate for the new parent size for i:=0 to cNum-1 do begin wndCtrl := GetDlgItem(wndDlg,Control[i]); //Fetch control GetWindowRect(wndCtrl, cRc); //Get control's rect MapWindowPoints( 0, wndDlg, cRc, 2 ); if (Control[i] <> lst1) then //For any control except the lst1 //move the control appropriately SetWindowPos( wndCtrl, HWND(NiL), cRc.left, cRc.top + AddSize, 0, 0, SWP_NOSIZE ) else //size the folder view control appropriately SetWindowPos( wndCtrl, HWND(NiL), 0, 0, cRc.right - cRc.left, cRc.bottom - cRc.top + AddSize, SWP_NOMOVE ); end; end; WM_NOTIFY: begin case POFNotify(Message.LParam)^.hdr.code of // Can also trap: // CDN_FILEOK, CDN_FOLDERCHANGE, CDN_HELP, CDN_INITDONE, CDN_SELCHANGE, // CDN_SHAREVIOLATION, CDN_TYPECHANGE. CDN_SELCHANGE: begin // get the ACTUAL ListView handle (not lst1) pLV := GetDlgItem( GetParent(Handle), lst2 ); LV := GetDlgItem( pLV, 1 ); Style := GetWindowLong(LV, GWL_STYLE); Style := Style and (not LVS_TYPEMASK); Style := Style or LVS_ICON; SetWindowLong(LV, GWL_STYLE, Style); // currently selected item pos := ListView_GetNextItem ( LV, -1, LVNI_ALL or LVNI_SELECTED ); if ( pos <> -1 ) then begin ListView_GetItemText( LV, pos, 0, buf, 255 ); S := ExtractFilePath( Filename ) + ExtractFileNameOnly(buf) ; if FileExists(S + ExtractFileExt( Filename )) then FStatus.SimpleText := 'File: ' + s + ExtractFileExt( Filename ) else FStatus.SimpleText := 'Folder: '+s; end; end; end; end; end; inherited WndProc(Message); end; end. //// test.rc: YOURDLGTEMPLATE DIALOG 0, 0, 296, 80 STYLE 0x404L | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS FONT 8, "MS Sans Serif" { RTEXT "", 1119, 0, 0, 204, 76, SS_LEFT | WS_CHILD | NOT WS_VISIBLE | WS_GROUP }