1
我的問題與純Win32程序上的Listview 當我刪除該項目,然後單擊它的位置之前刪除項目返回。 所以ListView中不能刪除任何實際項目Listview項目返回後刪除純win32
這個程序和來源:
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#define BTN_DELETE 123
static HWND resList=NULL;
LVITEM LvItem;
LVCOLUMN lvc;
HINSTANCE MainInstance;
HWND Test_FORM;
LRESULT CALLBACK Test_FORM_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
resList= CreateWindow(WC_LISTVIEW,"", WS_CHILD | WS_BORDER | WS_VISIBLE | LVS_REPORT,0,0,700,420,hwnd,(HMENU)666,MainInstance,NULL);
CreateWindow("button", "Delete",WS_VISIBLE | WS_CHILD ,20, 430, 150, 30,hwnd, (HMENU) BTN_DELETE, MainInstance, NULL);
memset(&lvc,0,sizeof(lvc));
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
lvc.iSubItem = 0;
lvc.pszText = "Items";
lvc.cx = 200;
SendMessage(resList,LVM_INSERTCOLUMN,0,(LPARAM)&lvc);
memset(&LvItem,0,sizeof(LvItem));
LvItem.mask=LVIF_TEXT;
LvItem.cchTextMax = 256;
LvItem.iItem=0;
LvItem.iSubItem=0;
LvItem.pszText="Item 0";
SendMessage(resList,LVM_INSERTITEM,0,(LPARAM)&LvItem);
}
break;
case WM_COMMAND: { if(HIWORD(wParam) == BN_CLICKED) { switch(LOWORD(wParam)) { case BTN_DELETE: { ListView_DeleteAllItems(resList); } break; } } } break;
case WM_CLOSE: {DestroyWindow(hwnd); PostQuitMessage(0); } break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MSG Msg;
MainInstance=hInstance;
WNDCLASS ResClass;
ResClass.cbClsExtra = 0;
ResClass.cbWndExtra = 0;
ResClass.hbrBackground = CreateSolidBrush(RGB(45,45,45));
ResClass.hCursor = LoadCursor(NULL,IDC_ARROW);
ResClass.hIcon = NULL;
ResClass.lpszMenuName = NULL;
ResClass.style = 0;
ResClass.hInstance = NULL;
ResClass.lpfnWndProc = Test_FORM_WndProc;
ResClass.lpszClassName = "RES_CL";
RegisterClass(&ResClass);
Test_FORM = CreateWindow("RES_CL","Test",WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,700,500,NULL,0,NULL,NULL);
Test_FORM_WndProc(Test_FORM,WM_CREATE,NULL,NULL);
if(Test_FORM == NULL){return 1;}
while(GetMessage(&Msg,NULL,0,0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
該鏈接不起作用。此外,你不能只在這裏轉儲源並得到答案。詳細解釋*你做了什麼以及如何不起作用。 – 2013-05-07 08:19:02
不過,除非你改進它,否則你的問題將被關閉。它僅僅是開放的,因爲還沒有很多人看到它。耐心的人比我低。 – 2013-05-07 08:22:29
我不明白。 ListView_DeleteAllItems宏刪除所有項目不是單個項目。 – Xearinox 2013-05-07 09:23:01