Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Subclassing a dialog with a menu Collapse All
Subject Author Date
Jean-Yves Tremblay Apr 29, 2010 - 12:38 PM

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

Technical Support May 4, 2010 - 9:33 AM

The popup menus displayed from the menu bar use the standard MFC’s CCmdUI-based command updating mechanism for controlling enabled / checked / radio states of all the menu’s command items. If there are no command/updating handlers found for particular menu items, such menu items get auto-disabled. The menu command items with system command range identifiers are not auto-disabled. You can simply handle/update your dynamic menu bar’s commands in the OnCmdMsg() virtual method.