作者共发了6篇帖子。 内容转换:不转换▼
 
点击 回复
405 5
ListView控件的平铺视图研究进度
一派护法 十九级
1楼 发表于:2015-12-5 21:43
目前已经实现了5个视图的互相切换,但是平铺视图还只能显示32x32的图标。
灰色的详细信息还未能显示。
一派护法 十九级
2楼 发表于:2015-12-5 21:44

Details视图目前还只能显示第一列。
一派护法 十九级
3楼 发表于:2015-12-5 21:45
核心代码备份:
【头文件 Dlg1.h】
void Dlg1_Show(HINSTANCE hInst, HWND hWnd);
INT_PTR CALLBACK Dlg1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void Dlg1_Init(HWND hDlg);
void Dlg1_UpdateView(int view);
【源文件 Dlg1.cpp】
#include "stdafx.h"
#include <Windows.h>
#include <Commctrl.h>
#include "resource.h"
#include "Dlg1.h"

struct
{
    HWND hListBox;
    HWND hRadio1;
    HWND hRadio2;
    HWND hRadio3;
    HWND hRadio4;
    HWND hRadio5;
} ctrls;

void Dlg1_Show(HINSTANCE hInst, HWND hWnd)
{
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Dlg1);
}

INT_PTR CALLBACK Dlg1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        Dlg1_Init(hDlg);
        return (INT_PTR)TRUE;
    case WM_COMMAND:
        wmId = LOWORD(wParam);
        wmEvent = LOWORD(wParam);
        switch (wmId)
        {
        case IDOK:
        case IDCANCEL:
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        case IDC_RADIO1:
            Dlg1_UpdateView(LV_VIEW_ICON);
            break;
        case IDC_RADIO2:
            Dlg1_UpdateView(LV_VIEW_SMALLICON);
            break;
        case IDC_RADIO3:
            Dlg1_UpdateView(LV_VIEW_LIST);
            break;
        case IDC_RADIO4:
            Dlg1_UpdateView(LV_VIEW_DETAILS);
            break;
        case IDC_RADIO5:
            Dlg1_UpdateView(LV_VIEW_TILE);
            break;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

void Dlg1_Init(HWND hDlg)
{
    LV_COLUMN lvc;
    LV_ITEM lvi;
    HINSTANCE hShellInst;
    int i, len;
    HIMAGELIST hImgListSm, hImgListLg;
    HICON hIcon;

    SIZE size = {200, 50};
    LVTILEVIEWINFO tileViewInfo;

    LPWSTR columnNames[] = {L"Name", L"Price", L"Number", L"Available"};
    const int columnSizes[] = {230, 80, 80, 80};
    LPWSTR itemNames[] = {L"Computer", L"Printer", L"Trash", L"Magnifier", L"Lock", L"Hard Drive", L"Scissors", L"Floppy", L"Picture Frame", L"Noteboard", L"Fax", L"Tray", L"Camera", L"CD", L"TF Card"};
    const int itemImageIds[] = {16, 17, 32, 23, 48, 166, 16762, 16761, 63001, 16763, 1005, 327, 309, 302, 307};

    ctrls.hListBox = GetDlgItem(hDlg, IDC_LIST1);
    ctrls.hRadio1 = GetDlgItem(hDlg, IDC_RADIO1);
    ctrls.hRadio2 = GetDlgItem(hDlg, IDC_RADIO2);
    ctrls.hRadio3 = GetDlgItem(hDlg, IDC_RADIO3);
    ctrls.hRadio4 = GetDlgItem(hDlg, IDC_RADIO4);
    ctrls.hRadio5 = GetDlgItem(hDlg, IDC_RADIO5);

    // Init view
    tileViewInfo.cbSize = sizeof(tileViewInfo);
    tileViewInfo.dwFlags = LVTVIF_FIXEDSIZE;
    tileViewInfo.dwMask = LVTVIM_COLUMNS | LVTVIM_TILESIZE;
    tileViewInfo.cLines = 2; // Maximum number of text lines in each item label, not counting the title
    tileViewInfo.sizeTile = size; // Size of an individual tile
    ListView_SetTileViewInfo(ctrls.hListBox, &tileViewInfo);
    SendMessage(ctrls.hRadio5, BM_SETCHECK, BST_CHECKED, NULL);
    Dlg1_UpdateView(LV_VIEW_TILE);

    // Add columns
    lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
    len = sizeof(columnSizes) / sizeof(int);
    for (i = 0; i < len; i++)
    {
        lvc.iSubItem = i;
        lvc.pszText = columnNames[i];
        lvc.cx = columnSizes[i];
        lvc.fmt = LVCFMT_LEFT;
        ListView_InsertColumn(ctrls.hListBox, i, &lvc);
    }

    // Create ImageList
    hImgListSm = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 1, 0);
    hImgListLg = ImageList_Create(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), ILC_COLOR32, 1, 0);
    hShellInst = GetModuleHandle(L"shell32.dll");
    len = sizeof(itemImageIds) / sizeof(int);
    for (i = 0; i < len; i++)
    {
        hIcon = LoadIcon(hShellInst, MAKEINTRESOURCE(itemImageIds[i]));
        ImageList_AddIcon(hImgListLg, hIcon);
        ImageList_AddIcon(hImgListSm, hIcon);
        DestroyIcon(hIcon);
    }
    ListView_SetImageList(ctrls.hListBox, hImgListLg, LVSIL_NORMAL);
    ListView_SetImageList(ctrls.hListBox, hImgListSm, LVSIL_SMALL);

    // Add items
    lvi.mask = LVIF_IMAGE | LVIF_TEXT;
    lvi.iSubItem = 0;
    for (i = 0; i < len; i++)
    {
        lvi.pszText = itemNames[i];
        lvi.iImage = i;
        lvi.iItem = i;
        ListView_InsertItem(ctrls.hListBox, &lvi);
    }
}

void Dlg1_UpdateView(int view)
{
    ListView_SetView(ctrls.hListBox, view);
}
【主cpp源文件(部分)】
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    LPCWSTR welcomeStr = L"Welcome to Arslanbar!";
    LPCWSTR str2 = L"Please double-click to open the dialog...";

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        case ID_FILE_SHOWITEMS:
        case ID_ACCELERATOR32772:
            Dlg1_Show(hInst, hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        TextOut(hdc, 4, 4, welcomeStr, wcslen(welcomeStr));
        TextOut(hdc, 4, 20, str2, wcslen(str2));
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_LBUTTONDBLCLK:
        Dlg1_Show(hInst, hWnd);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
一派护法 十九级
4楼 发表于:2015-12-5 21:50

选择框还未变成蓝色实心矩形框。
一派护法 十九级
5楼 发表于:2015-12-5 21:52

一派护法 十九级
6楼 发表于:2015-12-5 21:53

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:405 回复数:5
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2015-12-5 21:53
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。