当前位置: 软件>C/C++软件
Windows 表格控件 Simple Grid
本文导语: Simple Grid 是一个基于消息的表格控件,是一个纯使用 Windows API (C语言)实现 UI 控件。 示例代码: void LoadGrid4(HWND hGrid) { // // Create image list // INT iImages[] = { IDR_BMP_OFF, IDR_BMP_ON}; HIMAGELIST hImageList ...
Simple Grid 是一个基于消息的表格控件,是一个纯使用 Windows API (C语言)实现 UI 控件。
示例代码:
void LoadGrid4(HWND hGrid) { // // Create image list // INT iImages[] = { IDR_BMP_OFF, IDR_BMP_ON}; HIMAGELIST hImageList = ImageList_Create(32, 32, ILC_COLOR32, NELEMS(iImages), 1); for(int i = 0; i < NELEMS(iImages); ++i){ HBITMAP hbmp = (HBITMAP)LoadImage(ghInstance, MAKEINTRESOURCE(iImages[i]), IMAGE_BITMAP, 32, 32, LR_CREATEDIBSECTION | LR_DEFAULTSIZE); ImageList_Add(hImageList, hbmp, NULL); } // Set Row height to accommodate the graphics SimpleGrid_SetRowHeight(hGrid,34); // // Create Columns // // Column type // Column header text // Optional data (ex: combobox choices) SGCOLUMN lpColumns[] = { GCT_COMBO, _T("Combo Column"), _T("FordChevyZaparozhetsVolkswagenToyotaHondaCitroenFiatVolvo"), GCT_BUTTON, _T("Button Column"), NULL, GCT_IMAGE, _T("Image Column"), hImageList, GCT_LINK, _T("Link Column"), NULL }; // Add the columns for(int k = NELEMS(lpColumns), m = 0; 0 < k; --k, ++m) { SimpleGrid_AddColumn(hGrid, &lpColumns[m]); SimpleGrid_SetColWidth(hGrid, m, 100); } // // Add some rows // for(int i = 0; i < 2; ++i) SimpleGrid_AddRow(hGrid, _T("")); //Don't care about row header text // // Set cells to data // // Column number // Row number // Item (cell) value SGITEM lpItems[] = { // Combo column 0, 0, (LPARAM)_T("Zaparozhets"), 0, 1, (LPARAM)_T("Citroen"), // Button column 1, 0, (LPARAM)_T("#1 On"), 1, 1, (LPARAM)_T("#2 On"), // Image column 2, 0, (LPARAM) 0, 2, 1, (LPARAM) 0, // Link column 3, 0, (LPARAM)_T("The Code Projecthttp:\\www.codeproject.com"), 3, 1, (LPARAM)_T("The Daily WTF: Curious Perversions in " "Information Technologyhttp:\\www.thedailywtf.com"), }; for(int i = 0; i < NELEMS(lpItems); ++i) { SimpleGrid_SetItemData(hGrid, &lpItems[i]); } }