The grid can inform its owners about some events, such as addition of a new line, selection or focus changes, etc. The given information is sent in form of WM_NOTIFY message, where one of the structures containing the detailed information about an event is stored in the lParam. For improving grid productivity it is possible to block event sending by calling
CGrid::AllowNotifications() function.
List of available notifications:
The following example demonstrates how to get notications from the grid
1. You have a class that contains the GGrid object
using namespace Dapfor;
class CSomeDialog : public CDialog
{
...
protected:
afx_msg void OnSelectionChanged(NMHDR*, LRESULT*);
afx_msg void OnExpansionChanged(NMHDR*, LRESULT*);
private:
GUI::CGrid m_Grid;
};
BEGIN_MESSAGE_MAP(CSomeDialog, CDialog)
...
ON_NOTIFY(Dapfor::GUI::Notifications::SelectionChanged, IDC_CUSTOM1, OnSelectionChanged)
ON_NOTIFY(Dapfor::GUI::Notifications::ExpansionChanged, IDC_CUSTOM1, OnExpansionChanged)
END_MESSAGE_MAP()
void CSomeDialog::OnSelectionChanged(NMHDR* hdr, LRESULT* lresult)
{
Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
}
void CSomeDialog::OnExpansionChanged(NMHDR* hdr, LRESULT* lresult)
{
Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
}
2. If you have your own control that derives from the grid, you can use the following:
#include <Dapfor/GUI/Grid.h>
class CCustomGrid : public Dapfor::GUI::CGrid
{
protected:
afx_msg void OnLButtonDown(UINT flags, CPoint point);
afx_msg void OnExpansionChanged(NMHDR*, LRESULT*);
DECLARE_MESSAGE_MAP()
};
#include <Dapfor/GUI/Notifications.h>
BEGIN_MESSAGE_MAP(CCustomGrid, Dapfor::GUI::CGrid)
ON_WM_LBUTTONDOWN()
ON_NOTIFY_REFLECT(Dapfor::GUI::Notifications::ExpansionChanged, OnExpansionChanged)
END_MESSAGE_MAP()
void CCustomGrid::OnLButtonDown(UINT flags, CPoint point)
{
CGrid::OnLButtonDown(flags, point);
}
void CCustomGrid::OnExpansionChanged(NMHDR* hdr, LRESULT* lresult)
{
Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
...
}