3个回答
展开全部
给你写个CList带删除清空功能的~~~其它你自己改吧
//右键功能
BOOL CTrafRTTDlg::PreTranslateMessage(MSG* pMsg){
CWnd* pWnd = GetDlgItem(IDC_LIST_FILEPATH);
CString strMenuDel, strMenuClear;
if( WM_RBUTTONDOWN == pMsg->message ){
if( pWnd && pWnd->GetSafeHwnd() == pMsg->hwnd){
CMenu menu;
menu.CreatePopupMenu();
strMenuDel.LoadString(IDS_MENU_DELETE);
strMenuClear.LoadString(IDS_MENU_CLEAR);
menu.AppendMenu(MF_STRING,IDR_MENU_LIST_DELETE,strMenuDel);
menu.AppendMenu(MF_STRING,IDR_MENU_LIST_CLEAR,strMenuClear);
CPoint pt;
GetCursorPos(&pt);
DWORD SelectionMade = menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD, pt.x, pt.y, this);
switch(SelectionMade)
{
case IDR_MENU_LIST_DELETE:
OnMenuDelete();
break;
case IDR_MENU_LIST_CLEAR:
OnMenuClear();
break;
default:
break;
}
menu.DestroyMenu();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
//删除当前记录
void CTrafRTTDlg::OnMenuDelete(void)
{
CString strText;
int nSel;
nSel = m_ListFilePath.GetCurSel();
if(nSel > -1){
m_ListFilePath.GetText(nSel, strText);
m_ListFilePath.DeleteString(nSel);
if(strText.CompareNoCase(RTTInf.m_strFilePath) == 0){
RTTInf.m_strFilePath = _T("");
}
}
}
void CTrafRTTDlg::OnMenuClear(void)
{
for(int i = m_ListFilePath.GetCount(); i >= 0; i--){
m_ListFilePath.DeleteString(i);
}
RTTInf.m_strFilePath = _T("");
}
//右键功能
BOOL CTrafRTTDlg::PreTranslateMessage(MSG* pMsg){
CWnd* pWnd = GetDlgItem(IDC_LIST_FILEPATH);
CString strMenuDel, strMenuClear;
if( WM_RBUTTONDOWN == pMsg->message ){
if( pWnd && pWnd->GetSafeHwnd() == pMsg->hwnd){
CMenu menu;
menu.CreatePopupMenu();
strMenuDel.LoadString(IDS_MENU_DELETE);
strMenuClear.LoadString(IDS_MENU_CLEAR);
menu.AppendMenu(MF_STRING,IDR_MENU_LIST_DELETE,strMenuDel);
menu.AppendMenu(MF_STRING,IDR_MENU_LIST_CLEAR,strMenuClear);
CPoint pt;
GetCursorPos(&pt);
DWORD SelectionMade = menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD, pt.x, pt.y, this);
switch(SelectionMade)
{
case IDR_MENU_LIST_DELETE:
OnMenuDelete();
break;
case IDR_MENU_LIST_CLEAR:
OnMenuClear();
break;
default:
break;
}
menu.DestroyMenu();
}
}
return CDialog::PreTranslateMessage(pMsg);
}
//删除当前记录
void CTrafRTTDlg::OnMenuDelete(void)
{
CString strText;
int nSel;
nSel = m_ListFilePath.GetCurSel();
if(nSel > -1){
m_ListFilePath.GetText(nSel, strText);
m_ListFilePath.DeleteString(nSel);
if(strText.CompareNoCase(RTTInf.m_strFilePath) == 0){
RTTInf.m_strFilePath = _T("");
}
}
}
void CTrafRTTDlg::OnMenuClear(void)
{
for(int i = m_ListFilePath.GetCount(); i >= 0; i--){
m_ListFilePath.DeleteString(i);
}
RTTInf.m_strFilePath = _T("");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
BEGIN_MESSAGE_MAP(CStateListCtrl, CWZListCtrl)
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
void CStateListCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags;
int iIndex = HitTest(point,&uFlags);
if (uFlags & LVHT_ONITEMLABEL)
{
SetItem(iIndex, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0);
ASSERT(m_pParentWnd);
m_pParentWnd->SendMessage(WM_LISTCTRL_RCLICK,iIndex,0);
}
}
m_pParentWnd 就是 CMInfoSubCellEditDlg
LRESULT CMInfoSubCellEditDlg::OnRClickListCtrl(WPARAM wParam ,LPARAM lParam)
{
int iIndex = (int)wParam;
if (m_iDyclistFocusItem != -1 && m_iDyclistFocusItem != iIndex)
{
m_listCtrlDynamicCell.SetItemState(m_iDyclistFocusItem,0,LVIS_SELECTED);
}
m_iDyclistFocusItem = iIndex;
AjustButton();
CString strText = _T("");
strText = m_listCtrlDynamicCell.GetItemText(m_iDyclistFocusItem,2);
if (!strText.IsEmpty())
{
CMenu menu;
menu.CreatePopupMenu();
menu.AppendMenu( MF_STRING , ID_MICCEG_MENU_DETACH , _T("右键菜单")) );//
CPoint pt;
GetCursorPos(&pt);
menu.TrackPopupMenu( TPM_LEFTALIGN , pt.x , pt.y , this );
}
return NULL;
}
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
void CStateListCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags;
int iIndex = HitTest(point,&uFlags);
if (uFlags & LVHT_ONITEMLABEL)
{
SetItem(iIndex, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0);
ASSERT(m_pParentWnd);
m_pParentWnd->SendMessage(WM_LISTCTRL_RCLICK,iIndex,0);
}
}
m_pParentWnd 就是 CMInfoSubCellEditDlg
LRESULT CMInfoSubCellEditDlg::OnRClickListCtrl(WPARAM wParam ,LPARAM lParam)
{
int iIndex = (int)wParam;
if (m_iDyclistFocusItem != -1 && m_iDyclistFocusItem != iIndex)
{
m_listCtrlDynamicCell.SetItemState(m_iDyclistFocusItem,0,LVIS_SELECTED);
}
m_iDyclistFocusItem = iIndex;
AjustButton();
CString strText = _T("");
strText = m_listCtrlDynamicCell.GetItemText(m_iDyclistFocusItem,2);
if (!strText.IsEmpty())
{
CMenu menu;
menu.CreatePopupMenu();
menu.AppendMenu( MF_STRING , ID_MICCEG_MENU_DETACH , _T("右键菜单")) );//
CPoint pt;
GetCursorPos(&pt);
menu.TrackPopupMenu( TPM_LEFTALIGN , pt.x , pt.y , this );
}
return NULL;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你自定义的类是集成于哪个类的?每个类都不同的事件响应。
追问
ClistCtrl.主 窗口中 有三个列表控件,现在我一个一个添加事件 是可以响应的。
然后我想弄得简单写 就想到重新写个类,看着清爽点,但是写到POP菜单出来后的响应函数 我添加到 DLG和 自定义的类里 都没有反应了。我想实现 ClistCtrl 的 右击 复制 功能。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询