www.pudn.com > SDK 工具条,分割条,TREE 等控件演示代码.rar > listview.cpp
#include "WinMain.h"
#include "listview.h"
extern HINSTANCE hInst;
HWND CreateListView(HWND hWndParent)
{
HWND hWndListView;
RECT rcl;
InitCommonControls();
GetClientRect(hWndParent,&rcl);
hWndListView = CreateWindow(WC_LISTVIEW,"",WS_CHILD|LVS_REPORT|LVS_EDITLABELS,0,0,rcl.right-rcl.left,rcl.bottom-rcl.top,
hWndParent,NULL,hInst,NULL);
if (hWndListView == NULL)
return NULL;
InitListViewColumns(hWndListView);
}
BOOL InitListViewColumns(HWND hWndListView)
{
char szText[256];
LVCOLUMN lvc;
int iCol;
lvc.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
for (iCol = 0;iCol < 3;iCol++)
{
lvc.iSubItem = iCol;
lvc.pszText = szText;
lvc.cx = 100;
if ( iCol < 2 )
{
lvc.fmt = LVCFMT_LEFT; // left-aligned column
}
else
{
lvc.fmt = LVCFMT_RIGHT; // right-aligned column
}
LoadString(hInst, IDS_FIRSTCOLUMN + iCol,szText, sizeof(szText)/sizeof(szText[0]));
if (ListView_InsertColumn(hWndListView, iCol,&lvc) == -1)
return FALSE;
}
return TRUE;
}