<< Return to Main Index

< Return to Class Index

class CGXChild

The CGXChild class is an abstract base class.  CGXChild establishes a default control-to-child interface that derived control child classes must implement. CGXChild objects can be added to a CGXControl object and can be used for small buttons (such as the up- and down-arrow buttons in the CGXSpinEdit control).

You should create and add the children in the constructor of your CGXControl-derived class.

The rectangle for the button should be passed to the child object when the control’s OnInitChildren method is called.

See the example for an edit control with a bitmap-button in the cell.

#include <gxall.h>

Example

This example illustrates an edit control with a bitmap-button in the cell.

////////////////////////////////////////////////////////////////////
// CBitmapBtnEdit control

class CBitmapBtnEdit: public CGXEditControl
{
   GRID_DECLARE_CONTROL(CBitmapBtnEdit);

public:
   // Constructor & Destructor
   CBitmapBtnEdit(CGXGridCore* pGrid, UINT nID);
   virtual CRect GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem = NULL, const CGXStyle* pStyle = NULL);

protected:
   virtual void OnInitChildren(ROWCOL nRow, ROWCOL nCol, const CRect& rect);
   virtual void OnClickedButton(CGXChild* pChild);

   // Attributes:
   CGXBitmapButtonChild* m_pButton;
   CSize m_sizeBtn;

   // Generated message map functions
protected:
   //{{AFX_MSG(CBitmapBtnEdit)
   //}}AFX_MSG
   GRID_DECLARE_MESSAGE_MAP()
};

//////////////////////////////////////////////////////////////////////
// CBitmapBtnEdit control

CBitmapBtnEdit::CBitmapBtnEdit(CGXGridCore* pGrid, UINT nID)
   : CGXEditControl(pGrid, nID)
{
   AddChild(m_pButton = new CGXBitmapButtonChild(this));
   VERIFY(m_pButton->LoadBitmaps(IDB_BITMAP1));

   m_sizeBtn = CSize(14,14);
}

BEGIN_MESSAGE_MAP(CBitmapBtnEdit, CGXEditControl)
   //{{AFX_MSG_MAP(CBitmapBtnEdit)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

CRect CBitmapBtnEdit::GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem /* = NULL */, const CGXStyle* pStyle /*= NULL*/)
{
   // compute the interior rectangle for the text
   // without buttons and borders

   CRect rect = CGXEditControl::GetCellRect(nRow, nCol, rectItem, pStyle);

   rect.left += m_sizeBtn.cx+3;

   return rect;
}

void CBitmapBtnEdit:: OnInitChildren(ROWCOL nRow, ROWCOL nCol, const CRect& rect)
{
   nRow, nCol;

   int nTop = (max(0, rect.Height() - m_sizeBtn.cy)) / 2;

   // init BitmapBtn button
   CRect rectBtn;
   rectBtn.IntersectRect(rect,
            CRect(rect.left+3,
               rect.top + nTop,
               rect.left+3+m_sizeBtn.cx,
               rect.top+ nTop + m_sizeBtn.cy)
            );

   m_pButton->SetRect(rectBtn);
}

void CBitmapBtnEdit::OnClickedButton(CGXChild* pChild)
{
   pChild;
   AfxMessageBox("You pressed the bitmap");
};

See Also

CGXControl

CGXChild

Class Members