📄 subject_25068.htm
字号:
<p>
序号:25068 发表者:忧河 发表日期:2002-12-18 18:54:47
<br>主题:鼠标点击位置问题!
<br>内容:我在一个对话框里添加了一个ListCtrl ,我想实现在我右键点击列表项的时候,在点击的位置弹出快捷菜单,本想在WM_RBUTTONDOWN 里获取,但是发现它只能获取点击在对话框中空闲区域的,而点击在ListCtrl里并不能响应,不知道有什么方法可以或许其位置?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:songxinye 回复日期:2002-12-18 19:57:20
<br>内容:不要直接使用ListCtrl,用ListCtrl派生你自己的类,在派生类中的WM_RBUTTONDOWN的函数中记录鼠标位置,把这个派生类用在对话框中<BR>class MyListCtrl : public CListCtrl<BR>{<BR>// Construction<BR>public:<BR> MyListCtrl();<BR>public:<BR>// Overrides<BR> // ClassWizard generated virtual function overrides<BR> //{{AFX_VIRTUAL(MyListCtrl)<BR> //}}AFX_VIRTUAL<BR><BR>// Implementation<BR>public:<BR> UINT m_flag;<BR> CPoint m_point;<BR> virtual ~MyListCtrl();<BR><BR> // Generated message map functions<BR>protected:<BR> //{{AFX_MSG(MyListCtrl)<BR> afx_msg void OnLButtonDown(UINT nFlags, CPoint point);<BR> afx_msg void OnRButtonDown(UINT nFlags, CPoint point);<BR> //}}AFX_MSG<BR><BR> DECLARE_MESSAGE_MAP()<BR>};<BR><BR>void MyListCtrl::OnRButtonDown(UINT nFlags, CPoint point) <BR>{<BR>m_point=point; <BR>CListCtrl::OnRButtonDown(nFlags, point);<BR>}<BR><BR>在对话框中使用m_point成员变量
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:lin 回复日期:2002-12-19 08:31:54
<br>内容:许多控件都不支持MOUSE的左、右键操作<BR><BR>但控件的容器肯定支持,添加容器的OnRButtonDown函数,可获得Mouse位置<BR>m_ptMouse=point;<BR>ClientToScreen(&m_ptMouse); //转换成屏幕坐标<BR><BR>在与你的ListCtrl控件所在的rect(CRect)相比较即可<BR>rect.PtInRect(m_ptMouse)<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:忧河 回复日期:2002-12-19 08:49:02
<br>内容:songxinye :您说得方法可以实现,不过我得程序现在更改有点烦琐!不知除此方法是否还有其它得办法?<BR><BR>lin :你说得办法我也试过,但是失败了,因为当其鼠标得位置在ListCtrl中的时候程序根本不响应OnRButtonDown函数。<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -