如何获得plyline的鼠标悬停效果。 [英] How to get mousehover effect for plyline.

查看:117
本文介绍了如何获得plyline的鼠标悬停效果。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我通过提供点数和计数来创建多个Ployline。现在我需要在鼠标移过ploylines时显示一条消息。

请帮我在ployline上获取mousemove或mousehover事件。



问候,

Abhishek

Hi,

I have created multiple Ployline by providing point and number of counts. Now I need to display a message whenever the mouse moves over the ploylines.
Please help me to get the the mousemove or mousehover event on ployline.

Regards,
Abhishek

推荐答案

这是一个众所周知的问题:这些行不是控制对象(而不是Window对象) ),所以他们没有消息处理。您需要使用用于渲染线的窗口控件的消息处理。问题相对复杂:您应该在每条线周围建立一个容差区域,并根据从消息 WM_MOUSEMOVE 中获取的鼠标坐标进行命中测试。您应该在这些坐标位于该区域时应用效果。如果不同线条的公差区域相交,则可能需要选择一个。因此,您需要维护行对象的Z顺序(或其他标准)。



这将是您自己做的大量工作。正确的方法可能是这样的:创建一个描述这些对象的纯数据模型,并对模型进行所有计算,以及渲染。当模型被更改时(比如,其中一个对象已经移动,添加等),您需要调用一个覆盖影响区域或矩形的无效函数。当您处理 WM_MOUSEMOVE 或其他鼠标事件时,您应该只从事件处理程序中获取鼠标坐标(状态等),然后对模型执行命中测试和进一步操作。最终,这些事件将导致模型的变化,并最终导致失效;它发送 WM_PAINT 消息,依此类推。



我在过去的回答中描述了它的基础:< a href =http://www.codeproject.com/Answers/618664/MFC-Drawed-lines-is-disappeared#answer1> MFC绘制的线条消失了 [ ^ ]。



-SA
This is a well-known problem: the lines are not control objects (and not Window objects), so they don't have message handling. You need to use message handling of your windowed control used for rendering lines. The problem is relatively complex: you should build a "tolerance region" around each line and do the hit test based on the mouse coordinate taken from the message WM_MOUSEMOVE. You should apply the effect when those coordinate are in that region. If the tolerance regions of different lines intersect, you probably need to select one. Therefore, you need to maintain Z-order (or other criteria) for your line objects.

This would be considerable work you would do by yourself. The right approach to this could be some thing like this: create a pure data model describing those objects and do all calculations on the model, as well as rendering. When model is changed (say, one of the objects has moved, added, etc.), you need to call one of the invalidate functions covering affecting region or rectangle. When you handle WM_MOUSEMOVE or other mouse events, you should only take the mouse coordinate (state, etc) from the event handler and then do the hit test and further actions on the model. Eventually, those events will lead to the change in the model and, ultimately, invalidation; it sends WM_PAINT messages, and so on.

I described the basics of it in my past answer: MFC Drawed lines is disappeared[^].

—SA


这篇关于如何获得plyline的鼠标悬停效果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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