Cannot center Open File Dialog

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Matthias Hofmann (hofmann_at_anvil-soft.com)
Date: 03/07/04

  • Next message: Christian ASTOR: "Re: Cannot center Open File Dialog"
    Date: Sun, 7 Mar 2004 21:30:16 +0100
    
    

    Hello!

    I wrote an application that uses the GetOpenFileName() function to let the
    user load a document. It would be great if the dialog thus created could be
    centered on the screen - however, this turns out to be more difficult than
    you'd think...

    Studying the MSDN Library, I found that specifying a hook procedure and
    centering the window in response to the WM_INITDIALOG message seems to be
    the 'official' way to do it. So I wrote a function that centers the dialog
    on the screen, but this does not work properly on Windows 95 (yes, I know
    that Windows 95 is obsolete and no one cares about it anymore, but I do). To
    be more specific, the call to SetWindowPos() causes parts of the open file
    dialog to be literally cut off when part of the application is outside the
    screen.

    As I found no way to work around this bug I decided to have Windows do the
    job and specify the DS_CENTER style for the open file dialog. The only way
    to accomplish this is to get the dialog's parent in response to the
    WM_INITDIALOG message (the MSDN library states that the open file dialog
    will be a child of the actual dialog created by the call to
    GetOpenFileName()) and add the DS_CENTER style. I was able to verify using
    Spy++ that the DS_CENTER style had actually been set, but unfortunately, the
    whole thing had no effect at all. Apparently the style has to be set on
    creation, it is too late when the dialog proc is entered.

    I have spent hours looking for a solution now, but I start feeling
    deparate - the only thing I can do is not to center the dialog, thus making
    it appear at position 0,0 of the parent's client area.

    Does anyone have an idea what I could do? What is the best way to make the
    open file dialog appear at a decent position on the screen? Other apps (like
    MS VC++) do not seem to have these problems as their dialogs appear as they
    should - I just don't think they'll let me see the source code...

    Best regards,

    Matthias Hofmann


  • Next message: Christian ASTOR: "Re: Cannot center Open File Dialog"

    Relevant Pages

    • change directory when select a MRU file (in any application)
      ... I knew the following function from old Windows NT systems: ... Now you click on the third entry of the MRU list to open the file ... If you use the "open file" function after ... that the active directory in the dialog box is automatically changed to ...
      (microsoft.public.windowsxp.general)
    • Re: Win2003: "Recent" folder Common Open Dialog PAIN!
      ... Locking Down Windows Server 2003 Terminal Server Sessions ... This policy removes the shortcut bar from the Common Open File ...
      (microsoft.public.win2000.termserv.clients)
    • Re: Open File Security Warning
      ... as with admin rights) they get the message, Open File - Security Warning." ... DEP protection which is set to "Turn on DEP for essential Windows programs ...
      (microsoft.public.windowsxp.security_admin)
    • Re: File association
      ... Handle works on Windows 9x/Me and Windows NT and higher. ... Handle is targetted at searching for open file references, ... handles in the system that refer to open files and the names of the files. ... I know nothing about using cmd prompt. ...
      (microsoft.public.windowsxp.basics)
    • VBA 6.0 GetOpenFilename
      ... I have a question to Excel VBA. ... I am using the GetOpenFilename application to open the "open file" ... browser. ...
      (microsoft.public.excel.programming)