8

I have cursor shaped forms (functioning as actual cursors). Whenever I drag it makes what looks like mouse trails. The red and white stuff. See the little red arrow on the upper heart and the little white arrow on the lowest heart? Those are my cursor shaped forms, it's a picture on a tiny form (I cut regions so that the form will be shaped like the picture on it). Those are created in the MainUnit (which I minimized).

form trails http://img10.imageshack.us/img10/9718/mousetrails.png

When I click and hold, it makes these trails... hovering over those will erase it. How do I get rid of this behavior?

And I can get rid of these by refreshing but if I refresh everytime a mouse moves there is terrible flickering. My current solution is refreshing whenever there is a click, but I want a solution that will get rid of the behavior and not just erase it after it gets drawn.


Okay, I tried it without the wallpaper. No wallpaper http://img830.imageshack.us/img830/6595/nowallpaper.png It's the same effect inside folders too.


Through a little more experimenting. I've discovered that it wasn't the (cursor) form at all. And it wasn't the code. I tried moving (randomly) forms (with a timer using it's left and top properties). And it seemed okay at first but when I click and hold on the desktop. This happens: Form Trails http://img411.imageshack.us/img411/7409/formg.png Soooooo. Any suggestions as to what I should do to avoid/minimize/control this?

Dian
  • 1,187
  • 3
  • 18
  • 35
  • I'd need to see code to help answer this one. :) What Delphi version? – Tobiasopdenbrouw Jul 22 '10 at 07:42
  • Delphi 7.. though I tried delphi 2009 too. Same thing. What part of the code? The moving part...? Will post it shortly. – Dian Jul 22 '10 at 07:47
  • 1
    The real question is, what's so special about your form that makes the window behind it NOT automatically repaint itself? The fact that it's shaped like a mouse arrow shouldn't have anything to do with it, nor the fact you're moving it using it's Top and Left properties. Is the same thing happening when you're moving your "cursor" over some other kind of window (example: over a notepad window)? – Cosmin Prund Jul 22 '10 at 07:59
  • I truth is I don't know. It's perfectly ordinary. Shall I post the dfm? Or the code inside the forms (which only includes the FormCreate and CreateParams)? – Dian Jul 22 '10 at 08:19
  • It should be tiny, right (at least the elementary part which causes problems)? You could just post the whole thing. – Tobiasopdenbrouw Jul 22 '10 at 08:24
  • @tobias: Yes, the form is tiny. The whole thing is a lot of code... most of it, not so pretty because of the whole RawInput Thing, and I don't think the whole registering of mice and getting of device handles and positions is relevant to the problem. So should I post the whole moving the forms part? or the dfm of the form and stuff? – Dian Jul 22 '10 at 08:30
  • @Dian, Post the CreateParams code; Also post the form's declaration. (the stuff before "implementation") – Cosmin Prund Jul 22 '10 at 08:33
  • I'm not sure what to suggest to you. You may find that reducing your code to the minimal amount that still generates the problem will help you solve it, though. Especially if you remove some 'irrelevant' code that happens to fix the problem. :) – Tobiasopdenbrouw Jul 22 '10 at 08:33
  • @Cosmin: *posted* Pretty basic stuff there though. @Tobias: I would, but 'irrelevant' to the problem isn't irrelevant to the project. Thanks for your help anyway. – Dian Jul 22 '10 at 08:39
  • @Dian - You'd strip a copy of your code, of course. :) – Tobiasopdenbrouw Jul 22 '10 at 09:12
  • @Tobias: I tried moving another form the same way I moved the cursor form, it worked fine. So the problem must be with the cursor-form. I'm still trying to change stuff with the cursor-form. Yep, a copy of the cursor form. :D – Dian Jul 22 '10 at 09:15
  • 2
    Apparently, there's issues with WS_EX_NOACTIVATE and trails (only found hints through googling so far). Also, have a look at http://msdn.microsoft.com/en-us/library/ff684179(VS.85).aspx – Tobiasopdenbrouw Jul 22 '10 at 09:18
  • Hmm.. tried removing the createparams altogether but it still had the trails. :( ooooh, does it mean that Vista's DWM is cooler and won't leave trails? dang. I don't have Vista. – Dian Jul 22 '10 at 09:32
  • @Dian - I've reached the end of what I can do for you (without spending too much time). Good luck! – Tobiasopdenbrouw Jul 22 '10 at 11:35
  • 2
    @Dian, what I usually do when I run into such a problem is start a new project and start adding stuff from the old project to the new project until it brakes. When I know what brakes it, I know how to fix it. If I were to solve your problem, I'd start with a single form and a timer, from the timer I'd make the form move left and right. If it doesn't leave a "trail" (and it doesn't), I'll start adding more code. For example, I'd add the code to shape it as an mouse cursor. Next the code to stop it from acquiring focus, etc, etc... – Cosmin Prund Jul 22 '10 at 18:23
  • 1
    Dian, I've noticed you've demonstrated the trails on an empty desktop. When there are other windows on the desktop, do you see the trails over them too? If not, what happens if you remove the Doc. and select 'None' as desktop background? – Sertac Akyuz Jul 23 '10 at 00:29
  • @Tobias Okay thanks! :D @Cosmin: I'll do that. Thank you for your help. :) @Sertac: On other windows like notepad and calc there are no trails. I'm gonna post a picture of what happens when the background is none. – Dian Jul 23 '10 at 01:14
  • 5
    Dian, I can duplicate what you're seeing if I activate 'Active Desktop' on my PC. When you press the button and move your mouse, you're starting a drag operation, and the shell is calling 'LockWindowUpdate'. Basically, it wants to control what is drawn on the desktop, but your form is moving. See the links in the comment to the following answer which explains far better than me: http://stackoverflow.com/questions/2421646/delphi-prevent-controls-repainting-for-a-time/3291567#3291567 . – Sertac Akyuz Jul 23 '10 at 04:07
  • Thanks for the info. :D I'll look into it and see what I can do. – Dian Jul 23 '10 at 04:12
  • @Dian, >>On other windows like notepad and calc there are no trails.<< So as I usually say: Shoe uz thee codez. If you create a stripped-down version of your main form still reproducing the behavior, I am sure lots of people will have good suggestions. – TheBlastOne Nov 25 '10 at 09:08
  • 1
    Sorry, for the loooong wait. My newer files got wiped out and I had to pick up everything from my old files. Anyway, turns out you're right, it was an issue with the drivers (updated them for the nth time). Thanks for your help. It's much appreciated. – Dian Feb 22 '11 at 01:28

