1、1、MFC窗口中拖放Picture Control
2、
void CSimpleGridSampleDlg::_FillGrid()
{
CWaitCursor wait;
// Create grid tree:
CRect rectClient;
GetClientRect(rectClient);
m_wndGrid.Create(WS_CHILD | WS_VISIBLE, rectClient, this, ID_GRID);
m_wndGrid.EnableColumnAutoSize(TRUE);
m_wndGrid.SetSingleSel(FALSE);
m_wndGrid.EnableGroupByBox(FALSE);
m_wndGrid.SetReadOnly();
m_wndGrid.SetWholeRowSel();
m_wndGrid.EnableHeader(TRUE, BCGP_GRID_HEADER_SORT); // test sorting with sub-items
m_wndGrid.SetRowMarker(FALSE);
m_wndGrid.EnableGridLines(TRUE);
m_wndGrid.EnableTreeLines(TRUE);
m_wndGrid.EnableTreeButtons(TRUE);
m_wndGrid.SetShowDragContext(FALSE);
// Set grid tab order (first):
m_wndGrid.SetWindowPos(&CWnd::wndTop, -1, -1, -1, -1, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// Set grid colors
CBCGPGridColors colors;
colors.m_LeftOffsetColors.m_clrBackground = globalData.clrWindow;
m_wndGrid.SetColorTheme(colors);
m_wndGrid.InsertColumn(0, _T("Name"), 100);
m_wndGrid.InsertColumn(1, _T("Size"), 100);
m_wndGrid.InsertColumn(2, _T("Type"), 100);
m_wndGrid.InsertColumn(3, _T("Date"), 100);
m_wndGrid.InsertColumn(4, _T("Attributes"), 100);
m_wndGrid.SetHeaderAlign(1, HDF_RIGHT);
m_wndGrid.SetColumnAlign(1, HDF_RIGHT);
srand((unsigned)time(NULL));
const int nColumns = m_wndGrid.GetColumnCount();
// Create root item:
CBCGPGridRow* pRoot = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pRoot);
pRoot->AllowSubItems();
pRoot->GetItem(0)->SetValue(_T("My Computer"));
m_wndGrid.AddRow(pRoot, FALSE);
{
//
CBCGPGridRow* pDiskC = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pDiskC);
pDiskC->GetItem(0)->SetValue(_T("My Local Disk (C:)"));
pDiskC->AllowSubItems();
pRoot->AddSubItem(pDiskC, FALSE);
CBCGPGridRow* pFolder1 = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pFolder1);
pFolder1->GetItem(0)->SetValue(_T("Images"));
pFolder1->AllowSubItems();
pDiskC->AddSubItem(pFolder1, FALSE);
CBCGPGridRow* pFolder2 = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pFolder2);
pFolder2->GetItem(0)->SetValue(_T("Music"));
pFolder2->AllowSubItems();
pDiskC->AddSubItem(pFolder2, FALSE);
CBCGPGridRow* pFolder3 = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pFolder3);
pFolder3->GetItem(0)->SetValue(_T("My Project"));
pFolder3->AllowSubItems();
pDiskC->AddSubItem(pFolder3, FALSE);
//
CBCGPGridRow* pUsers = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pUsers);
pUsers->GetItem(0)->SetValue(_T("Users"));
pRoot->AddSubItem(pUsers, FALSE);
//
CBCGPGridRow* pNetwork = m_wndGrid.CreateRow(nColumns);
ASSERT_VALID(pNetwork);
pNetwork->GetItem(0)->SetValue(_T("Network"));
pRoot->AddSubItem(pNetwork, FALSE);
}
m_wndGrid.AdjustLayout();
}
实现的效果图如下: