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 Tech Support » dynamic menu items and statusbar Collapse All
Subject Author Date
Ulrich Heinicke Jan 20, 2009 - 2:40 PM

Hi,


i construct my menus dynamically at runtime as you describe it in the feature-article. But i don’t know how to set the text for the statusbar of the menu items. Please tell me how i can do this.


Thanks


 

Ulrich Heinicke Jan 26, 2009 - 2:55 PM

Hi,


i add in mainfrm.cpp the following code:


ON_REGISTERED_MESSAGE(CExtPopupMenuWnd::g_nMsgPrepareMenu, OnExtMenuPrepare)


#define ID_GENERAL_MARKER               32805

#define    ID_START_MENU                    32820



LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)

{

    lParam;

    CExtCmdItem* pCmdItem;



    CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =

        reinterpret_cast < CExtPopupMenuWnd::MsgPrepareMenuData_t * > ( wParam );

    ASSERT( pData != NULL );

    CExtPopupMenuWnd * pPopup = pData->m_pPopup;

    ASSERT( pPopup != NULL );

    INT nReplacePos;

    nReplacePos = pPopup->ItemFindPosForCmdID( ID_GENERAL_MARKER );

    if (nReplacePos >= 0)

    {

        VERIFY( pPopup->ItemRemove(nReplacePos) );

        pCmdItem = g_CmdManager->CmdAllocPtr(g_CmdManager->ProfileNameFromWnd(this->GetSafeHwnd()), ID_START_MENU);

        if(pCmdItem != NULL)

        {

            CString sMoreWindows(_T("Windows..."));

            CString sManageWindows(_T("Manages the currently open windows"));

            pCmdItem->m_sMenuText = sMoreWindows;

            pCmdItem->m_sToolbarText = pCmdItem->m_sMenuText;

            pCmdItem->m_sTipTool = sManageWindows;

            pCmdItem->m_sTipStatus = pCmdItem->m_sTipTool;

            pCmdItem->StateSetBasic( true );



            pPopup->ItemInsert(ID_START_MENU, nReplacePos, __EXT_MFC_SAFE_LPCTSTR(sMoreWindows), NULL, m_hWnd);

        }

        return 1L;

    }

    return 0;

}


When i open the menu a first time i see the menu text



the second time the menu text is missing



Please tell me what’s wrong.


Thanks


 


Technical Support Jan 27, 2009 - 11:38 AM

Please replace the following code:

pCmdItem = g_CmdManager->CmdAllocPtr(g_CmdManager->ProfileNameFromWnd(this->GetSafeHwnd()), ID_START_MENU);
with:
pCmdItem = g_CmdManager->CmdAllocPtr(g_CmdManager->ProfileNameFromWnd(this->GetSafeHwnd()), ID_START_MENU);
            if( pCmdItem == NULL )
                        pCmdItem = g_CmdManager->CmdGetPtr(g_CmdManager->ProfileNameFromWnd(this->GetSafeHwnd()), ID_START_MENU);
The CExtCmdManager::CmdAllocPtr() method returns NULL if the specified command identifier was already allocated.

Ulrich Heinicke Jan 28, 2009 - 3:11 PM

Hi,


i a little wondering why every time i click on the menu the variable nReplacePos is greater or equal 0. The first time i call ItemFindPosForCmdID they can find the ID and the position is ok, but the next time ItemFindPosForCmdID they can’t find it, because i call ItemRemove. So nReplacePos must be invalid, maybe -1, but every time it is 0. I think that’s a bug. Why should i call ItemInsert every time i click on the menu ?

Technical Support Jan 29, 2009 - 12:44 PM

The CExtPopupMenuWnd popup menu in most cases is constructed from a CMenu/HMENU Win32 menu tree. Prof-UIS menus are tree like data structures which use the CExtPopupMenuWnd objects as tree nodes. The CExtPopupMenuWnd trees are data structures which are not based on Win32 menus. The Win32 menus are just used for initialization of Prof-UIS menus and this is very convinient. Your code will find marker command each time you opening menu. It’s often required to replace such marker commands with different set of commands depending from the current application state.


Ulrich Heinicke Jan 29, 2009 - 1:32 PM

So, let me describe what i need: when i start my program it will look for available modules. Then for each of the modules it should add an entry into several menus in the menubar. After that the menus will be fixed. Is there a way to do that with CExtPopuoMenuWnd like i did it before with CMenu?


Thanks

Technical Support Jan 30, 2009 - 3:19 AM

The difference between CExtPopupMenuWnd and CMenu is that the CExtPopupMenuWnd objects always delete themselves automatically when menu is closed. So, you cannot use CExtPopupMenuWnd as CMenu. But your question already contains answer. You can simply modify CMenu which is used by CExtPopupMenuWnd.

Ulrich Heinicke Jan 23, 2009 - 12:20 PM

My program load some plugins and for that i need menu items. But i don’t  know how many menu items need. So it is difficulte to setup a range at program start. It is possible to add a range after initialization? Maybe with a small example?


Thanks


 

Technical Support Jan 26, 2009 - 6:00 AM

The entire range of available commands is in the range of 1...65634. The Visual Studio wizards allocating command identifiers at the beginning of this range. MFC uses pre-defined command identifiers at the end of this range. Prof-UIS defines its internal identifiers in range 29000..310000. We guess all of your plugins need less than 2000 identifiers. You can safely use range like 40000...42000. You can invoke the CExtCmdManager::CmdAllocPtr() method 2000 times at startup for allocating identifiers in the 40000...42000 range. It will not take a long time even if you really need 5000 identifiers or 15000 identifiers

Technical Support Jan 22, 2009 - 12:36 PM

Please use menu items based on the command manager. Your dynamically constructed menu should insert menu commands using the CExtPopupMenuWnd::ItemInsert() method. The command identifiers should be allocated in the command manager using the CExtCmdManager::CmdAllocPtr() method (g_CmdManager->CmdAllocPtr()). You can allocate some range of commands during application initialization and then simply use commands from this range when constructing dynamic popup menus. If you have pre-allocated command identifier, then you can get pointer to the CExtCmdItem object describing properties of this command using the CExtCmdManager::CmdGetPtr()</code> method. The status tip text is stored in properties of the CExtCmdItem object.