Forum > Win32/64

Center OpenDialog To Parent Form Windows XP

(1/2) > >>

guitarmang:
Hi,
Just wanted to thank everyone that's answered my questions so far about dialogs. This is a great community.

I have one more question. I have some older Delphi code that works well to center dialogs to the parent form. I'm using Lazarus version 1.2.6, and I'm on Windows XP, and trying to center the explorer type opendialog(not the of oldstyle). I've used the Lazarus tool to convert the Delphi project to Lazarus. I'm stuck with trying to fix a couple of functions. Here's some code.

--- Code: ---function GetTopWindow: HWND;
begin
  Result := GetLastActivePopup(Application.Handle);
  if (Result = Application.Handle) or not IsWindowVisible(Result) then
    Result := Screen.ActiveCustomForm.Handle;
end;
--- End code ---


--- Code: ---function TAwCommonDialog.Execute: Boolean;
begin
  try
    Application.NormalizeAllTopMosts;
    FHookProc := MakeHookInstance(HookProc);
    FWndHook := SetWindowsHookEx(WH_CALLWNDPROCRET, FHookProc, 0,
      GetCurrentThreadID);
    Result := FDialog.Execute;
  finally
    if FWndHook <> 0 then
      UnhookWindowsHookEx(FWndHook);
    if FHookProc <> nil then
      FreeHookInstance(FHookProc);
    Application.RestoreTopMosts;
  end;
end;
--- End code ---

Would it be possible to get this code working in Lazarus?

Any help would be greatly appreciated.
Thanks, Wyatt

Here's the Delphi project that I converted. See Attached.


ChrisF:
A first possible correction...

Once Application and MainForm have been created:

--- Code: ---Application.Handle  -->  Application.MainForm.Handle

--- End code ---

And if it's not enough, for a windows program only (this solution is not recommended, and may eventually not work):

--- Code: ---uses
   ..., Win32Int;

Application.Handle  -->  Win32WidgetSet.AppHandle

--- End code ---


** Edit **  For the rest, are NormalizeAllTopMosts/RestoreTopMosts really necessary ?

guitarmang:

--- Quote from: ChrisF on December 05, 2014, 11:26:40 pm ---A first possible correction...

Once Application and MainForm have been created:

--- Code: ---Application.Handle  -->  Application.MainForm.Handle

--- End code ---

And if it's not enough, for a windows program only (this solution is not recommended, and may eventually not work):

--- Code: ---uses
   ..., Win32Int;

Application.Handle  -->  Win32WidgetSet.AppHandle

--- End code ---


** Edit **  For the rest, are NormalizeAllTopMosts/RestoreTopMosts really necessary ?

--- End quote ---

Thanks for the reply.

I tried what you recommended, and it compiles, but the dialog doesn't center to the form.
Thanks for trying.
Wyatt

guitarmang:
Here's another attached project for a test.
I commented out the NormalizeAllTopMosts and RestoreTopMosts, and replaced Application.Handle with Application.MainForm.Handle.

Thanks again for trying.



typo:
You could try to make a feature request on BugTracker.

Navigation

[0] Message Index

[#] Next page

Go to full version