David Wilkinson
2005-12-29 22:59:48 UTC
Hi all:
Using VC6, and after updating the SDK and setting _WIN32_WINNT to
0x0500, I encountered the OPENFILENAME size problem, and tried replacing
CFileDialog with the CFileDialogST that I found on CodeProject.
After slight modification, it works fine (shows the Places bar), but it
always puts the file dialog top left on the screen. So I added a Window
Hook procedure so I could center the file dialog on my application:
static UINT __stdcall OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam);
implemented as
UINT CFileDialogST::OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam)
{
if(uiMsg == WM_INITDIALOG)
{
ASSERT(::IsWindow(hdlg));
// code
}
return 0;
}
Here I expected hdlg to be the HWND of the open file dialog. But it does
not seem to be. Rather the open file dialog is the parent of hdlg. Why
is this?
The following does what I want, but I do not really understand why:
UINT CFileDialogST::OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam)
{
if(uiMsg == WM_INITDIALOG)
{
ASSERT(::IsWindow(hdlg));
CWnd* pWnd = CWnd::FromHandle(hdlg);
CWnd* pDlg = pWnd->GetParent(); // this is the dialog!!
ASSERT(::IsWindow(pDlg->GetSafeHwnd()));
CRect dlgRect;
pDlg->GetWindowRect(&dlgRect);
CWnd* pMainWnd = AfxGetMainWnd();
ASSERT(::IsWindow(pMainWnd->GetSafeHwnd()));
CRect mainRect;
pMainWnd->GetWindowRect(&mainRect);
CPoint point = mainRect.CenterPoint() - dlgRect.CenterPoint();
dlgRect += CSize(point.x, point.y);
pDlg->MoveWindow(&dlgRect);
}
return 0;
}
TIA,
David Wilkinson
Using VC6, and after updating the SDK and setting _WIN32_WINNT to
0x0500, I encountered the OPENFILENAME size problem, and tried replacing
CFileDialog with the CFileDialogST that I found on CodeProject.
After slight modification, it works fine (shows the Places bar), but it
always puts the file dialog top left on the screen. So I added a Window
Hook procedure so I could center the file dialog on my application:
static UINT __stdcall OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam);
implemented as
UINT CFileDialogST::OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam)
{
if(uiMsg == WM_INITDIALOG)
{
ASSERT(::IsWindow(hdlg));
// code
}
return 0;
}
Here I expected hdlg to be the HWND of the open file dialog. But it does
not seem to be. Rather the open file dialog is the parent of hdlg. Why
is this?
The following does what I want, but I do not really understand why:
UINT CFileDialogST::OfnHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam,
LPARAM lParam)
{
if(uiMsg == WM_INITDIALOG)
{
ASSERT(::IsWindow(hdlg));
CWnd* pWnd = CWnd::FromHandle(hdlg);
CWnd* pDlg = pWnd->GetParent(); // this is the dialog!!
ASSERT(::IsWindow(pDlg->GetSafeHwnd()));
CRect dlgRect;
pDlg->GetWindowRect(&dlgRect);
CWnd* pMainWnd = AfxGetMainWnd();
ASSERT(::IsWindow(pMainWnd->GetSafeHwnd()));
CRect mainRect;
pMainWnd->GetWindowRect(&mainRect);
CPoint point = mainRect.CenterPoint() - dlgRect.CenterPoint();
dlgRect += CSize(point.x, point.y);
pDlg->MoveWindow(&dlgRect);
}
return 0;
}
TIA,
David Wilkinson