///////////////////////////////////////////////////////////////////////////////
//
// TForm1.OpenDlgOnShow
//
// OnShowEventHandler des Dialoges
// Edit auf Dialog plazieren
//
procedure TForm1.OpenDlgOnShow(Sender: TObject);
var
hParent: THandle;
rect: TRect;
hEdit: THandle;
begin
// OpenDialog1.Handle ist irgendwie das falsche :?
hParent := GetParent(OpenDialog1.Handle);
// Position und Größe ermitteln
GetWindowRect(hParent, rect);
// Dialog vergrößern für Edit
SetWindowPos(hParent, 0, 0, 0, rect.Right - rect.Left, rect.Bottom - rect.Top
+ 25, SWP_NOMOVE);
// Edit erzeugen, ID = 101
hEdit := CreateWindowEx(WS_EX_CLIENTEDGE, '
EDIT', '
', WS_VISIBLE
or WS_CHILD,
195, rect.Bottom - rect.Top - 27, 150, 20, hParent, 101, 0,
nil);
if hEdit = 0
then
RaiseLastOSError;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TForm1.OpenDlgOnClose
//
// OnCloseEventHandler des OpenDialoges
// eigenes Edit auslesen
//
procedure TForm1.OpenDlgOnClose(Sender: TObject);
var
hParent: THandle;
hEdit: THandle;
Buffer: PChar;
len: Integer;
begin
hParent := GetParent(OpenDialog1.Handle);
// Handle des Edits ermitteln, ID = 101 siehe oben
hEdit := GetDlgItem(hParent, 101);
// Speicher allozieren
len := SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);
GetMem(Buffer, len + 1);
try
ZeroMemory(Buffer, len + 1);
// Text aus Edit holen
SendMessage(hEdit, WM_GETTEXT, len, lParam(Buffer));
ShowMessage(Buffer);
finally
FreeMem(Buffer, len + 1);
end;
end;
////////////////////////////////////////////////////////////////////////////////
//
// TForm1.Button1Click
//
// OpenDialog anzeigen
//
procedure TForm1.Button1Click(Sender: TObject);
begin
// eigene EventHandler zuweisen
OpenDialog1.OnShow := OpenDlgOnShow;
OpenDialog1.OnClose := OpenDlgOnClose;
// aufrufen
if OpenDialog1.Execute
then
begin
ShowMessage(OpenDialog1.FileName);
end;
end;