The CExtGridWnd
class can be configured using four 32-bit styles which can be applied using SiwModifyStyle()
, SiwModifyStyleEx()
, BseModifyStyle()
and BseModifyStyleEx()
methods. Most of these flags are already defined and used. So we have 32x4=128 possible configuration options in the grid control. These style does not cover all the possible settings of the grid window and several behavior improvements can be done by overriding virtual methods or coding grid cell and data provider classes only. This is related to the plain grid control implemented in the CExtGridWnd
class only. We do not discuss tree, report and property grids here.
The number of possible input, validation and of some action events of the CExtGridWnd
class is much greater that the number of its options and styles. We think the virtual methods and replaceable parts coded as new C++ classes are best way to customize the CExtGridWnd
control.
As the mouse click event: it’s typically connected to a click on a grid cell or its part, whichcauses focus and/or selection changing in the grid control, pressing some check box or button in some grid cell with further displaying of popup menu or some modal dialog. Generally, the "how to handle the mouse click in the grid window?" question is enough wide and requires details about particular task. In the easiest case, it’s possible to use the following template class:
template < class _BT > class CMouseEventRedirection : public _BT
{
public:
CWnd * m_pWndTargetForMouseMessagePreTransaltion;
CMouseEventRedirection( CWnd * pWndTargetForMouseMessagePreTransaltion = NULL )
: m_pWndTargetForMouseMessagePreTransaltion( pWndTargetForMouseMessagePreTransaltion )
{
}
virtual BOOL PreTranslateMessage( MSG * pMsg )
{
if( m_pWndTargetForMouseMessagePreTransaltion != NULL
&& pMsg->hwnd == m_hWnd
&& WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST
&& GetSafeHwnd() != NULL
&& pWndTargetForMouseMessagePreTransaltion->PreTranslateMessage( pMsg );
)
return TRUE;
return _BT::PreTranslateMessage( pMsg );
}
};
The
CMouseEventRedirection
template class allows you to pre-translate mouse messages of any window (including
CExtGridWnd
) in any other window which is specified as the
m_pWndTargetForMouseMessagePreTransaltion
property. So, you can use the
CMouseEventRedirection < CExtGridWnd >
template based class in your project instead of the
CExtGridWnd
class type as is:
class CSomeYourDialog : public . . .
{
. . .
public:
CMouseEventRedirection < CExtGridWnd > m_wndGrid;
. . .
Then you should initialize it in the constructor of the
CSomeYourDialog
class:
CSomeYourDialog::CSomeYourDialog( . . . )
{
m_wndGrid.m_pWndTargetForMouseMessagePreTransaltionq = this;
. . .
}
Then you should override the
PreTranslateMessage()
virtual method in a
CSomeYourDialog
class (can be done with Visual C++ wizards) and catch all the grid’s mouse messages in it:
BOOL CSomeYourDialog::PreTranslateMessage( MSG * pMsg )
{
if( pMsg->hwnd == m_wndGrid.m_hWnd
&& WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST
&& m_wndGrid.GetSafeHwnd() != NULL
)
{
. . .
}
. . .
Visual C++ does not support adding user defined and registered window messages into message map of
CWnd
-derived class using some wizard. It support only standard window messages and messages of some common controls like combo box, list box, tree view, list view, etc. So, defining your own grid class or using template based solution described above is the easiest way.