I.m using this code to draw a line with a mouse on top of all windows. I'm using mouse hook to get mouse coordinates and on each mouse movement while right mouse button is down I'm drawing the line. I'm using NOTXORPEN
so I will be able to delete the line only by drawing it again.
Init:
ScreenDC := GetDcEx(GetDesktopWindow,0,DCX_LOCKWINDOWUPDATE);
PenHandle := CreatePen(PS_SOLID,HitStorage.GetPenWidth,10);
SelectObject(ScreenDC ,PenHandle);
OldPenMode := SetRop2(ScreenDC, R2_NOTXORPEN); // Setting the PenMode to NotXor
MoveToEx(ScreenDC, X, Y, Nil); //Move The Pen Position to the Cursor Position
I'm using this code on each mouse movement:
LineTo(ScreenDC, X, Y); // Draw a Line between the prev Point to Current Point
This code worked for Windows 95, 98, 2000 and XP but now with Windows 7 its very slow.
I wrote a mouse gestures program (written in 1999) in Delphi 3 using ONLY Windows API (mouse hook was written in VC because of Delphi BUG in version 3). This program is doing exactly what StrokeIt is doing but somehow StrokeIt managed to figure out the solution to this problem.
My code is in Delphi but an answer in any language we will be appreciated!
I will explain in more details what exactly I'm trying to build. my application is divided to three parts :
I'm having trouble making Part1 to work on Windows7 (Vista), and as Martyn wrote in his answer I guess I have to change concept. Now I'm doing the tracking by hooking the mouse messages and the gesture drawing by the code i attached above... I understood the basics of Layered windows but what will work for me? do you think making a fullscreen topmost tranparent window and drawing on it will do the job? can some help me writing the code for this?
Before Windows Vista, the desktop was drawn as an actual GDI surface, and so this kind of activity worked - though how fast it worked depended on your GDI driver's acceleration.
With Vista and beyond the Desktop Window Manager uses DX to composite together multiple windows (some of which may use GDI, and some of which may not) to a single final scene that is rendered to a newer driver model. As a result directly poking at screen pixels gets a lot slower.
More fundamentally, this is not the way to get things done. It's not really clear to me what you are trying to build, but you probably want to learn about Layered Windows: http://msdn.microsoft.com/en-us/library/ms997507.aspx which provide a supported and appropriate way to create more complex scenes on top of the actual apps. They should also help you avoid using a mouse hook, which is also a bad idea.
Martyn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With