HMENU Menu_list,Menu_all; POINT point; HINSTANCE hInstance;
//下面代码放到BOOL WINAPI DialogProc下 case WM_CONTEXTMENU: if((HWND)wParam == GetDlgItem(hWnd,IDC_LIST_VIEW)) { Menu_all=GetSubMenu(Menu_list,0); GetCursorPos(&point);//得到鼠标当前坐标, TrackPopupMenu(Menu_all,TPM_LEFTBUTTON,point.x,point.y,0,hWnd,NULL); } break; //下面的代码放到void OnCommand函数里 case ID_CLA: SendMessage(hWndlist, LVM_DELETEALLITEMS, 0, 0); i=0; break; case ID_DEL: { LVITEM item; item.iItem = SendMessage(hWndlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED); SendMessage(hWndlist,LVM_DELETEITEM,item.iItem,0); i--; } break;
插入一个菜单资源,上面代码中有两个菜单项ID_CLA和ID_DEL。