Dear Support,
I extended SubclassChildControls() to subclass dialogs in the same way.
Here is the code that I use :
void SubclassChildControls(HWND hWndParent)
{
...
GetClassName(hWndParent, szClassName,
sizeof(szClassName)/sizeof(szClassName[0]));
//Subclass *THIS* DIALOG
if (_stricmp(szClassName, WC_DIALOG2) == 0) // WC_DIALOG2[] = "#32770";
{
pWndParent = CWnd::FromHandlePermanent(hWndParent);
if (pWndParent == NULL)
{
pWndParent = new CTheDynamicDialog;
pWndParent->SubclassWindow(hWndParent);
}
}
...
}
class CTheDynamicDialog : public CExtNCW < CExtResizableDialog >
{
protected:
CVABExtMenuControlBar m_wndMenuBar;
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void PreSubclassWindow();
virtual void PostNcDestroy()
{
delete this;
}
};
I also wanted to use the prof-uis menu bar if the "unsubclassed" dialog had one :
CTheDynamicDialog::PreSubclassWindow()
{
CExtNCW < CExtResizableDialog >::PreSubclassWindow();
HMENU hMenu = NULL;
CMenu *pOldMenu = NULL;
//Menu deja subclasse
if (::IsWindow(m_wndMenuBar.GetSafeHwnd()))
{
return;
}
//Pas de menu a subclasser
pOldMenu = GetMenu();
if (pOldMenu == NULL)
{
return;
}
SetMenu(NULL);
if (!m_wndMenuBar.Create(NULL, this, 59397, 0x50402034))
{
pOldMenu->DestroyMenu();
return;
}
hMenu = pOldMenu->Detach();
m_wndMenuBar.LoadMenuBar(hMenu);
CWnd::RepositionBars(0,0xFFFF,0);
}
I overrided CExtMenuControlBar::LoadMenuBar() to load an existing HMENU instead
of loading one from resource :
BOOL CVABExtMenuControlBar::LoadMenuBar(HMENU hMenu)
{
if( m_menuDoc.GetSafeHmenu() != NULL )
{
VERIFY( m_menuDoc.DestroyMenu() );
}
if( m_menuFrame.GetSafeHmenu() != NULL )
{
VERIFY( m_menuFrame.DestroyMenu() );
}
if( m_pDockSite != NULL )
{
if ( GetSafeHwnd() == NULL
|| (!::IsWindow(GetSafeHwnd()))
|| m_menuFrame.GetSafeHmenu() != NULL
)
{
ASSERT( FALSE );
return FALSE;
}
}
//~~DC_100402 -->
/*
if( ! g_ResourceManager->LoadMenu( m_menuFrame, nResourceID ) )
{
ASSERT( FALSE );
return FALSE;
}
*/
if (!m_menuFrame.Attach(hMenu))
{
ASSERT(FALSE);
return FALSE;
}
//~~DC_100402 <--
ASSERT( ::IsMenu(m_menuFrame.GetSafeHmenu()) );
if( !g_CmdManager->UpdateFromMenu(
g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
m_menuFrame.GetSafeHmenu()))
{
ASSERT( FALSE );
return FALSE;
}
return _UpdateMenuBar();
}
Until then, all seems to work perfectly but when I click on an item in the menu,
all the sub-items that pop-up are grayed. I suspect that it’s related to the command
manager. I didn’t register any profile with the subclassed dialog since it has one
by default. (I tried to register my own profile, but it makes no difference).
Stangely, the only command that works is ID_APP_EXIT (0xE141)
I also have some predefined commands like ID_FILE_OPEN and ID_FILE_SAVE.
What remains is just custom commands, beginning at 32771
It’s worth noting that the dialog to subclass is created in a dll while the
subclassing take place in the exe side. The dll is loaded via LoadLibrary,
not linked with a lib.
Any suggestion ?
Thanks in advance !
David