问题描述
嗨!
第二天没有任何收获!
请帮忙!
我尝试了一些创建ListView(Tile)的方法,但没有一个成功.
我哪里错了?有人可以给我看示例代码吗?
我使用VS2009,Windows XP(版本comctl dll> 6.0),语言:C ++.
新的Win32项目
我的步骤.
在资源中使用ListView(ID_LISTVIEW1)创建新对话框.
此处代码:
typedef struct tagPETINFO
{
TCHAR szKind [10];
TCHAR szBreed [50];
TCHAR szPrice [20];
} PETINFO;
PETINFO rgPetInfo [] =
{
{TEXT("Dog"),TEXT("Poodle"),TEXT("$ 300.00")}},
{TEXT("Cat"),TEXT("Siamese"),TEXT("$ 100.00")}},
{TEXT("Fish"),TEXT("Angel Fish"),TEXT("$ 10.00")},
};
int APIENTRY _tWinMain(...) {
...
...
//开始对话框
return DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL,MyDialogProc);
}
INT_PTR CALLBACK MyDialogProc(...){
SIZE size = {100,50};
LVTILEVIEWINFO tvi = {0};
LVITEM lvi;
HWND hWndListView;
...
开关(消息){
案例WM_NOTIFY:
开关((((LPNMHDR)lParam)-> code){
情况LVN_GETDISPINFO:
MessageBox(hWnd,"WM_NOTIFY-LVN_GETDISPINFO","msg",MB_OK);
NMLVDISPINFO * plvdi =(NMLVDISPINFO *)lParam;
开关(plvdi-> item.iSubItem){
案例0:
plvdi-> item.pszText = rgPetInfo [plvdi-> item.iItem] .szKind;
break;
情况1:
plvdi-> item.pszText = rgPetInfo [plvdi-> item.iItem] .szBreed;
break;
情况2:
plvdi-> item.pszText = rgPetInfo [plvdi-> item.iItem] .szPrice;
break;
默认值:
break;
}
返回0;
}
...
案例WM_INITDIALOG:
hGIconList = ImageList_Create(32,32,ILC_COLOR8 | ILC_MASK,3,1);
ImageList_AddIcon(hGIconList,LoadIcon(hGInstance,MAKEINTRESOURCE(IDI_ICON_C1))));
ImageList_AddIcon(hGIconList,LoadIcon(hGInstance,MAKEINTRESOURCE(IDI_ICON_C2))));
ImageList_AddIcon(hGIconList,LoadIcon(hGInstance,MAKEINTRESOURCE(IDI_ICON_C3))));
hWndListView = GetDlgItem(hWnd,ID_LISTVIEW1);
ListView_SetImageList(hWndListView,hGIconList,LVSIL_SMALL);
ListView_SetImageList(hWndListView,hGIconList,LVSIL_NORMAL);
break;
案例WM_COMMAND:
开关(LOWORD(wParam)){
案例IDC_CREATE_LIST: //按钮点击事件
hWndListView = GetDlgItem(hWnd,ID_LISTVIEW1);
tvi.cbSize = sizeof(tvi);
tvi.dwMask = LVTVIM_TILESIZE | LVTVIM_COLUMNS;
tvi.dwFlags = LVTVIF_FIXEDSIZE | LVTVIF_EXTENDED;
tvi.sizeTile = size;
tvi.cLines = 2;
ListView_SetTileViewInfo(hWndListView,& tvi);
ListView_SetView(hWndListView,LV_VIEW_TILE);
//添加项目和2个子项目
lvi.cColumns = 3;
lvi.mask = LVIF_IMAGE | LVIF_COLUMNS | LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText =名称";
lvi.iImage = 1;
lvi.iItem = ListView_InsertItem(hWndListView,&lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText =文本1";
ListView_SetItem(hWndListView,&lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 2;
lvi.pszText =文本2";
ListView_SetItem(hWndListView,&lvi);
break;
...
}
Hi!
Second day and no any gain! Just my head in pain!
Please help!!!
I try some ways to create ListView (Tile) and no one success.
Where I wrong? Could anyone show me sample code?
I using VS2009, Windows XP (version comctl dll > 6.0), Language: C++.
New Win32 project
My steps.
Create new dialog with ListView (ID_LISTVIEW1) in resources.
CODE HERE:
typedef struct tagPETINFO
{
TCHAR szKind[10];
TCHAR szBreed[50];
TCHAR szPrice[20];
}PETINFO;
PETINFO rgPetInfo[ ] =
{
{TEXT("Dog"), TEXT("Poodle"), TEXT("$300.00")},
{TEXT("Cat"), TEXT("Siamese"), TEXT("$100.00")},
{TEXT("Fish"), TEXT("Angel Fish"), TEXT("$10.00")},
};
int APIENTRY _tWinMain(...) {
...
...
//Start dialog
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MyDialogProc);
}
INT_PTR CALLBACK MyDialogProc(...) {
SIZE size = {100, 50};
LVTILEVIEWINFO tvi = {0};
LVITEM lvi;
HWND hWndListView;
...
switch (message) {
case WM_NOTIFY:
switch (((LPNMHDR) lParam)->code) {
case LVN_GETDISPINFO:
MessageBox(hWnd, "WM_NOTIFY-LVN_GETDISPINFO", "msg", MB_OK);
NMLVDISPINFO* plvdi = (NMLVDISPINFO*)lParam;
switch (plvdi->item.iSubItem) {
case 0:
plvdi->item.pszText = rgPetInfo[plvdi->item.iItem].szKind;
break;
case 1:
plvdi->item.pszText = rgPetInfo[plvdi->item.iItem].szBreed;
break;
case 2:
plvdi->item.pszText = rgPetInfo[plvdi->item.iItem].szPrice;
break;
default:
break;
}
return 0;
}
...
case WM_INITDIALOG:
hGIconList = ImageList_Create(32, 32, ILC_COLOR8 | ILC_MASK, 3, 1);
ImageList_AddIcon(hGIconList, LoadIcon(hGInstance, MAKEINTRESOURCE(IDI_ICON_C1)));
ImageList_AddIcon(hGIconList, LoadIcon(hGInstance, MAKEINTRESOURCE(IDI_ICON_C2)));
ImageList_AddIcon(hGIconList, LoadIcon(hGInstance, MAKEINTRESOURCE(IDI_ICON_C3)));
hWndListView = GetDlgItem(hWnd, ID_LISTVIEW1);
ListView_SetImageList(hWndListView, hGIconList, LVSIL_SMALL);
ListView_SetImageList(hWndListView, hGIconList, LVSIL_NORMAL);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_CREATE_LIST: // Button click event
hWndListView = GetDlgItem(hWnd, ID_LISTVIEW1);
tvi.cbSize = sizeof(tvi);
tvi.dwMask = LVTVIM_TILESIZE | LVTVIM_COLUMNS;
tvi.dwFlags = LVTVIF_FIXEDSIZE | LVTVIF_EXTENDED;
tvi.sizeTile = size;
tvi.cLines = 2;
ListView_SetTileViewInfo(hWndListView, &tvi);
ListView_SetView(hWndListView, LV_VIEW_TILE);
// Add item and 2 subitems
lvi.cColumns = 3;
lvi.mask = LVIF_IMAGE | LVIF_COLUMNS | LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = "Name";
lvi.iImage = 1;
lvi.iItem = ListView_InsertItem(hWndListView, &lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
lvi.pszText = "Text 1";
ListView_SetItem(hWndListView, &lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 2;
lvi.pszText = "Text 2";
ListView_SetItem(hWndListView, &lvi);
break;
...
}
推荐答案
这篇关于ListView-平铺视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!