From c23094e75a154c736b6d8cbabb6a5292aa19fba1 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 18 Dec 2007 08:00:10 +0000 Subject: [PATCH] win32: Open and Save dialogs will be shown at screen center now (issue #0010432) git-svn-id: trunk@13368 - --- lcl/interfaces/win32/win32wsdialogs.pp | 32 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lcl/interfaces/win32/win32wsdialogs.pp b/lcl/interfaces/win32/win32wsdialogs.pp index 7678cd7fc9..8f596db210 100644 --- a/lcl/interfaces/win32/win32wsdialogs.pp +++ b/lcl/interfaces/win32/win32wsdialogs.pp @@ -33,7 +33,7 @@ uses // To get as little as posible circles, // uncomment only when needed for registration //////////////////////////////////////////////////// - LCLProc, LCLType, Dialogs, Controls, Graphics, SysUtils, Classes, + LCLProc, LCLType, Dialogs, Controls, Graphics, SysUtils, Classes, Forms, //////////////////////////////////////////////////// WSDialogs, WSLCLClasses, Windows, Win32Extra, Win32Int, InterfaceBase, Win32Proc; @@ -142,7 +142,7 @@ function GetOwnerHandle(ADialog : TCommonDialog): HWND; begin with ADialog do begin - if Owner Is TWinControl then + if Owner is TWinControl then Result := TWinControl(Owner).Handle else Result := TWin32WidgetSet(WidgetSet).AppHandle; @@ -235,14 +235,36 @@ end; type TWinFileDialogFunc = function(OpenFile: Windows.LPOPENFILENAME): WINBOOL; stdcall; -function OpenFileDialogCallBack(hwnd : Handle; uMsg : UINT; wParam: WPARAM; - lParam: LPARAM) : UINT; stdcall; +function OpenFileDialogCallBack(hWnd: Handle; uMsg: UINT; wParam: WPARAM; + lParam: LPARAM): UINT; stdcall; + + procedure Reposition(ADialogWnd: Handle); + var + Left, Top: Integer; + DialogRect: TRect; + begin + // Btw, setting width and height of dialog doesnot reposition child controls :( + // So no way to set another height and width at least here + GetWindowRect(ADialogWnd, @DialogRect); + + Left := (GetSystemMetrics(SM_CXSCREEN) - DialogRect.Right + DialogRect.Left) div 2; + Top := (GetSystemMetrics(SM_CYSCREEN) - DialogRect.Bottom + DialogRect.Top) div 2; + SetWindowPos(ADialogWnd, HWND_TOP, Left, Top, 0, 0, SWP_NOSIZE); + end; + var OpenFileNotify: LPOFNOTIFY; OpenFileName: Windows.POPENFILENAME; NeededSize: SizeInt; DialogRec: POpenFileDialogRec; begin + if uMsg = WM_INITDIALOG then + begin + // Windows asks us to initialize dialog. At this moment controls are not + // arranged and this is that moment when we should set bounds of our dialog + Reposition(GetParent(hWnd)); + end + else if uMsg = WM_NOTIFY then begin OpenFileNotify := LPOFNOTIFY(lParam); @@ -284,7 +306,7 @@ begin end; end; end; - Result:= 0; + Result := 0; end; function CreateFileDialogHandle(AOpenDialog: TOpenDialog): THandle;