64,646
社区成员
发帖
与我相关
我的任务
分享
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
typedef struct
{
char szItemNr[8];
char szItem[32];
char szItemDescription[32];
}Item;
static CREATESTRUCT *cs;
static HWND hWndListView;
static HFONT hFont;
static LV_ITEM lv;
static Item ListItem[3];
static char szColumnHeader[3][12] = {"Number", "Item", "Description"};
int index;
int iiWidth[3];
LV_COLUMN lvC;
RECT rect;
LV_DISPINFO *lvd;
NMHDR *hdr;
cs = (CREATESTRUCT *)lParam;
hFont = CreateFont(11, 0, 0, 0, 500, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_CHARACTER_PRECIS, PROOF_QUALITY,
FF_DONTCARE, "MS SANS SERIF");
hWndListView = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW,
"", WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_SHOWSELALWAYS,
0, 0, 0, 0, hwnd,(HMENU)ID_LISTVIEW, cs->hInstance, NULL);
ListView_SetExtendedListViewStyle(hWndListView, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
iiWidth[0] = 60;
iiWidth[1] = 100;
iiWidth[2] = 400;
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvC.fmt = LVCFMT_LEFT;
for(index = 0; index < 3; index++)
{
lvC.iSubItem = index;
lvC.cx = iiWidth[index];
lvC.pszText = szColumnHeader[index];
ListView_InsertColumn(hWndListView,index,&lvC);
}
// Add some items here
strcpy(ListItem[0].szItemNr, "1");
strcpy(ListItem[0].szItem, "Cat");
strcpy(ListItem[0].szItemDescription, "Pet");
strcpy(ListItem[1].szItemNr, "2");
strcpy(ListItem[1].szItem, "Dog");
strcpy(ListItem[1].szItemDescription, "Pet");
AdjustListView(hWndListView, &lv, index);