function OpenFileDialogCallBack(Wnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): UINT; stdcall; var OpenFileNotify: LPOFNOTIFY; OpenFileName: Windows.POPENFILENAME; DialogRec: POpenFileDialogRec; procedure Reposition(ADialogWnd: Handle); var Left, Top: Integer; ABounds, 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 if (GetParent(ADialogWnd) = Win32WidgetSet.AppHandle) then begin if Screen.ActiveCustomForm <> nil then ABounds := Screen.ActiveCustomForm.Monitor.BoundsRect else if Application.MainForm <> nil then ABounds := Application.MainForm.Monitor.BoundsRect else ABounds := Screen.PrimaryMonitor.BoundsRect; end else ABounds := Screen.MonitorFromWindow(GetParent(ADialogWnd)).BoundsRect; GetWindowRect(ADialogWnd, @DialogRect); Left := (ABounds.Right - DialogRect.Right + DialogRect.Left) div 2; Top := (ABounds.Bottom - DialogRect.Bottom + DialogRect.Top) div 2; SetWindowPos(ADialogWnd, HWND_TOP, Left, Top, 0, 0, SWP_NOSIZE); end; procedure ExtractDataFromNotify(); begin OpenFileName := OpenFileNotify^.lpOFN; DialogRec := POpenFileDialogRec(OpenFileName^.lCustData); UpdateStorage(Wnd, OpenFileName); UpdateFileProperties(OpenFileName); end; 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(Wnd)); end else if uMsg = WM_NOTIFY then begin OpenFileNotify := LPOFNOTIFY(lParam); if OpenFileNotify = nil then Exit; case OpenFileNotify^.hdr.code of CDN_INITDONE: begin ExtractDataFromNotify(); TOpenDialog(DialogRec^.Dialog).DoShow; end; CDN_SELCHANGE: begin ExtractDataFromNotify(); TOpenDialog(DialogRec^.Dialog).DoSelectionChange; end; CDN_FOLDERCHANGE: begin ExtractDataFromNotify(); TOpenDialog(DialogRec^.Dialog).DoFolderChange; end; CDN_TYPECHANGE: begin ExtractDataFromNotify(); DialogRec^.Dialog.IntfFileTypeChanged(OpenFileNotify^.lpOFN^.nFilterIndex); end; end; end; Result := 0; end;