Using the GridCtrl in a View This article was contributed by Chris Maunder. http://www.codeguru.com/controls/gridctrl_in_view.shtmlThe easiest way as I see it is as follows: Add a member variable of type CGridCtrl* to your view class: CGridCtrl* m_pGrid;Initialise this to NULL in your view class' constructor: CMyView::CMyView { m_pGrid = NULL; }In the CView function OnInitialUpdate, create a new CGridCtrl object if the m_pGrid is not NULL, and then create the CGridCtrl window: CMyView::OnInitialUpdate { CView::OnInitialUpdate(); if (m_pGrid == NULL) // Have we already done this bit? { m_pGridCtrl = new CGridCtrl; // Create the Gridctrl object if (!m_pGridCtrl) return; CRect rect; // Create the Gridctrl window GetClientRect(rect); m_pGridCtrl->Create(rect, this, 100); m_pGridCtrl->SetRowCount(50); // fill it up with stuff m_pGridCtrl->SetColumnCount(10);
// ... etc } }This allows the view to be reused (eg SDI situations). We want the grid to take up the whole of the view's client space, so add a handler to the WM_SIZE message for the view and edit the OnSize function thus: 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. } }Remember to delete the object when you are done: CMyView::~CMyView { if (m_pGrid) delete m_pGrid; }You may want to also add an OnCmdMsg overide to your view class and let the grid control have first go at the messages (this will allow commands such as ID_EDIT_COPY to be wired in automatically: 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; return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }
This article was contributed by Chris Maunder.
http://www.codeguru.com/controls/gridctrl_in_view.shtmlThe easiest way as I see it is as follows: Add a member variable of type CGridCtrl* to your view class:
CGridCtrl* m_pGrid;Initialise this to NULL in your view class' constructor:
CMyView::CMyView
{
m_pGrid = NULL;
}In the CView function OnInitialUpdate, create a new CGridCtrl object if the m_pGrid is not NULL, and then create the CGridCtrl window:
CMyView::OnInitialUpdate
{
CView::OnInitialUpdate(); if (m_pGrid == NULL) // Have we already done this bit?
{
m_pGridCtrl = new CGridCtrl; // Create the Gridctrl object
if (!m_pGridCtrl) return; CRect rect; // Create the Gridctrl window
GetClientRect(rect);
m_pGridCtrl->Create(rect, this, 100); m_pGridCtrl->SetRowCount(50); // fill it up with stuff
m_pGridCtrl->SetColumnCount(10);
// ... etc
}
}This allows the view to be reused (eg SDI situations). We want the grid to take up the whole of the view's client space, so add a handler to the WM_SIZE message for the view and edit the OnSize function thus:
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.
}
}Remember to delete the object when you are done:
CMyView::~CMyView
{
if (m_pGrid)
delete m_pGrid;
}You may want to also add an OnCmdMsg overide to your view class and let the grid control have first go at the messages (this will allow commands such as ID_EDIT_COPY to be wired in automatically:
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; return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
vcmfc,great123,再操冰棍他妈的B----大贱B
vcmfc,great123,冰棍,你妈是我干的!真的!
vcmfc,great123,冰棍,Mda在床上等我,怎么办?
vcmfc,great123,冰棍,Mda叫我晚上去操她!
vcmfc,great123,冰棍,你老妈前几天跟一条狗搞在一起呀!!
vcmfc,great123,冰棍,你老妈前几天被狗操翻了