自定义组件点击消息

发布于 2024-10-27 04:45:52 字数 618 浏览 4 评论 0原文

我正在编写一个从速度按钮派生的小组件。我需要做的实际上是覆盖绘画方法,因为我想改变外观。 现在我已经达到了我想在单击按钮时提供不同背景颜色的地步。但是,我无法找到一种方法来捕获组件中的鼠标左键单击消息。

到目前为止我所使用的:

procedure KeyboardButton.WndProc(var Message: TMessage);
begin
  if Message.LParam = VK_LBUTTON then
  begin
    //Some code
  end
  else
    inherited;
end;

当我单击按钮 Message.LParam 不是 1 时,这不起作用。

我也尝试过...

procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

好吧,我知道 CM_MOUSELEAVE 不是代表鼠标单击的消息。但也许有一条像 CM_MOUSECLICK 这样的消息???但我找不到它。到底,谁能告诉我什么是 CM_XXXX,因为我在 msdn 上找不到任何内容?似乎是 Delphi 特定的消息。

提前致谢!

I am writing a little component which i derive from speed button. All i need to do is actually override the paint method because i would like to change the appearance.
Now i've reached to the point where i would like to give different background color when button is clicked. However, i can't find a way to catch left mouse button click message in my component.

What i've used so far:

procedure KeyboardButton.WndProc(var Message: TMessage);
begin
  if Message.LParam = VK_LBUTTON then
  begin
    //Some code
  end
  else
    inherited;
end;

Which doesn't work as when i click on the button Message.LParam is not 1.

Also i tried...

procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;

Well, i know that CM_MOUSELEAVE is not a message that represents mouse click. But maybe there's a message like CM_MOUSECLICK??? I couldn't find it though. At all, can anyone please tell me what is CM_XXXX as i can't find anything from msdn? Seems like Delphi specific messages.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌︼了一个春 2024-11-03 04:45:52

VCL 已经为您跟踪 WM_LBUTTONDOWN/UP 消息。当在组件上按住鼠标左键时,将在组件的 ControlState 属性中启用 csLButtonDown 标志(如果 DragMode 属性未设置为 dmAutomatic< /代码>,即)。您的 Paint() 代码可以检查该标志并根据需要调整其背景绘制。

The VCL already tracks the WM_LBUTTONDOWN/UP messages for you. The csLButtonDown flag will be enabled in your component's ControlState property while the left mouse button is held down on your component (if the DragMode property is not set to dmAutomatic, that is). Your Paint() code can check for that flag and adjust its background drawing as needed.

北音执念 2024-11-03 04:45:52

您只需重写 MouseDown 和 MouseUp 方法即可。请记住检查 Button 参数的值!

You can just override the MouseDown and MouseUp methods. Remember to check the value of the Button parameter!

勿忘心安 2024-11-03 04:45:52

您没有正确测试鼠标事件。试试这个:

if Message.Msg = WM_LBUTTONDOWN then
  // Some code
else
  inherited;

BTW、TMessage.LParamTMessage.WParam 是使用特定消息类型(例如 WM_LBUTTONDOWN)传递的参数,并且具有不同的含义取决于 TMessage.Msg 实际上是什么。 绝对不应该出现这样的情况:您收到诸如 TMessage 之类的通用消息,并且仅检查 WParamLParam

You're not correctly testing for a mouse event. Try this:

if Message.Msg = WM_LBUTTONDOWN then
  // Some code
else
  inherited;

BTW, TMessage.LParam and TMessage.WParam are parameters passed with a specific message type (like WM_LBUTTONDOWN), and have different meanings depending on what TMessage.Msg actually is. There should never be a case where you get a generic message like TMessage and check only the WParam or LParam.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文