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 » CExtReportGridWnd::OnReportGridColumnCtxMenuConstruct Collapse All
Subject Author Date
Suhai Gyorgy Aug 1, 2007 - 7:01 AM

Dear Support,

I’ve overriden CExtReportGridWnd::OnReportGridColumnCtxMenuConstruct method to remove some menu items and change the text of the default context menu. But now I need the menu to be resized because of the changes. Please, advise!

I know how to do it with the usage of CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel message, but I’d like to handle this menu inside my ReportGrid-derived class, not in MainFrame (which already handles other popup menus through CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel)

Thank you!

Technical Support Aug 1, 2007 - 11:32 AM

The modified report grid’s context menu should have been resized taking into account its items. Could you send us a screenshot demonstrating the incorrect menu size?

Suhai Gyorgy Aug 2, 2007 - 2:14 AM

I could reproduce the problem in your ReportGird sample. The overriden method is like follows:

bool CChildView::OnReportGridColumnCtxMenuConstruct(
		CExtPopupMenuWnd * pPopup,
		CWnd * pWndSrc,
		CExtReportGridColumn * pRGC,
		DWORD & dwMenuTrackingFlags
		)
{
	if ( !CExtReportGridWnd::OnReportGridColumnCtxMenuConstruct( pPopup, pWndSrc, pRGC, dwMenuTrackingFlags ) )
		return false;
 
	for ( int i = 0; i < pPopup->ItemGetCount(); i++ ) {
		if ( pPopup->ItemGetCmdID(i) == ID_EXT_RG_CTX_SORT_ASCENDING ) {
			pPopup->ItemSetPopupText( i, _T("This is a very long text for testing") );
		}
	}
	return true;
}
Here’s a screenshot.

But after developing further, we added a new command in this popup menu with the following code placed just before the for loop:
	if ( !g_CmdManager->CmdIsRegistered(g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ), ID_GRID_CTX_UNGROUP_ALL) ) {
		CExtCmdItem * pCmdItem = g_CmdManager->CmdAllocPtr(
				g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
				ID_GRID_CTX_UNGROUP_ALL );
		ASSERT( pCmdItem != NULL );
		pCmdItem->m_sMenuText = _T("My Command");
		g_CmdManager->CmdSetup( g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ), *pCmdItem );
	}
	pPopup->ItemInsert(ID_GRID_CTX_UNGROUP_ALL, 6);
This time the popup menu gets resized to the proper size. Screenshot.

Technical Support Aug 2, 2007 - 12:56 PM

Thank you for the detailed description. We have fixed the problem by adding one line of code:

      bool OnReportGridColumnCtxMenuConstruct(
                  CExtPopupMenuWnd * pPopup,
                  CWnd * pWndSrc,
                  CExtReportGridColumn * pRGC,
                  DWORD & dwMenuTrackingFlags
                  )
      {
            if ( !CExtReportGridWnd::OnReportGridColumnCtxMenuConstruct( pPopup, pWndSrc, pRGC, dwMenuTrackingFlags ) )
                  return false;
            for( int i = 0; i < pPopup->ItemGetCount(); i++ )
            {
                  if( pPopup->ItemGetCmdID(i) == /*ID_EXT_RG_CTX_SORT_ASCENDING*/ 30453 )
                  {
                        pPopup->ItemSetPopupText( i, _T("This is a very long text for testing") );
                  }
            }
            pPopup->_SyncItems(); // THIS LINE WAS ADDED
            return true;
      }