在 Win 7 上在桌面上画线非常慢
我使用此代码在所有窗口顶部用鼠标画一条线。我使用鼠标挂钩来获取鼠标坐标,并且在鼠标右键按下时每次移动鼠标,我都会绘制线条。我正在使用 NOTXORPEN
,因此我只能通过再次绘制来删除该线。
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
我在每次鼠标移动时都使用此代码:
LineTo(ScreenDC, X, Y); // Draw a Line between the prev Point to Current Point
此代码适用于 Windows 95、98、2000 和 XP,但现在 Windows 7 速度非常慢。
我只使用Windows API在Delphi 3中编写了一个鼠标手势程序(1999年编写)(由于Delphi版本3中的BUG,鼠标钩子是用VC编写的)。这个程序正在做 StrokeIt 正在做的事情,但不知何故,StrokeIt 设法找到了这个问题的解决方案。
我的代码是用 Delphi 编写的,但我们将不胜感激任何语言的答案!
我将更详细地解释我到底想要构建什么。我的应用程序分为三个部分:
- 单击鼠标右键时的鼠标手势跟踪和存储
- 基于有限数量的形状的手势识别基于
- 识别的手势和启动手势时光标下的应用程序的宏激活
我'我在使第 1 部分在 Windows7 (Vista) 上运行时遇到困难,正如 Martyn 在他的回答中所写,我想我必须改变概念。现在我正在通过挂钩鼠标消息和我上面附加的代码绘制手势来进行跟踪...我了解分层窗口的基础知识,但是什么对我有用?您认为制作一个全屏最上面的透明窗口并在其上绘图可以完成这项工作吗?有人可以帮我为此编写代码吗?
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 :
- Mouse Gesture tracking and storing while Right-Mouse-Button is clicked
- Gesture Recognition based on limited number of shapes
- Macro activation based on the recognized gesture and the Application that was under the cursor while starting the gesture
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Windows Vista 之前,桌面被绘制为实际的 GDI 表面,因此这种活动是有效的 - 尽管它的运行速度取决于 GDI 驱动程序的加速。
在 Vista 及更高版本中,桌面窗口管理器使用 DX 将多个窗口(其中一些可能使用 GDI,一些可能不使用)组合在一起,形成一个渲染到较新驱动程序模型的最终场景。因此,直接戳屏幕像素会慢很多。
更根本的是,这不是完成任务的方法。我不太清楚您要构建什么,但您可能想了解分层 Windows: http ://msdn.microsoft.com/en-us/library/ms997507.aspx 它提供了一种受支持且适当的方法来在实际应用程序之上创建更复杂的场景。它们还应该帮助您避免使用鼠标挂钩,这也是一个坏主意。
马丁
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