Centering File common item dialogs (MSW)

41 views
Skip to first unread message

dgt

unread,
Sep 4, 2020, 5:20:47 PM9/4/20
to wx-users
Is it possible to center the new-style common item file dialog on Windows and still maintain the new style?

Calling FileDialog::Center() or FileDialog::CenterOnParent() reverts the style of the dialog to the older-style common control dialog instead of the newer common item dialog. This is because calling either of these methods set the m_bMovedWindow flag. This leads to a hook proc being created to handle the centering after the dialog is initialized.

wxFileDialog::ShowModal() has this code:
   if (m_bMovedWindow || HasExtraControlCreator()) // we need these flags. 
    {
        ChangeExceptionPolicy();
        msw_flags |= OFN_EXPLORER |OFN_ENABLEHOOK;
        msw_flags |= OFN_ENABLESIZING;
    }   

The problem line is:
        msw_flags |= OFN_EXPLORER|OFN_ENABLEHOOK;

Anytime OFN_EXPLORER and OFN_ENABLEHOOK  are specified together, Windows reverts to the common control version. This is the best explanation of why that I've found.

If I don't call Center() / CenterOnParent()  then I get the new common item dialogs, but they are displayed at the top-left corner of my parent window. This isn't how the rest of my dialogs behave, but the behavior does seem consistent with the behavior of Visual Studio, MS Word, Excel, Firefox, Chrome, and other apps.

I assume that if they don't center the new dialogs then there's not a way to do it.  Am I correct?

dgt

unread,
Sep 4, 2020, 5:25:36 PM9/4/20
to wx-users
I should clarify that OFN_ENABLEHOOK is required to allow a callback proc to move the dialog after it is initialized.

Vadim Zeitlin

unread,
Sep 4, 2020, 8:41:24 PM9/4/20
to wx-u...@googlegroups.com
On Fri, 4 Sep 2020 14:20:47 -0700 (PDT) dgt wrote:

d> Is it possible to center the new-style common item file dialog on Windows
d> and still maintain the new style?
[...]
d> I assume that if they don't center the new dialogs then there's not a way
d> to do it. Am I correct?

I don't know of a way to do it, but it doesn't mean it doesn't exist. If
you find a reasonable way to do it, please let us know (or even implement a
patch doing it). I can only think of using global hooks, which actually
might be not too bad complexity-wise, but it's a rather blunt instrument.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

dgt

unread,
Sep 12, 2020, 4:36:45 PM9/12/20
to wx-users
I'm not going to put this high on my list to investigate. If MS's applications don't do it then I don't want to start and introduce unexpected behavior in my app.

What I will do is ensure that the position is remembered between uses in the same application instance and when a new instance is started.

Reply all
Reply to author
Forward
0 new messages