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 » Replacing the menu in a dialog with a CExtMenuControlBar Collapse All
Subject Author Date
Adrian M Aug 9, 2005 - 3:48 PM

I have a dialog base MFC app in which I replaced the CDialog with CExtResizableDialog. In the resource editor I specified the id of the menu to be used with the dialog. There is no menu variable in the code - how can I replace the default menu with a CExtMenuControlBar to make the application consitent from a UI standpoint.


Adrian

Technical Support Aug 10, 2005 - 12:48 PM

It is not difficult to initialize the menu bar in your main dialog window and the CMainDlg class in the ProfUIS_Controls sample application demonstrates how to do this. First of all you should drop a custom control resource onto your dialog template resource like the IDC_MAIN_MENUBAR custom control in the IDD_PROFUIS_CONTROLS_DIALOG dialog template resource in the ProfUIS_Controls sample application. Please specify the ProfUIS-ControlBar string as the Class property, the 0x50402034 value as the Style property and zero as the ExStyle property of the custom control. Now you can add the CExtMenuControlBar m_wndMenuBar; member to your dialog class declaration and the DDX_Control(pDX, IDC_MAIN_MENUBAR, m_wndMenuBar); line at the end of the DoDataExchange() methods body. The OnInitDialog() method should initialize the command profile in the command manager and load the menu resource into the menu bar:

CWinApp * pApp = ::AfxGetApp();
    ASSERT( pApp != NULL );
    ASSERT( pApp->m_pszRegistryKey != NULL );
    ASSERT( pApp->m_pszRegistryKey[0] != _T(’\0’) );
    ASSERT( pApp->m_pszProfileName != NULL );
    ASSERT( pApp->m_pszProfileName[0] != _T(’\0’) );
    VERIFY(
        g_CmdManager->ProfileSetup(
            pApp->m_pszProfileName,
            GetSafeHwnd()
            )
        );
    VERIFY(
        g_CmdManager->UpdateFromMenu(
            pApp->m_pszProfileName,
            IDR_MAIN_MENU
            )
        );
    ASSERT( m_wndMenuBar.GetSafeHwnd() != NULL );
    if( ! m_wndMenuBar.LoadMenuBar( IDR_MAIN_MENU ) )
    {
        ASSERT( FALSE );
        return FALSE;
    }


This code assumes that the IDR_MAIN_MENU value is the menu resource identifier for the menu bar. If you don’t need the gripper, please use the following code:
m_wndMenuBar.SetBarStyle( 
        m_wndMenuBar.GetBarStyle() & ~CBRS_GRIPPER 
        );
Finally the OnInitDialog() method should let the menu bar to recompute positions of its buttons and invoke the CWnd::RepositionBars() method to let the menu bar be sticked to the dialog border:
    m_wndMenuBar.SetWindowPos(
        NULL, 0, 0, 0, 0,
        SWP_NOSIZE|SWP_NOMOVE
            |SWP_NOZORDER|SWP_NOOWNERZORDER
            |SWP_FRAMECHANGED
        );
    CWnd::RepositionBars( 0, 0xFFFF, 0 );
If your dialog is enabled for resizing, then you should implement the WM_SIZE message handler like as follows:
void CMainDlg::OnSize( UINT nType, int cx, int cy ) 
{
    CExtResizableDialog::OnSize( nType, cx, cy );
    if( nType != SIZE_MINIMIZED )
        CWnd::RepositionBars(0,0xFFFF,0);
}

Adrian M Aug 10, 2005 - 7:50 PM

That did it.


Thanks!


Adrian