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 » CExtGridWnd Help Collapse All
Subject Author Date
Massimo Germi Dec 12, 2005 - 9:39 AM

/* CExtGridWnd derived class */


I need to display a context menu when the user press right mouse button in a multiselected cell. I’ve tried to override  ..


void CGridSoftware::OnRButtonUp(UINT nFlags, CPoint point)
{
 GetOwner()->SendMessage(WM_RCLICK,point.x,point.y);
 CExtGridWnd::OnRButtonUp(nFlags, point);
}


but multiselection disappears, there is a siple way to do this?


thanks

Technical Support Dec 12, 2005 - 11:45 AM

In some of our projects we used the code below for handling context menus. This code handles the mouse up event and WM_CONTEXTMENU message. It changes the cell focus but not selection.

Header:

virtual void OnShowContextMenu( 
    LONG nColNo,
    LONG nRowNo, 
    CPoint ptTrack
    );
 
virtual bool OnGbwAnalyzeCellMouseClickEvent(
    UINT nChar, // VK_LBUTTON, VK_RBUTTON or VK_MBUTTON only
    UINT nRepCnt, // 0 - button up, 1 - single click, 2 - double click, 3 - post single click & begin editing
    UINT nFlags, // mouse event flags
    CPoint point // mouse pointer in client coordinates
    );
 
...
...
...
 
//{{AFX_MSG(CBaseGridWnd)
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
//}}AFX_MSG


Source:
BEGIN_MESSAGE_MAP(CBaseGridWnd,CExtGridWnd)
    //{{AFX_MSG_MAP(CBaseGridWnd)
    ON_WM_CONTEXTMENU()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
...
...
...
 
void CBaseGridWnd::OnShowContextMenu( 
    LONG nColNo,
    LONG nRowNo, 
    CPoint ptTrack 
    )
{
    nColNo;
    nRowNo;
    ptTrack;
    // show you context menu here
}
 
bool CBaseGridWnd::OnGbwAnalyzeCellMouseClickEvent(
    UINT nChar,
    UINT nRepCnt,
    UINT nFlags,
    CPoint point
    )
{
    ASSERT_VALID( this );
    ASSERT( 0 <= nRepCnt && nRepCnt <= 3 );
    if( CExtGridWnd::OnGbwAnalyzeCellMouseClickEvent(
            nChar,
            nRepCnt,
            nFlags,
            point
            )
        )
        return true;
    if(        nChar == VK_RBUTTON
        &&    nRepCnt == 0 // 0 - button up
        )
    {
        CExtGridHitTestInfo htInfo( point );
        HitTest( htInfo, false, true );
        if(        (!htInfo.IsHoverEmpty()) && htInfo.IsValidRect() 
            &&    htInfo.m_nRowNo >= 0
            &&    (htInfo.m_dwAreaFlags&__EGBWA_INNER_CELLS) != 0
            )
        {
            CPoint ptFocus( htInfo.m_nColNo, htInfo.m_nRowNo );
            SetFocus();
            FocusSet( ptFocus, true, true, false );
 
            CPoint ptTrack( point );
            ClientToScreen( &ptTrack );
 
            OnShowContextMenu( 
                htInfo.m_nColNo,
                htInfo.m_nRowNo, 
                ptTrack 
                );
        }
        return true;
    }
    return false;
}
 
void CBaseGridWnd::OnContextMenu( CWnd * pWnd, CPoint point ) 
{
    LONG nRowNo = SelectionGetLastRowInColumn( 0L );
    if( nRowNo < 0 )
        nRowNo = FocusGet().y;
    if( nRowNo >= 0 )
    {
        CRect rcCell;
        if( GridCellRectsGet(
                0L,
                nRowNo,
                0,
                0,
                &rcCell
                )
            )
        {
            CPoint ptTrack( rcCell.left, rcCell.bottom );
            ClientToScreen( &ptTrack );
            OnShowContextMenu( 
                0L,
                nRowNo,
                ptTrack 
                );        
        }
    }
}