使用鼠标光标捕获屏幕截图
我使用以下代码在 Windows 上获取屏幕截图。
hdcMem = CreateCompatibleDC (hdc) ;
int cx = GetDeviceCaps (hdc, HORZRES);
int cy = GetDeviceCaps (hdc, VERTRES);
HBITMAP hBitmap(NULL);
hBitmap = CreateCompatibleBitmap (hdc, cx, cy) ;
SelectObject (hdcMem, hBitmap) ;
BitBlt(hdcMem, 0, 0, cx, cy, hdc, 0, 0, SRCCOPY);
但是,鼠标光标不显示。
我怎样才能获得光标?或者有没有图书馆可以做到这一点?
提前致谢。
I have used the following code to get screen shot on Windows.
hdcMem = CreateCompatibleDC (hdc) ;
int cx = GetDeviceCaps (hdc, HORZRES);
int cy = GetDeviceCaps (hdc, VERTRES);
HBITMAP hBitmap(NULL);
hBitmap = CreateCompatibleBitmap (hdc, cx, cy) ;
SelectObject (hdcMem, hBitmap) ;
BitBlt(hdcMem, 0, 0, cx, cy, hdc, 0, 0, SRCCOPY);
However, the mouse cursor doesn't show up.
How could I get the cursor? or Is there a library can do that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 BitBlt 之后和从 hdcMem 中选择位图之前,您可以执行以下操作:
上面的代码使用全局光标状态确定光标是否显示,因为您可能正在截取一个窗口(或多个窗口)的屏幕截图在另一个进程中。然后它获取目标窗口坐标以从屏幕进行调整。它获取有关光标的特定信息,包括其热点。它计算图标的绘制位置。最后,它获取光标图标的实际大小,以便可以在不进行任何拉伸的情况下绘制它。
据我所知,这种方法的唯一限制是:
After your BitBlt and before you select the bitmap back out of hdcMem, you can do this:
The code above figures out if the cursor is showing, using the global cursor state since you're probably taking a screenshot of a window (or windows) in another process. It then gets the target window coordinates for adjusting from screen. It gets specific info about the cursor, including its hotspot. It computes the drawing position of the icon. Finally, it gets the actual size of the cursor icon so that it can draw it without any stretching.
The only limitations to this approach that I know of are: