You can't use this code directly for Lazarus/FPC
Your code is tightly bind to the way Delphi processes the Windows Common DialogBoxes; but this is different for Lazarus.
Just as a proof of concept, modifying and simplifying your code gives an acceptable result for very basic programs (i.e. for very simple forms and applications).
In TAwCommonDialog.HookProc, modify as indicated:
// Parent := GetWindowLong(FDialog.Handle, GWL_HWNDPARENT);
// if ((Data.hwnd = FDialog.Handle) and (Parent = Application.MainForm.Handle)) or
// ((Data.hwnd = FDialog.Handle) and (FDialog is TFindDialog)) or
// (Data.hwnd = Parent) then
Parent := GetWindowLong(Data.hWnd, GWL_HWNDPARENT);
if (Parent <> 0) and (Parent = FCenterWnd) then
This is only for demonstration purposes and certainly not a definitive solution (several controls have been removed, which makes this code not a general one).
A very simple approach would be to modify the LCL code to comply to your needs (or eventually to make and use your own Dialogs controls by overwriting the current ones).
Apparently, currently DialogBoxes are always centered relatively to the screen with Lazarus, not to the owner form: see "Reposition" function in "win32wsdialogs.pp"
** Edit ** BTW, you don't need to add the "win32int" unit in your "uses" clause if you're not using any windows widegset objects or classes (which is the case or your second sample code).