Software development libraries on www.maxdz.com
The library allows to create grid with movable and resizable columns, changable title and data background and text colors. No MFC dependencies - the library is WTL/ATL/STL based, therefore small and quick. Due to "C" function interface, the library may be used from C/C++, VisualBasic, etc. For details see function reference and sample applications.
All the functions and constants are defined in the MDZSimpleGrid namespace. You access CreateGrid function for example, as MDZSimpleGrid::CreateGrid. Also you can use the declaration using namespace MDZSimpleGrid; which promotes all library names into the current namespace.
MDZSimpleGrid functions:
|
CreateGrid
|
Creates grid and returns handle on it |
|
CreateGridVB
|
Creates grid and returns handle on it (to use in Visual Basic instead of CreateGrid) |
|
DestroyGrid
|
Destroys grid and releases the corresponding memory. |
|
RecalculateLayout
|
Recalculates grid columns/rows widths/heights, sets scrollings. |
|
SetWindowRect
|
Sets grid window rectangle in coordinates of parent window |
|
AddColumn
|
Adds column to the grid |
|
AddStringData
|
Adds string data to the column |
|
SetColorSchema
|
Sets color schema fro the grid |
|
ChangeColors
|
Opens ColorSchemaDialog allowing to modify grid color schema |
Creates grid and returns handle on it
int CreateGrid(
HWND POINT hWnd, //Handle of containing window
RECT rctWnd, //Grid rectangle in parent window coordinates
int* piGrid //0-based handle on grid returned
);Parameters
hWnd
Handle of containing window
rctWnd
Grid rectangle in parent window coordinates
piGrid
0-based hande on grid returnedReturn Value
ERR_NONE if function succeeds or one of the next error codes:
| ERR_INVALIDPARAM | passed hWnd is 0 |
| ERR_MEMORY | cannot allocate memory for grid |
| ERR_CREATE | cannot create grid window |
Remarks
The function creates new grid and returns it's 0-based handle. The handle must be used in other calls to the grid. Parent window (container of the grid) must provide window handle (HWND). Grid window is child a window with attributes WS_CHILD | WS_VISIBLE | WS_BORDER. Examples
Example 1: Grid creationint iGrid;
if(ERR_NONE!=CreateGrid(m_hWnd,CRect(0,0,100,100),&iGrid))
return false;
// ... do some activities with the grid;
Back to top...
Creates grid and returns handle on it (to use in Visual Basic instead of CreateGrid)
int CreateGridVB(
HWND POINT hWnd, //Handle of containing window
int iLeft, //Left coordinate of grid in parent winow coordinates
int iTop, //Top coordinate of grid in parent winow coordinates
int iRight, //Right coordinate of grid in parent winow coordinates
int iBottom, //Bottom coordinate of grid in parent winow coordinates
int* piGrid //0-based handle on grid
);Parameters
hWnd
Handle of containing window
iLeft
Left coordinate of grid in parent winow coordinates
iTop
Top coordinate of grid in parent winow coordinates
iRight
Right coordinate of grid in parent winow coordinates
iBottom
Bottom coordinate of grid in parent winow coordinates
piGrid
0-based hande on gridReturn Value
ERR_NONE if function succeeds or one of the next error codes:
| ERR_INVALIDPARAM | passed hWnd is 0 |
| ERR_MEMORY | cannot allocate memory for grid |
| ERR_CREATE | cannot create grid window |
Remarks
The function is to use in VisualBasic instead of CreateGrid function. For details see CreateGrid function description.Back to top...
Destroys grid and releases the corresponding memory.
int DestroyGrid(
int iGrid //Handle of grid returned by CreateGrid
);Parameters
iGrid
Handle of grid returned by CreateGridReturn Value
ERR_NONE if the function succeeds or ERR_INVALIDID if iGrid is invalidRemarks
The function destroys the grid accessed by the handle and releases the corresponding memory. Examples
Example 1: Grid destroyingint iGrid;
if(ERR_NONE!=CreateGrid(m_hWnd,CRect(0,0,100,100),&iGrid));
return false;
//... do some activities with the grid
DestroyGrid(iGrid);
Back to top...
Recalculates grid columns/rows widths/heights, sets scrollings.
int RecalculateLayout(
int iGrid //Handle of grid returned by CreateGrid
);Parameters
iGrid
Handle of grid returned by CreateGridReturn Value
ERR_NONE if function succeeds or one of the next error codes:
| ERR_INVALIDID | iGrid is invalid |
| ERR_INVALIDROWNUM | number of rows is different in some columns (must always be the same) |
Remarks
Recalculates grid columns/rows widths/heights, sets scrollings. Must be called after AddColumn,AddStringData functions, otherwise columns will not be correctly positioned. Alternative way to recalculate grid is SetWindowRect function call.Examples
Example 1: Recalculation usageint iGrid;
CreateGrid(hWnd,CRect(0,0,100,100,&iGrid)
AddColumn(iGrid,"Column1");
AddColumn(iGrid,"Column2",100);
AddStringData(iGrid,"Column1","Value1");
AddStringData(iGrid,"Column2","Value2");
RecalculateLayout(iGrid);
Back to top...
Sets grid window rectangle in coordinates of parent window
bool SetWindowRect(
int iGrid, //Handle of grid returned by CreateGrid
RECT rctWnd //Grid rectangle in parent window coordinates
);Parameters
iGrid
Handle of grid returned by CreateGrid
rctWnd
Grid rectangle in parent window coordinatesReturn Value
ERR_NONE if function succeeds or one of the next error codes:
| ERR_INVALIDID | iGrid is invalid |
| ERR_INVALIDROWNUM | number of rows is different in some columns (must always be the same) |
Remarks
Sets grid window rectangle in coordinates of parent window. For example, if grid size and position depends on size of parent (containing) window, you may call the function in the WM_SIZE handler of parent to change size and position of grid.Back to top...
Adds column to the grid
bool AddColumn(
int iGrid, //Handle of grid returned by CreateGrid
const char* pcTitle, //Column title string
int iWidth //Column width
);Parameters
iGrid
Handle of grid returned by CreateGrid
pcTitle
Column title string
iWidth
Column widthReturn Value
ERR_NONE if the function succeeds or one of the next error codes:
| ERR_INVALIDID | iGrid is invalid |
| ERR_INVALIDPARAM | pcTitle is invalid |
| ERR_MEMORY | couldn't allocate memory for column |
Remarks
The function adds column with title pcTitle to the grid. If iWidth is positive or column width changed later during resizing, column width stay fixed. Otherwise, column width will be recalculated depending on column content length. See example for RecalculateLayout function. Back to top...
Adds string data to the column
bool AddStringData(
int iGrid, //Handle of grid returned by CreateGrid
const char* pcTitle, //Title of column to add in
const char* pcData //String to add
);Parameters
iGrid
Handle of grid returned by CreateGrid
pcTitle
Title of column to add in
pcData
String to addReturn Value
ERR_NONE if the function succeeds or one of the next error codes:
| ERR_INVALIDID | iGrid is invalid |
| ERR_INVALIDPARAM | pcTitle is invalid |
| ERR_INVALIDNAME | column with pcTitle title name is not found |
Remarks
Adds string value pcData to the column with pcTitle title. See example for RecalculateLayout functionBack to top...
Sets color schema fro the grid
bool SetColorSchema(
int iGrid, //Handle of grid returned by CreateGrid
ColorSchemaEnum enSchema, //Kind of color schema
COLORREF clrEvenBk, //Even row/column background color
COLORREF clrEvenText, //Even row/column text color
COLORREF clrOddBk, //Odd row/column background color
COLORREF clrOddText, //Odd row/column text color
COLORREF clrTitleBk, //Column title background color
COLORREF clrTitleText //Column title text color
);Parameters
iGrid
Handle of grid returned by CreateGrid
enSchema
Kind of color schema
clrEvenBk
Even row/column background color
clrEvenText
Even row/column text color
clrOddBk
Odd row/column background color
clrOddText
Odd row/column text color
clrTitleBk
Column title background color
clrTitleText
Column title text colorReturn Value
ERR_NONE if the function succeeds or ERR_INVALID if iGrid is invalidRemarks
Sets color schema for the column.
enSchema may be one of CS_FLAT, CS_STRIPE_ROWS, CS_STRIPE_COLUMNS, where:
| CS_FLAT |
clrEvenBk and are used for all cells (clrOddBk, clrOddText are ignored); |
| CS_STRIPE_ROWS |
clrEvenBk,clrEvenText are used for cells of even rows and clrOddBk,clrOddText are used for cells of odd rows |
| CS_STRIPE_COLUMNS |
clrEvenBk,clrEvenText are used for cells of even columns and clrOddBk,clrOddText are used for cells of odd columns. |
clrTitleBk and clrTitleText are used for column title.Back to top...
Opens ColorSchemaDialog allowing to modify grid color schema
bool ChangeColors(
int iGrid //Handle of grid returned by CreateGrid
);Parameters
iGrid
Handle of grid returned by CreateGridReturn Value
ERR_NONE if the function succeeds or ERR_INVALID if iGrid is invalidRemarks
Opens ColorSchemaDialog allowing to modify grid color schema.Back to top...
www.maxdz.com