2 Answers2

2

Update your video driver.

Or, as a shortcut, fallback to stock plain vanilla (i.e. standard Windows-supplied) VGA drivers, without changing anything else. If the symptom then persists, the problem is not in the driver, and you can forget about the driver update. (This shortcut is a shortcut because you often cannot easily undo a driver update, just in case you'd want.)

TheBlastOne
  • 4,291
  • 3
  • 38
  • 72
  • That's a Windows XP issue (because it doesn't use compositing, the same problem should happen on Vista and Seven with **Aero disabled**). It happens because when you're dragging items Windows disables screen redrawing. So just when you move a window the thing beneath it don't redraw and you get the house of mirrors effect. – Trinidad Nov 19 '10 at 18:16
  • So what issue exactly is it, and how can it be fixed? I have seen exactly this symptom on XP machines, including the "active desktop" relation, and after updating the video driver, it worked. There are a zillion issues that can cause an app not to redraw correctly. It just is not enough to say "it is an issue". But thanks for downvoting my answer, and commenting it with a "better" answer. – TheBlastOne Nov 22 '10 at 09:00
  • @Dian, did you try updating your video driver? – TheBlastOne Nov 22 '10 at 09:00
  • I added a suggestion to the original answer. – TheBlastOne Nov 25 '10 at 09:04
  • @TheBlastOne: Hey, I found out I lost a huge part of the code because I abandoned this months ago and I didn't have backups for some parts. I will try recreating it when I'm done with my current project, btw, what do you mean by 'in notepad and calc there are no trails', did you do some kind of testing? – Dian Dec 03 '10 at 08:16
  • @Dian: I was (elsewhere) referring to your comment "@Sertac: On other windows like notepad and calc there are no trails.". – TheBlastOne Dec 03 '10 at 08:53
  • Dian, you do not need the sources to reproduce if you still have an executeable. Simply reproduce with it, switch to plain vanilla VGA drivers, try to reproduce, and additively, and only if possible, update the video driver, try to reproduce. The Results of those steps would signal whether it is definetely a programming issue in your code or an "environmental" issue regarding your video drivers. – TheBlastOne Dec 03 '10 at 08:54
1

Based upon Sertac Akyuz comment and http://msdn.microsoft.com/en-us/library/dd145034(VS.85).aspx, try the following:

function TForm1.WaitUntilDesktopUnlocks: Boolean;
var
  desktopUnlocked: Boolean;
begin
  desktopUnlocked:= False;
  while not desktopUnlocked do begin
    desktopUnlocked:= LockWindowUpdate(Self.Handle);
    LockWindowUpdate(0);
  end;
end;

procedure TForm1.DoMoveCursorWindow() // method called to move the window each step
begin
  WaitUntilDesktopUnlocks;
  Self.Left := Self.Left + 1;
  Self.Top := Self.Top + 1;
end;
halfer
  • 19,824
  • 17
  • 99
  • 186
Trinidad
  • 2,756
  • 2
  • 25
  • 43