The following class implements a grid window which can lock focus and selection changing and does this when the user clicks on the built-in cell’s check boxes:
class CYourGridWnd : public CExtGridWnd
{
public:
bool m_bLockSelectionSetting:1, m_bLockFocusSetting:1;
CYourGridWnd()
: m_bLockSelectionSetting( false )
, m_bLockFocusSetting( false )
{
}
virtual CPoint FocusSet(
const POINT & ptNewFocus,
bool bEnsureVisibleColumn = true,
bool bEnsureVisibleRow = true,
bool bResetSelectionToFocus = true,
bool bRedraw = true,
bool * p_bCanceled = NULL
)
{
ASSERT_VALID( this );
if( m_bLockFocusSetting )
return FocusGet();
return CExtGridWnd::FocusSet( ptNewFocus, bEnsureVisibleColumn, bEnsureVisibleRow, bResetSelectionToFocus, bRedraw, p_bCanceled );
}
virtual bool SelectionSet(
const RECT & rcNewSelection,
bool bReplaceOldAreas = true,
bool bReplaceLastArea = false,
bool bRedraw = true
)
{
ASSERT_VALID( this );
if( m_bLockSelectionSetting )
return true;
return CExtGridWnd::SelectionSet( rcNewSelection, bReplaceOldAreas, bReplaceLastArea, bRedraw );
}
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
)
{
ASSERT_VALID( this );
CExtGridHitTestInfo htInfo( point );
HitTest( htInfo, false, true );
if( (! htInfo.IsHoverEmpty() )
&& htInfo.IsValidRect()
&& ( htInfo.m_dwAreaFlags & __EGBWA_CELL_CHECKBOX ) != 0
)
m_bLockFocusSetting = m_bLockSelectionSetting = true;
bool bRetVal = CExtGridWnd::OnGbwAnalyzeCellMouseClickEvent( nChar, nRepCnt, nFlags, point );
m_bLockFocusSetting = m_bLockSelectionSetting = false;
return bRetVal;
}
};