在mfc中获取clistbox控件内的鼠标坐标 [英] Getting the mouse coordinates inside clistbox control in mfc

查看:168
本文介绍了在mfc中获取clistbox控件内的鼠标坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我能够处理鼠标移动事件并在对话框上获得鼠标坐标;但是当鼠标在ClistBox内移动时,我无法获得坐标。你可以帮忙吗?



我尝试了什么:



我我在对话框上移动鼠标时能够获得鼠标坐标;但是一旦鼠标进入clistbox控件,我就不会在OnMouseMove函数中得到任何消息();这是预期的。但是,那么我应该如何在列表框上获得鼠标坐标?

Hi,
I am able to handle the mouse move events and get the mouse coordinates on the dialog; but when the mouse moves inside a ClistBox, I am not able to get the coordinates. Could you please help?

What I have tried:

I am able to get the mouse coordinates when I move the mouse on the dialog; but once the mouse enters the clistbox control, I dont get any message in the OnMouseMove function(); that is expected. But, then how am i supposed to get the mouse coordinates on the listbox?

推荐答案

我正在写这个答案,以便其他人可以得到帮助以防其他人面对这个问题。首先要做的事情;您无法直接处理来自Clistbox的鼠标移动消息。因此,您基于ClistBox类创建一个新类,然后在该类中处理OnMouseMove()。然后,在OnMouseMove()函数内,您应该根据鼠标坐标获取clistbox中的项目(如IInspectable所述)。 br />


代码示例;见下文。



I am writing this answer so that others can get help in case some one else is facing this problem. First things first; you can't directly handle mouse move messages from Clistbox. So, you create a new class based on ClistBox class and then handle OnMouseMove() in that class.Then, inside that OnMouseMove() function you should get the item in the clistbox based on the mouse coordinates (as mentioned by IInspectable).

For code example; see below.

BOOL b;
int n = ItemFromPoint(point,b);
CString str;
GetText( n,str);
AfxMessageBox(str);





我想类似的解决方案应该适用于其他控件,如CButton等。

希望,这会有所帮助。



I guess similar solution should work for other controls like CButton etc.
Hope, this helps.


这篇关于在mfc中获取clistbox控件内的鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