Simple GridWindows 表格控件

联合创作 · 2023-09-28 02:06

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("Ford\0Chevy\0Zaparozhets\0Volkswagen\0Toyota\0Honda\0Citroen\0Fiat\0Volvo\0"),
        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 Project\0http:\\\\www.codeproject.com\0"),
        3, 1, (LPARAM)_T("The Daily WTF: Curious Perversions in " 
          "Information Technology\0http:\\\\www.thedailywtf.com\0"),
    };

    for(int i = 0; i < NELEMS(lpItems); ++i)
    {
        SimpleGrid_SetItemData(hGrid, &lpItems[i]);
    }

}
浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报