Center Open/Save dialogs on the desktop?

Hi, I have made a DLL for calling in my Delphi application using Dev-CPP which contains the means of accessing the windows explorer style open/save dialogs.

They don't center themselves though, they end up in the top left hand corner...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

uhm... and why dont you call it directly in delphi? you could hook the dialog and then set whatever once you got its handle. if you want i can give an example in delphi
HiImGlenAuthor Commented:
Because it takes up space and ram, I also noticed that even when free'd the dialog still used ram and it wasn't released, so I thought if I did it manually in c++ that wouldn't happen.

But the same behaviour remains, I find it a good idea to contain all the code in a dll though. Dynamically used of course.
hmm... i suspect youre using something else than directly calling GetOpenFileName(). if you can say me how i can test if my pure api calls also take "space and ram" which are never released then i could test if my methods result in the same (propably it wont be enough to watch taskman when opening the dialog and when closing it, right?). in fact i never had memory problems with that.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

HiImGlenAuthor Commented:
Through Delphi as TOpenDialog/TSaveDialog or using API in Delphi and in C++ seems to have no difference, but only as the Task Manager shows, even if it isn't really there it's annoying that it displays it.

I do call a function in my c++ DLL that sets it up for two different opendialogs and executes the api or a save dialog and executes the api.

I know it never centers itself by default though, but I can't find any answers that don't pertain to MFC..........
at least i know how to hook the selectfolder-dialog to resize it according to its calling window and i know the open/save dialogs also support a specific callback hook. i could try to do that in borland builder 5 to do so, or in delphi 5. both things will be pure api calls and will show you how to change the position of the dialog. if you want that - say yes :) otherwise i can spare the work
>>>> They don't center themselves though, they end up in the top left hand corner...

Did you pass the parent's window handle via the OPENFILENAME struct?

If yes, (or if passing the window's  handle doesn't help), you could provide an OFNHookProc hook procedure for an Explorer-style Open dialog box. To enable the hook procedure, set the OFN_EXPLORER and OFN_ENABLEHOOK flags in the Flags member of the OPENFILENAME structure and specify the address of the hook procedure in the lpfnHook member.

The hook procedure has the following prototype:

  HWND hdlg,      // handle to child dialog window
  UINT uiMsg,     // message identifier
  WPARAM wParam,  // message parameter
  LPARAM lParam   // message parameter
If the procedure indicates the WM_INITDIALOG message you might get the parent window by GetParent() and the parent's window rect by GetWindowRect. Then you might move the file dialog's window by calling MoveWindow.

Regards, Alex


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.