Excel-Like Headers
GridEx modifies the default Grid row and column headers to closely mimic Excel, and includes the following features:
*Color schemes (Excel Blue, Black, Silver styles and custom)
*Gradient drawing of column headers
*Specific drawing of the top-left cell
*Color change when mouse cursor is over the header
Implementation
Class CGXHeaderExcel derives from existing class CGXHeader and contains new and overridden functions in the files GXHeaderExcel.h, GXHeaderExcel.cpp.
The function CGXHeaderExcel::GetHeaderState() determines the state of the header which is drawn, particularly if it is a row, column or the top-left header. This function reports whether it is pressed (i.e. the row, column or entire grid selected), it has the mouse cursor over it, or if any selected cells are in a contiguous row or column.
The overridden Draw() function draws headers depending on header state and application style chosen while the MFC class CDrawingManager is used for gradient drawing. For example:
 
CDrawingManager dm(*pDC);
dm.FillGradient2(rc,
ExcelHeaderColors[HeaderState],
ExcelHeaderColors[HeaderState+1],90);
The implementation includes the following enumeration in file GXHeaderExcel.h used for header component colors that change with application style or with custom settings:
 
enum enHeaderColor {Row, RowMouse, RowSelected, RowSelectedMouse, RowPressed,
RowPressedMouse, Column, ColumnTop, ColumnMouse,
ColumnMouseTop, ColumnSelected, ColumnSelectedTop,
ColumnSelectedMouse, ColumnSelectedMouseTop, ColumnPressed,
ColumnPressedTop, ColumnPressedMouse, ColumnPressedMouseTop,
ZeroCell, ZeroCellMouse, ZeroCellPressed,
ZeroCellPressedMouse, TopLine, Separator, SeparatorSelected,
SeparatorPressed,ZeroCellTriangle, ZeroCellHighlightBorder,
ZeroCellBorderTop, ZeroCellBorderLeft, ZeroCellBorderRight};
For gradient drawing, two colors for one component are used, such as Column and ColumnTop.
Setting Excel-Style Headers in Grid
Set headers with the following code in function CGXGridCoreEx<T>::InitializeExcel():
 
CGXHeader* pHeader = new CGXHeaderExcel(this);
((CGXStatic*)pHeader)->ImplementCellTips();
RegisterControl(GX_IDS_CTRL_HEADER, pHeader);
ChangeColHeaderStyle(CGXStyle().SetControl(GX_IDS_CTRL_HEADER));
NOTE >> Note: Currently, the Excel-look features do not work separately, so do not exclude anything from function InitializeExcel() to avoid unpredictable behavior.
Color schemes are selected automatically when function CGXGridCoreEx<T>::OnStyleChanged() is called. If the application style is changed from the menu, it is convenient to trap the message WM_APPSTYLE (that is sent from class SFLMDIFrameWndEx implemented in FoundationEx library) and call OnStyleChanged() in its handler.
You can set a custom color for any member of the enumeration enHeaderColor, calling the function SetCustomHeaderColor(enHeaderColor type, COLORREF color), for example:
 
SetCustomHeaderColor(Row, RGB(255,0,0));
User Interaction
Header colors change in following cases:
*When a row or column is selected by clicking on header
*When any cell is selected in a contiguous row or column
*When the mouse cursor hovers over the header or leaves it
Related Samples
Excel-like headers are demonstrated in the sample ExcelGrid.