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 » How to get data in right-clicked row and column? Collapse All
Subject Author Date
Dave M May 6, 2005 - 10:38 AM

I’m trying to implement my context menu by right-clicking on a cell in my grid. To detect the mouse click, I overrode OnGbwAnalyzeCellMouseClickEvent. The "point" parameter has valid data in it, but now I need to convert the mouse coordinates into a row and column in the grid.

I passed point to a CExtGridHitTestInfo object, but when I do this, the m_nRowNo and m_nColNo remain -1. The point coordinates are definitely relative to my grid.

Do you have any idea why I can’t get CExtGridHitTestInfo to work?

Technical Support May 7, 2005 - 10:55 AM

We often use the following abstract code for hit-testing mouse clicks on grid’s data cells:

. . .
CPoint ptClient;
    if( ! ::GetCursorPos( &ptClient ) )
        return;
    wndGrid.ScreenToClient( &ptClient );
CExtGridHitTestInfo htInfo( ptClient );
    wndGrid.HitTest( htInfo, false, false );
INT nColType =
        htInfo.GetInnerOuterTypeOfColumn();
INT nRowType =
        htInfo.GetInnerOuterTypeOfRow();
    if( nColType != 0 || nRowType != 0 )
        return; // not an inner cell clicked
CExtGridCell * pCell =
        GridCellGet( htInfo.m_nColNo, htInfo.m_nRowNo );
. . .
The point parameter in the CExtGridBaseWnd::OnGbwAnalyzeCellMouseClickEvent() virtual method is described in grid’s client coordinates. The point parameter in MFC’s WM_CONTEXTMENU handler method added with Class Wizard is described in screen coordinates and needs to be converted. We guess that the hit-testing problem is caused by some typo in your code.

Dave M May 9, 2005 - 10:44 AM

Hi,

I didn’t have a typo, but I did forget to call HitTest(). Thanks for posting the sample code so I could catch my mistake.

On another note, do you have sample code for creating sub-popup menus dynamically? Every example I’ve seen so far relies on the resource editor to create static popup menus. However, for my context menu, the context menu items are generated based on various cell data in the selected row and column.

Technical Support May 11, 2005 - 10:01 AM

Constructing pop-up menus on the fly is very easy. You need to know only one important thing about command items: by default command items in Prof-UIS pop-up menus are based on the command description data stored in the command manager. There are two methods for inserting command items into pop-up menu. The first is the CExtPopupMenuWnd::ItemInsert() method which is used to insert command items based on the command manager’s data. The second is the CExtPopupMenuWnd::ItemInsertCommand() which is used to insert items without necessity to use the command manager. The CExtPopupMenuWnd::ItemInsertCommand() is handy for creating dynamic menus with sequential ranges of commands. Here is a code snippet that creates and tracks a pop-up menu:

CPoint ptCursor;
    if( ! ::GetCursorPos(&ptCursor) )
        return;
CExtPopupMenuWnd * pPopup =
        new CExtPopupMenuWnd;
    if( ! pPopup->CreatePopupMenu(
            hWndMainFrameOrDialog
            )
        )
    {
        ASSERT( FALSE );
        delete pPopup;
        return;
    }
    if( ! pPopup->ItemInsertCommand(
           1234,
           -1,
           _T("Text on menu item") 
           )
        )
    {
        ASSERT( FALSE );
        delete pPopup;
        return;
    }
    if( ! pPopup->TrackPopupMenu(
            TPMX_DO_MESSAGE_LOOP,
            ptCursor.x,
            ptCursor.y,
            )
        )
    {
        delete pPopup;
        return;
    }

Virendra Mishra May 12, 2005 - 3:16 AM

Hi dear,


   I am creating popup menu using ItemInsert() & ItemInsertCommand() as suggested above but my problem is that how can I attach toottip text and status bar test to these menu item? I tried following but it didn’t work


 


pCmdItem =


g_CmdManager->CmdGetPtr(


pApp->m_pszProfileName,


ID_VIEW_LIKE_OFFICE_2K


);


if( pCmdItem != NULL )


pCmdItem->m_sToolbarText = _T("Switch to MS Office 2000 theme");


 


reason being command manager doesn’t have that command.


Any suggestions please.


Thanks,


virendra

Technical Support May 12, 2005 - 8:31 AM

If a command item is not registered in the command manager, you need to allocate it with g_CmdManager->CmdAllocPtr(). You can use either dynamic command identifiers generated by the command manager or specify your command identifier value.