Center Open/Save dialogs on the desktop?

Posted on 2006-04-23
Last Modified: 2008-02-01
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...
Question by:HiImGlen
    LVL 12

    Expert Comment

    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

    Author Comment

    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.
    LVL 12

    Expert Comment

    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.

    Author Comment

    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..........
    LVL 12

    Expert Comment

    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
    LVL 39

    Accepted Solution

    >>>> 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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now