ListControl响应右键,弹出菜单

 1 void CTHREADDLG::OnRclickList(NMHDR* pNMHDR, LRESULT* pResult) 
 2 {
 3     //获取鼠标坐标
 4     CPoint ptCurSel(0,0);
 5     GetCursorPos(&ptCurSel);
 6     //转换为当前控件坐标系的坐标
 7     m_ctltThreadList.ScreenToClient(&ptCurSel);
 8     LVHITTESTINFO HitTestInfo;
 9     HitTestInfo.pt = ptCurSel;   
10     //判断坐标命中第几项
11     int nItem = m_ctltThreadList.HitTest(&HitTestInfo);
12     
13     //如果有选中项
14     if (nItem != -1)
15     {
16         //读取选中项内容
17         char szTmp[MAX_PATH];
18         m_ctltThreadList.GetItemText(nItem, 0, szTmp, MAX_PATH);
19         DWORD dwThreadID = strtoul(szTmp, NULL, 10);
20 
21         HMODULE hDll = LoadLibrary("Kernel32.dll");
22         _OPENTHREAD OpenThread = (_OPENTHREAD)GetProcAddress(hDll, "OpenThread");
23         m_hThread = OpenThread(THREAD_ALL_ACCESS, FALSE, dwThreadID);
24 
25         //弹出菜单
26         CMenu menu;
27         menu.LoadMenu(IDR_THREAD_MENU);
28         CPoint point;
29         GetCursorPos(&point);
30         CMenu* pSubMenu = menu.GetSubMenu(0);
31         pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);        
32     }
33     
34     *pResult = 0;
35 }

 

posted @ 2014-09-14 18:34  luzhiyuan  阅读(4398)  评论(0编辑  收藏  举报