Re: Center a CFileDialog in ATL

Tech-Archive recommends: Fix windows errors by optimizing your registry



I haven't used the class myself, so I can give you only generic
answer pertaining to the raw API as well. In case nobody else
answers, here's what you can do. Install a hook proc before
you open the dialog. Handle WM_INITDIALOG within your hook
proc (you may need to use GetParent - see OFNHookProc
docs) and then manually center the window within its parent.
You can use CWindow::CenterWindow for a CWindow instance
initialized with the dialog's HWND.

To summarize:

case WM_INITDIALOG:
{
HWND hFileDlg = ::GetParent(hWnd); // See OFNHookProc
HWND hParent = ::GetParent(hFileDlg);
CWindow(hFileDlg).CenterWindow(hParent);
}
break;

Note I haven't actually used this code, I simply pieced it together
from the docs...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Steve Turner" <SteveTurner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:76B1ADB9-F11F-41F4-B999-14BDC3007F5C@xxxxxxxxxxxxxxxx
WTL

"Alexander Nickolov" wrote:

ATL doesn't have class named CFileDialog. Are you talking
about WTL or MFC? If the latter - go to the MFC group:

microsoft.public.vc.mfc

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Steve Turner" <SteveTurner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:22A37DE5-188B-4D6E-88A4-4D5929FC9E9A@xxxxxxxxxxxxxxxx
So....no words of wisdom from anybody?

"Steve Turner" wrote:

I have a COM compnent that has a method that displays a CFileDialog.
This is
call is being made in a worker thread, and I have written a function
using
EnumWindows to get a handle to my main application window. Supplying
this
handle to DoModal, or alternatively to the CFileDialog ctor, results
in
the
expected behavior that the dialog is "attached" to the application
window
(and that you can't interact with the application window until this
dailog is
dismissed).

The problem is that the dialog is not centered, and even subclassing
CFileDialog and overriding OnInitDone doesn't solve the problem. It
seems
that no matter what I do, I cannot affect the palcement of this
dialog.

Suggestions?





.



Relevant Pages