m_pGridCtrl->SetRowCount(50); // fill it up with stuff
m_pGridCtrl->SetColumnCount(10);
// ... etc
}
}
我们希望网格占据整个视的客户区域,这样,需要添加WM_SIZE消息处理函数:
CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (m_pGrid->GetSafeHwnd()) // Have the grid object and window been created yet?
{
CRect rect;
GetClientRect(rect); // Get the size of the view's client area
m_pGrid->MoveWindow(rect); // Resize the grid to take up that space.
}
}
在析构函数中删除该控件:
CMyView::~CMyView
{
if (m_pGrid)
delete m_pGrid;
}
重载OnCmdMsg函数:
BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
if (m_pGrid && IsWindow(m_pGrid->m_hWnd))
if (m_pGrid->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;