First of all, you should understand the AfxHookWindowCreate()
MFC API:
http://www.microsoft.com/msj/0699/c/c0699.aspx
It will allow you to use Prof-UIS for skinning externally created dialogs and windows. Even Visual Studio’s assertion dialog and .NET Windows Forms windows can be skinned. Here is the example of how we themed the standard Windows Shell’s Browse for Folder dialog:
#ifndef __AFXPRIV_H__
#include <AfxPriv.h>
#endif
. . .
C_Hello_Win_Shell dlgHook;
::AfxHookWindowCreate( &dlgHook );
LPITEMIDLIST pItemList = SHBrowseForFolder( &bi );
::AfxUnhookWindowCreate();
And here is the
C_Hello_Win_Shell
class:
class C_Hello_Win_Shell : public CExtNCW < CExtResizableDialog >
{
public:
CMy_CExtNCSB < CTreeCtrl > m_wndTree;
C_Hello_Win_Shell()
: m_wndTree( true )
{
SetAutoSubclassChildControls();
}
protected:
void _DoFixes()
{
HWND hWnd = ::GetWindow( m_hWnd, GW_CHILD );
for( ; hWnd != NULL; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ) )
{
TCHAR sClassName[ _MAX_PATH + 1 ];
::memset( sClassName, 0, sizeof(sClassName) );
::GetClassName( hWnd, sClassName, _MAX_PATH );
if( m_wndTree.GetSafeHwnd() == NULL )
{
if( _tcsnicmp( sClassName, _T("shBrowseForFolder"), _tcslen( _T("shBrowseForFolder") ) ) == 0 )
{
HWND hWnd2 = ::GetWindow( hWnd, GW_CHILD );
for( ; hWnd2 != NULL; hWnd2 = ::GetWindow( hWnd2, GW_HWNDNEXT ) )
{
TCHAR sClassName[ _MAX_PATH + 1 ];
::memset( sClassName, 0, sizeof(sClassName) );
::GetClassName( hWnd2, sClassName, _MAX_PATH );
if( _tcsicmp( sClassName, _T("SysTreeView32") ) == 0 )
{
m_wndTree.SubclassWindow( hWnd2 );
m_wndTree.ModifyStyle( WS_BORDER, 0, SWP_FRAMECHANGED );
m_wndTree.ModifyStyleEx( WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME, 0, SWP_FRAMECHANGED );
break;
}
}
CWnd::FromHandle( hWnd ) -> ModifyStyle( WS_BORDER, WS_CLIPSIBLINGS|WS_CLIPCHILDREN, SWP_FRAMECHANGED );
CWnd::FromHandle( hWnd ) -> ModifyStyleEx( WS_EX_CLIENTEDGE|WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME, 0, SWP_FRAMECHANGED );
continue;
}
}
if( _tcsicmp( sClassName, _T("scrollbar") ) == 0 )
::ShowWindow( hWnd, SW_HIDE );
}
}
virtual void PreSubclassWindow()
{
__super::PreSubclassWindow();
_DoFixes();
ModifyStyle( 0, WS_CLIPSIBLINGS|WS_CLIPCHILDREN );
PostMessage( (WM_USER+321) );
}
virtual LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
{
if( message == (WM_USER+321) )
{
_DoFixes();
return 0L;
}
LRESULT lr = __super::WindowProc( message, wParam, lParam );
return lr;
}
};
In the most case you need even more simple approach without creating a dialog class:
CExtNCW < CExtResizableDialog > dlgHook;
dlgHook. SetAutoSubclassChildControls();
::AfxHookWindowCreate( &dlgHook );
. . .
// some HWND is created here
. . .
::AfxUnhookWindowCreate();
Please note, you should use the
CExtNCW
template class only with popup window types.