Click here to Skip to main content
15,846,346 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It's a somewhat minor niggle - but whenever I use a resizable IFileDialog (a new "Vista style" CFileDialog) it doesn't open centred in the specified parent window. It looks like it is centring to some default size, but not accounting for the actual size, so it's sort of centred but not quite.

I can resort to stupid IFileDialogEvents hacks to center it after it opens - but they don't always work, depending on where you open to and if there are any files to show there.

Anyone know WHY it doesn't work?

What I have tried:

Centring the dialog 'manually' after it shows - a la this example[^]
Updated 6-Jul-23 23:29pm

1 solution

The IFileDialog interface creates a stand-alone (i.e. modeless) dialog that is not connected to the application's Window. So it will be displayed at whatever position is chosen by the system.

It seems I was wrong, due to an incorrect implementation in my sample code. I have now corrected that and the dialog does display correctly located in the parent window. If The CFileDialog is not doing this then you need to investigate further, in order to see if your implementation is incorrect, or it is a bug in the CFileDialog class.
Share this answer
Kyudos 9-Jul-23 19:32pm    
So is the `CWnd* pParentWnd` in the CFileDialog constructor just for backward compatibility? Is doesn't actually do anything? I would have thought connecting the file dialog to the application which created it would be an inherent part of its functionality?
Richard MacCutchan 10-Jul-23 3:49am    
I need to do some more tests to be sure of what is happening. Are you sure that the code>CFileDialog class uses this interface?

Sorry about the other messages, internet problems.
Kyudos 10-Jul-23 19:33pm    
Yes, particularly if you are using the built-in customisation functions, controlled by the "bVistaStyle" flag in the constructor. As I may not have quite got over in the original post, the dialog does seem to be centred if you leave it at the default size. However, the resizable version remembers its size, so will not be centred if you make it bigger. This may also be affected by my customisation - adding extra controls changes the dialog size also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900