开发者

Why does OnMouseMove fire repeatedly when the mouse is not moving in D2010?

开发者 https://www.devze.com 2022-12-15 09:03 出处:网络
I\'m porting a Delphi 5 app to D2010, 开发者_如何学Cand I\'ve got a bit of a problem.On one form is a TImage component with an OnMouseMove event that\'s supposed to update a label whenever the mouse i

I'm porting a Delphi 5 app to D2010, 开发者_如何学Cand I've got a bit of a problem. On one form is a TImage component with an OnMouseMove event that's supposed to update a label whenever the mouse is moved over the image. This worked just fine in the original app, but now the OnMouseMove event fires constantly whenever the mouse is over the image, whether it's moving or not, which causes the label to flicker horribly.

Does anyone know what's causing this and how to fix it?


My psychic debugging sense tells me that you are on Windows, the label is a tooltip window and you are updating on every mousemove.

In all seriousness, I've seen this exact thing with tooltip window when we switched to Vista. It seems that more recent versions of the Windows tooltip window somehow generate WM_MOUSEMOVE messages when you update them. The only fix I could find was to only update the label when the text actually changes.

So, If you aren't on windows, Ignore me. But if you are on Windows, try updating the label text only when it actually changes.


Since I couldn't add a comment I'm using the answer section to confirm this behavior change. I have a project that was developed in Delphi 2007 where the OnMouseMove event is only called when the mouse position changes. I found that with XE OnMouseMove is constantly being called for the same code. I don't know why since they're both triggered by WM_MOUSEMOVE.

What I am doing till I get to the bottom of this is to compare the previous XY coordinates and exit if no change:

if ( x = ZoomRect.Right ) and ( y = ZoomRect.Bottom ) then exit ;


Mason, I can't reproduce this is a new D2010 (Update 4 & 5) VCL Forms application on Windows XP SP2. Here's what I did:

  • File|New|VCL Forms Application
  • Dropped a TImage and TLabel on the form
  • Picked a random image out of the default images folder (GreenBar.bmp) for the TImage.Picture
  • Double-clicked the TImage.OnMouseMove event in the Object Inspector, and added the following code:
    procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      Label1.Caption := Format('X: %d Y: %d', [X, Y]);
    end;
  • Ran the application (F9).

The label showed "Label1" (the default caption, of course) until I first moved the mouse over the image. It then updated correctly to show the X and Y coordinates. As soon as I moved the mouse pointer out of the image, the label stopped updating.

It appears to be something in your specific code, or something specific to the version of Windows you're using, and not Delphi 2010 itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消