Cannot center Open File Dialog
From: Matthias Hofmann (hofmann_at_anvil-soft.com)
Date: 03/07/04
- Previous message: anon: "Re: METAFILEPICT question"
- Next in thread: Christian ASTOR: "Re: Cannot center Open File Dialog"
- Reply: Christian ASTOR: "Re: Cannot center Open File Dialog"
- Messages sorted by: [ date ] [ thread ]
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
- Previous message: anon: "Re: METAFILEPICT question"
- Next in thread: Christian ASTOR: "Re: Cannot center Open File Dialog"
- Reply: Christian ASTOR: "Re: Cannot center Open File Dialog"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|