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 » ProfUIS 2.30 - Menu item with check marker Collapse All
Subject Author Date
Gernot Griesser Mar 12, 2005 - 12:48 PM

Hello,


I’ve changed my MenuBar and my ToolBar as descripted at http://www.prof-uis.com/ArticleRead.aspx?AID=220 (Freeware).


I’ve one item in my menu bar with a "check marker". When clicking on this menu item I do the following to show/close another dialog:


void CMainFrame::OnViewCheckentry()
{
CMenu *pMenu = GetMenu();
CMenu *pSubMenu = pMenu->GetSubMenu(2);



UINT state = pSubMenu->GetMenuState(ID_VIEW_CHECKENTRY, MF_BYCOMMAND);


if(state & MF_CHECKED)
{
 pSubMenu->CheckMenuItem(ID_VIEW_CHECKENTRY, MF_UNCHECKED | MF_BYCOMMAND);



 m_pDlg->DestroyWindow();
}
else
{
 pSubMenu->CheckMenuItem(ID_VIEW_CHECKENTRY, MF_CHECKED | MF_BYCOMMAND);


 // create and show dialog here
}
}


When I’m using "CExtMenuControlBar m_wndMenuBar" from ProfUIS and add/replace some code as discripted at http://www.prof-uis.com/ArticleRead.aspx?AID=220 it wouldn’t work.
I get an exception in line "CMenu *pSubMenu = pMenu->GetSubMenu(2);"!?


Another important point: In Office 2003 theme, for example, ProfUIS shows an icon in the menu entry ID_VIEW_CHECKENTRY instead of a "check marker". The icon should be onlny shown in my toolbar.


How should I change my code??


Thanks a lot in advance,
Gernot

Technical Support Mar 12, 2005 - 1:39 PM

You used an incorrect approach to set a check mark for the menu item. The CExtMenuControlBar::GetMenu() method should never be used because it is for internal library use only. Instead, just add the command updating method for the ID_VIEW_CHECKENTRY command like as follows:

ON_UPDATE_COMMAND_UI(
        ID_VIEW_CHECKENTRY,
        OnUpdateViewCheckEntry
        )

    void CMainFrame::OnUpdateViewCheckEntry( CCmdUI * pCmdUI ) 
    {
        pCmdUI->Enable();
        pCmdUI->SetCheck( TRUE );
    }
This sets a check mark for your command both in menus and toolbars. Please note that if the ID_VIEW_CHECKENTRY command has an icon in the command manager, then this icon will be displayed as pressed instead of a check mark.

Gernot Griesser Mar 12, 2005 - 2:37 PM

Thanks for your answer.


Sorry but I don’t know how to get my code working.


For example, I cannot check if the menu entry is checked (GetMenuState isn’t a method of pCmdUI).
Another example: Currently I use the GetMenu() method in void CMyDlg::OnClose() to uncheck the menu item if the window is closed.


It seems that I cannot use your UIS with my application depending on only one "check marker" :-(

Technical Support Mar 13, 2005 - 10:36 AM

Let us explain you some very important things with regard to Windows menus and Prof-UIS menus.

  • Windows context menus are created and tracked with or without the CMenu class of MFC and they are not controlled by the command updating mechanism. You can safely modify menu items in these menus and even use item check mark states and C++ bool variables.
  • Standard Windows menu line, menus displayed by the CExtMenuControlBar window of Prof-UIS and Prof-UIS context menus which are based on the CExtPopupMenuWnd window are fully controlled by the command updating mechanism of MFC and you should never access these menus directly. This is not the correct approach to GUI development with MFC. Your application should exactly know its state and use the MFC command updating mechanism to keep UI items consistent with the current state of the application. You should use this approach even if your application does not use Prof-UIS at all. We believe it is not extremely difficult to make your application fit these requirements.
Besides, please note that Prof-UIS menus provide more features than standard Windows menus. For instance, you can use color pickers in any menus and this feature is absolutely incompatible with standard Windows menus.

Gernot Griesser Mar 14, 2005 - 11:04 AM

Thanks for your help.


I’ve already changed my code.


A last point: How can I access to my main frame menu from another opened (non-modal) dialog without GetMenu()? In CMyDlg::OnClose() I cannot access to the menu with pCmdUI->SetCheck(FALSE).


Is there the possibility to release the CMainFrame::OnUpdateViewMyDlg(CCmdUI *pCmdUI) event in CMyDlg::OnClose()?


Notes: OnUpdateViewMyDlg() has already been implemented. The check status is stored in gMyDlgCheckStatus.


Yours,


Gernot

Technical Support Mar 15, 2005 - 8:21 AM

The MFC command updating mechanism works independently in your dialog and frame windows. The command updating handlers for menu items are invoked immediately before a menu appears on the screen. So, you should not care about menus. The command updating handlers for toolbar buttons are invoked each time when some window state is changed: list box selection, window focus, and etc. If you need to update some toolbar button explicitly, pleaseuse the following code:

CWnd * pTarget = pToolBar->GetOwner();
    if(    pTarget == NULL
        && (!pToolBar->m_bPresubclassDialogMode)
        )
        pTarget = pToolBar->GetParentFrame();
    if( pTarget != NULL )
    {
        BOOL bDisableIfNoHandler = TRUE;
        if( pTarget->IsKindOf( RUNTIME_CLASS(CFrameWnd) ) )
            bDisableIfNoHandler =
                ((CFrameWnd *)pTarget)->m_bAutoMenuEnable;
        int nIndex =
            pToolBar->CommandToIndex(
                ID_OF_TOOLBAR_BUTTON
                );
        CExtBarButton * pTBB =
            pToolBar->GetButton( nIndex );
        ASSERT_VALID( pTBB );
        pTBB->OnUpdateCmdUI(
            pTarget,
            bDisableIfNoHandler,
            nIndex
            );

    }

Gernot Griesser Mar 14, 2005 - 11:15 AM

Or: Is there an UPDATE_COMMAND_UI for OnClose()/WM_CLOSE to get a *pCmdUI?

Technical Support Mar 15, 2005 - 8:22 AM

The command updating mechanism relates to commands -- not to windows messages. The command in this case is a numeric identifier value which is passed in the WPARAM parameter of the WM_COMMAND message. If you want the user to not be able to close your main frame window, just add the command updating handler for the ID_APP_EXIT command and disable it by calling pCmdUI->Enable(FALSE). Besides, you need to disable the SC_CLOSE menu item in the system menu that you can get by calling GetSystemMenu(FALSE) of your main frame window. If the SC_CLOSE system command is disabled, the "X" button on the frame caption is also disabled and grayed. If this is not what you need exactly, feel free to contact us.