希望高手帮我具体讲解ListView的用法,希望有实例。资料也行,用C语言实现。急用,谢谢。
解决方案 »
- 对框框如何调用单文档?(在线等)
- 我是一个实习生帮下忙关系到工作问题。我做一个EXCEL数据导入SQL2000的程序,结果出现IDispatch error #3092
- 心急如焚:一小段代码搞不定了。怎么关闭这样的对话框。
- _Variant_t和_bstr_t这两个类是在哪个头文件里面的?
- 请将3句简单UNIX的程序转换成VC认可的程序
- 为什么线程中无法建立ADO连接实例?求救!
- IC卡操作中以目录名称选择DF时怎么填写??
- 关于用OUTLOOK收发邮件的问题(斑竹手下留情)奇怪的问题
- 求助vs2008使用mscomm控件做串口通讯,在win7下执行的问题
- 用5行代码就让系统重起的帖子怎么找不着了?谁告诉我?加分了!!
- 学了C++如何学习C sharp
- 子类话控件异常
// CreateListView: Creates a list-view control in report view.
// Returns the handle to the new control
// TO DO: The calling procedure should determine whether the handle is NULL, in case
// of an error in creation.
//
// HINST hInst: The global handle to the applicadtion instance.
// HWND hWndParent: The handle to the control's parent window.
//
HWND CreateListView (HWND hwndParent)
{
INITCOMMONCONTROLSEX icex; // Structure for control initialization.
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex); RECT rcClient; // The parent window's client area. GetClientRect (hwndParent, &rcClient); // Create the list-view window in report view with label editing enabled.
HWND hWndListView = CreateWindow(WC_LISTVIEW,
L"",
WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
0, 0,
rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top,
hwndParent,
(HMENU)IDM_CODE_SAMPLES,
g_hInst,
NULL); return (hWndListView);
}// InitListViewColumns: Adds columns to a list-view control.
// hWndListView: Handle to the list-view control.
// Returns TRUE if successful, and FALSE otherwise.
BOOL InitListViewColumns(HWND hWndListView)
{
WCHAR szText[256]; // Temporary buffer.
LVCOLUMN lvc;
int iCol; // Initialize the LVCOLUMN structure.
// The mask specifies that the format, width, text,
// and subitem members of the structure are valid.
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Add the columns.
for (iCol = 0; iCol < C_COLUMNS; iCol++)
{
lvc.iSubItem = iCol;
lvc.pszText = szText;
lvc.cx = 100; // Width of column in pixels. if ( iCol < 2 )
lvc.fmt = LVCFMT_LEFT; // Left-aligned column.
else
lvc.fmt = LVCFMT_RIGHT; // Right-aligned column. // Load the names of the column headings from the string resources.
LoadString(g_hInst,
IDS_FIRSTCOLUMN + iCol,
szText,
sizeof(szText)/sizeof(szText[0])); // Insert the columns into the list view.
if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1)
return FALSE;
}
return TRUE;
} // InsertListViewItems: Inserts items into a list view.
// hWndListView: Handle to the list-view control.
// cItems: Number of items to insert.
// Returns TRUE if successful, and FALSE otherwise.
BOOL InsertListViewItems(HWND hWndListView, int cItems)
{
LVITEM lvI; // Initialize LVITEM members that are common to all items.
lvI.pszText = LPSTR_TEXTCALLBACK; // Sends an LVN_GETDISPINFO message.
lvI.mask = LVIF_TEXT | LVIF_IMAGE |LVIF_STATE;
lvI.stateMask = 0;
lvI.iSubItem = 0;
lvI.state = 0; // Initialize LVITEM members that are different for each item.
for (int index = 0; index < cItems; index++)
{
lvI.iItem = index;
lvI.iImage = index;
// Insert items into the list.
if (ListView_InsertItem(hWndListView, &lvI) == -1)
return FALSE;
} return TRUE;
}