Hi,
I would like to subclass the default dialog of a CFileDialog object and its controls.
I use a slightly different version of SubclassAllControlsDynamically :
void SubclassAllControlsDynamically( HWND hWndDialogForm )
{
if( hWndDialogForm == NULL )
return;
if( ! ::IsWindow( hWndDialogForm ) )
return;
static const TCHAR szDialog[] = _T("#32770");
TCHAR szCompare[512] = _T("");
::GetClassName(
hWndDialogForm,
szCompare,
sizeof(szCompare)/sizeof(szCompare[0])
);
// DIALOG
if( ! _tcsicmp( szCompare, szDialog ) )
{
CWnd * pWndDlg = CWnd::FromHandlePermanent( hWndDialogForm );
if( pWndDlg == NULL )
{
class CTheDynamicDialog : public CExtNCW < CExtResizableDialog >
{
virtual LRESULT WindowProc(UINT message,
WPARAM wParam,
LPARAM lParam)
{
if (message == WM_COMMAND)
{
return (*m_pfnSuper)(GetSafeHwnd(), message, wParam, lParam);
}
return CExtNCW < CExtResizableDialog >::WindowProc(message, wParam, lParam);
}
virtual void PostNcDestroy()
{
delete this;
}
};
pWndDlg = new CTheDynamicDialog;
pWndDlg->SubclassWindow( hWndDialogForm );
}
}
HWND hWnd = ::GetWindow( hWndDialogForm, GW_CHILD );
while( hWnd != NULL )
{
[...]
hWnd = ::GetWindow( hWnd, GW_HWNDNEXT );
}
}
I overridded CFileDialog to automatically set proper flags and hook functions :
CVABFileDialog::CVABFileDialog(BOOL bOpenFileDialog,
LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags,
LPCTSTR lpszFilter,
CWnd* pParentWnd,
DWORD dwSize)
: CFileDialog(bOpenFileDialog,
lpszDefExt,
lpszFileName,
dwFlags,
lpszFilter,
pParentWnd,
dwSize)
{
OPENFILENAME& ofn = GetOFN();
ofn.Flags |= OFN_ENABLEHOOK;
if (ofn.Flags & OFN_EXPLORER)
{
ofn.lpfnHook = OFNHookProc;
}
else
{
ofn.lpfnHook = OFNHookProcOldStyle;
}
}
//static
UINT_PTR CALLBACK CVABFileDialog::OFNHookProc(HWND hdlg,
UINT uiMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uiMsg)
{
case WM_INITDIALOG :
CVABExtSubclassHelper::SubclassAllControlsDynamically(hdlg);
break;
}
return FALSE;
}
It seems to subclass correctly. but it crashes just after that.
I suppose I need to override some more in the CTheDynamicXXX classes...
Here is the stack trace :
mfc80d.dll!CPtrArray::GetSize() Line 192 + 0xa bytes
ProfUIS262md.dll!CExtComboBoxBase::LB_ITEM::LbItemCellGetCount() Line 873 + 0xb bytes
ProfUIS262md.dll!CExtComboBoxBase::OnPopupListBoxDrawItem(CDC & dc={...}, const tagRECT & rcItem={...}, const CSize & szExtra={...}, unsigned int nState=0x00001300, const CExtComboBoxBase::LB_ITEM * pLbItem=0x00000004) Line 2203 + 0x8 bytes
ProfUIS262md.dll!CExtComboBoxBase::DrawItem(tagDRAWITEMSTRUCT * lpDIS=0x0012ce7c) Line 2094
mfc80d.dll!CComboBox::OnChildNotify(unsigned int message=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c, long * pResult=0x00000000) Line 213
ProfUIS262md.dll!CExtComboBoxBase::OnChildNotify(unsigned int message=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c, long * pLResult=0x00000000) Line 1229
mfc80d.dll!CWnd::SendChildNotifyLastMsg(long * pResult=0x00000000) Line 2898
mfc80d.dll!CWnd::ReflectLastMsg(HWND__ * hWndChild=0x00050886, long * pResult=0x00000000) Line 2936
mfc80d.dll!CWnd::OnDrawItem(int __formal=0x00000471, tagDRAWITEMSTRUCT * lpDrawItemStruct=0x0012ce7c) Line 1184 + 0xe bytes
mfc80d.dll!CWnd::OnWndMsg(unsigned int message=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c, long * pResult=0x0012cc8c) Line 2133
mfc80d.dll!CWnd::WindowProc(unsigned int message=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c) Line 1741 + 0x20 bytes
mfc80d.dll!AfxCallWndProc(CWnd * pWnd=0x0012e938, HWND__ * hWnd=0x000e0860, unsigned int nMsg=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c) Line 240 + 0x1c bytes
mfc80d.dll!AfxWndProc(HWND__ * hWnd=0x000e0860, unsigned int nMsg=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c) Line 389
mfc80d.dll!AfxWndProcBase(HWND__ * hWnd=0x000e0860, unsigned int nMsg=0x0000002b, unsigned int wParam=0x00000471, long lParam=0x0012ce7c) Line 411 + 0x15 bytes
user32.dll!77d18734()
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]
user32.dll!77d1d05b()
user32.dll!77d1b89b()
user32.dll!77d1b903()
user32.dll!77d39827()
user32.dll!77d39654()
user32.dll!77d373e2()
user32.dll!77d3b476()
user32.dll!77d18734()
user32.dll!77d18816()
user32.dll!77d1c63f()
user32.dll!77d1e905()
mfc80d.dll!CWnd::DefWindowProcA(unsigned int nMsg=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 1029 + 0x20 bytes
mfc80d.dll!CWnd::Default() Line 274
ProfUIS262md.dll!CExtComboBox::OnPaint() Line 2611
mfc80d.dll!CWnd::OnWndMsg(unsigned int message=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000, long * pResult=0x0012d344) Line 2028
mfc80d.dll!CWnd::WindowProc(unsigned int message=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 1741 + 0x20 bytes
ProfUIS262md.dll!CExtComboBoxBase::WindowProc(unsigned int message=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 1559
ProfUIS262md.dll!CExtComboBox::WindowProc(unsigned int message=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 2867
mfc80d.dll!AfxCallWndProc(CWnd * pWnd=0x025be328, HWND__ * hWnd=0x00050886, unsigned int nMsg=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 240 + 0x1c bytes
mfc80d.dll!AfxWndProc(HWND__ * hWnd=0x00050886, unsigned int nMsg=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 389
mfc80d.dll!AfxWndProcBase(HWND__ * hWnd=0x00050886, unsigned int nMsg=0x0000000f, unsigned int wParam=0x00000000, long lParam=0x00000000) Line 411 + 0x15 bytes
user32.dll!77d18734()
user32.dll!77d18816()
user32.dll!77d1b4c0()
user32.dll!77d1b50c()
ntdll.dll!7c91eae3()
user32.dll!77d1d83f()
user32.dll!77d1d82a()
er32.dll!77d31ba1()
user32.dll!77d261c6()
user32.dll!77d26208()
comdlg32.dll!763491f4()
comdlg32.dll!76343236()
mfc80d.dll!CWnd::FromHandle(HWND__ * hWnd=0x0052005f) Line 310
ProfUIS262md.dll!CExtBitmap::Draw(HDC__ * hDC=0x52e80000, int nDstX=0x89fff433, int nDstY=0x7d83f845, int nDstWidth=0x077500f8, int nDstHeight=0x18e9c032, unsigned long dwRop=0x8b000002) Line 2999
ProfUIS262md.dll!CExtPaintManager::stat_HLS_Adjust_Bitmap(HBITMAP__ * hBitmapSrc=, unsigned long clrTransparent=, unsigned long clrTolerance=, double percentH=, double percentL=, double percentS=) Line 34573 + 0x4 bytes
Thanks in advance !
David