delphi 应用程序工厂_Delphi应用程序中的高级鼠标处理

delphi 应用程序工厂

You might already know how to handle some basic mouse events like MouseUp/MouseDown and MouseMove. However, there are times when you want your mouse to do what you tell it.

您可能已经知道如何处理一些基本的鼠标事件,例如MouseUp / MouseDown和MouseMove。 但是,有时您希望鼠标执行您所告诉的操作。

“基本” API内容 ( 'Basic' API stuff )

Many of us write programs that are designed to work only with the mouse. If we are writing programs that require mouse presence and/or are dependent on the mouse we have to be sure that various things are set up the right way.

我们中许多人编写的程序只能与鼠标一起使用。 如果我们正在编写需要鼠标存在和/或依赖于鼠标的程序,则必须确保以正确的方式设置了各种内容。

鼠标存在吗? ( Is Mouse Present? )

The quickest way to see if the mouse is present:

查看鼠标是否存在的最快方法:

动画鼠标光标 ( Animated Mouse Cursor )

Here's how to use animated cursors (or even how to use a BMP as a CUR):

这是使用动画光标的方法(或什至如何将BMP用作CUR):

定位鼠标 ( Positioning the Mouse )

The SetCursorPos API function moves the cursor to the specified screen coordinates. Since this function does not get a windows handle as a parameter, x/y have to be screen coordinates. Your component does use relative coordinates, e.g. relative to a TForm. You have to use the ClientToScreen function to calculate the proper screen coordinates.

SetCursorPos API函数将光标移动到指定的屏幕坐标。 由于此函数没有将Windows句柄作为参数,因此x / y必须是屏幕坐标。 您的组件确实使用相对坐标,例如相对于TForm。 您必须使用ClientToScreen函数来计算正确的屏幕坐标。

模拟 ( Simulations )

On most occasions we want the mouse to move to a certain position on the screen. We know that some components do not respond to a cursor change until the user moves the mouse, we have to provide some small move-from-code technique. And what about simulation mouse clicks without calling the OnClick event handler?

在大多数情况下,我们希望鼠标移动到屏幕上的某个位置。 我们知道某些组件在用户移动鼠标之前不会响应光标更改,我们必须提供一些小的“从代码移动”技术。 在不调用OnClick事件处理程序的情况下模拟鼠标单击又如何呢?

The following example will simulate mouse click event on Button2 after the click to Button1. We have to use mouse_event() API call. The mouse_event function synthesizes mouse motion and button clicks. Mouse coordinates given are in "Mickeys", where there are 65535 "Mickeys" to a screen's width.

下面的示例将模拟单击Button1后在Button2上进行鼠标单击事件。 我们必须使用mouse_event()API调用。 mouse_event函数可合成鼠标动作和按钮单击。 给定的鼠标坐标在“米奇”中,其中屏幕宽度有65535个“米奇”。

限制鼠标移动 ( Restrict The Mouse Movement )

Using the Windows API function ClipCursor, it is possible to restrict the movement of the mouse to a specific rectangular region on the screen:

使用Windows API函数ClipCursor,可以将鼠标的移动限制在屏幕上的特定矩形区域:

鼠标进入,鼠标离开? ( Mouse Enter, Mouse Leave? )

Detecting entering and exiting of the mouse pointer over a component is often coming up when writing your own component. All descendants of TComponent send a CM_MOUSEENTER and CM_MOUSELEAVE message when the mouse enters and leaves the bounds of the component. You will need to write a message handler for the respective messages if we wish to respond to them.

在编写自己的组件时,经常会检测到鼠标指针在组件上的进入和退出。 当鼠标进入并离开组件的边界时,TComponent的所有后代都会发送CM_MOUSEENTER和CM_MOUSELEAVE消息。 如果我们希望对它们进行响应,则需要为各个消息编写一个消息处理程序。

翻译自: https://www.thoughtco.com/advanced-mouse-processing-1058399

delphi 应用程序工厂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值