如何使用“工具提示”抓取屏幕截图在VB.Net? [英] How to grab a screen shot with "Tool Tips" in VB.Net?

查看:63
本文介绍了如何使用“工具提示”抓取屏幕截图在VB.Net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法抓住屏幕截图?包括工具提示?我在某个地方看到了这个代码

,不记得在哪里。但它并没有抓住工具提示。

在.net中有更好的方法吗?

谢谢!


私有声明函数CreateDC Lib" gdi32"别名CreateDCA (ByVal

lpDriverName As String,ByVal lpDeviceName As String,ByVal lpOutput As

String,ByVal lpInitData As String)As Integer


私有声明函数CreateCompatibleDC Lib" GDI32" (ByVal hDC As

整数)作为整数


私有声明函数CreateCompatibleBitmap Lib" GDI32" (ByVal hDC As

整数,ByVal nWidth为整数,ByVal nHeight为整数)为整数


私有声明函数GetDeviceCaps Lib" gdi32"别名GetDeviceCaps

(ByVal hdc As Integer,ByVal nIndex As Integer)As Integer


私有声明函数SelectObject Lib" GDI32" (ByVal hDC As Integer,

ByVal hObject As Integer)作为整数


私有声明函数BitBlt Lib" GDI32" (ByVal srchDC As Integer,ByVal

srcX As Integer,ByVal srcY As Integer,ByVal srcW As Integer,ByVal srcH As

Integer,ByVal desthDC As Integer,ByVal destX As整数,ByVal destY As

整数,ByVal op As Integer)整数


私有声明函数DeleteDC Lib" GDI32" (ByVal hDC As Integer)As

整数


私有声明函数DeleteObject Lib" GDI32" (ByVal hObj As Integer)As

整数


Const SRCCOPY As Integer =& HCC0020


私人oBackground As System.Drawing.Bitmap


私人FW,FH整数


Public Sub CaptureScreen()


Dim hSDC,hMDC As Integer


Dim hBMP,hBMPOld As Integer


Dim r As Integer

hSDC = CreateDC(" DISPLAY","","","")

hMDC = CreateCompatibleDC(hSDC)


FW = GetDeviceCaps(hSDC,8)


FH = GetDeviceCaps(hSDC,10)


hBMP = CreateCompatibleBitmap(hSDC,FW,FH)

hBMPOld = SelectObject(hMDC,hBMP)


r = BitBlt(hMDC,0,0, FW,FH,hSDC,0,0,13336376)


hBMP = SelectObject(hMDC,hBMPOld)


r = DeleteDC(hSDC)< br $>

r = DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(新的IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)

Is there a way to grab a "Screen Shot" that includes "Tool Tips"? I saw
this code someplace, cant remember where. But it doesnt grab "Tool Tips".
Is there a better way to do this in .net?
Thanks!

Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As String) As Integer

Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
Integer) As Integer

Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer

Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
ByVal hObject As Integer) As Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As
Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
Integer, ByVal op As Integer) As Integer

Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
Integer

Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As
Integer

Const SRCCOPY As Integer = &HCC0020

Private oBackground As System.Drawing.Bitmap

Private FW, FH As Integer

Public Sub CaptureScreen()

Dim hSDC, hMDC As Integer

Dim hBMP, hBMPOld As Integer

Dim r As Integer

hSDC = CreateDC("DISPLAY", "", "", "")

hMDC = CreateCompatibleDC(hSDC)

FW = GetDeviceCaps(hSDC, 8)

FH = GetDeviceCaps(hSDC, 10)

hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

hBMPOld = SelectObject(hMDC, hBMP)

r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)

hBMP = SelectObject(hMDC, hBMPOld)

r = DeleteDC(hSDC)

r = DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(New IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)


推荐答案

您好gregory_may,


感谢您使用Microsoft MSDN管理新闻组。


目前我正在寻找可以帮助你的人。我们将在这里回复

,并尽快提供更多信息。

如果您对此有任何疑问,请随时在此处发布。

祝你好运,

Gary Chang

微软在线合作伙伴支持


安全! - www.microsoft.com/security

此帖子原样是按原样提供的。没有保证,也没有赋予任何权利。

--------------------

Hi gregory_may,

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------


谢谢Gary:


下面的代码也没有抓住Mouse。我需要能够获得包括鼠标在内的屏幕截图的代码。 "光标" &安培; 工具提示。


感谢您的帮助!


" Gary Chang" <,V - ****** @ online.microsoft.com>在消息中写道

news:fG ************** @ cpmsftngxa07.phx.gbl ...
Thanks Gary:

This code below also doesnt Grab the "Mouse". I need code that that can
grab a screen shot including the "mouse" "Cursors" & "tool tips".

Thanks for your help!

"Gary Chang" <v-******@online.microsoft.com> wrote in message
news:fG**************@cpmsftngxa07.phx.gbl...
嗨gregory_may,

感谢您使用Microsoft MSDN管理新闻组。

目前我正在寻找可以帮助您的人。我们将在这里以
回复更多信息。
如果您有任何疑问,请随时在此发布。

祝你好运, Gary Gary
Microsoft在线合作伙伴支持

获得安全保障! - www.microsoft.com/security
此帖子提供按原样没有保证,并且不授予
权利。 --------------------
Hi gregory_may,

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. --------------------



你好格雷戈里,


感谢您的帖子。据我了解,你面临的问题是使用ToolTips和Cursor进行屏幕截图。

。如果有任何

的误解,请纠正我。我想与您分享以下信息:


1.根据我的经验和研究,我们可以获得一个屏幕截图

使用工具提示。打开工具提示窗口,您只需按下Pr

Scrn即可。 (在键盘上打印屏幕键),将屏幕截图粘贴到Paint.exe,

,您将看到工具提示。您可以执行一些操作(例如,

移动/单击鼠标),这将禁用工具提示,以便

触发您的ScreenShot功能,我相信''是你的屏幕截图中没有显示

工具提示的原因。

要解决此问题,可以使用键盘消息启动

ScreenShot功能。


如果它是系统级的,那就是你需要在你的VB上获取屏幕截图
.NET应用程序不活动,你需要调用SetWindowsHookEx来支持
安装一个全局钩子来监视keyborad消息以获取一个屏幕

shot。我们必须使用Visual C ++来创建本机系统范围的Hook DLL,因为全局钩子必须有一个本机动态链接库(DLL)导出

才能注入本身在另一个需要有效,一致的

函数调用的过程中。这需要DLL导出,.NET Framework

不支持。对于

函数指针,托管代码没有一致值的概念,因为这些函数指针是动态构建的代理。我相信以下MSDN文章是有用的:


如何:在Visual C#.NET中设置Windows挂钩
http://support.microsoft.com/?kbid=318804


SetWindowsHookEx
http: //msdn.microsoft.com/library/de...us/winui/winui

/ windowsuserinterface / windowing / hooks / hookreference / hookfunctions / setwindows

hookex.asp

Hooks
http://msdn.microsoft.com/library/de...us/winui/winui

/ windowsuserinterface


2.据我所知,光标被排除在屏幕之外

shot。您可能必须获取光标信息并将其手动添加到位图

截图。


如果您有任何问题,请随时告诉我或者担忧。


祝你有愉快的一天!


问候,


HuangTM
Microsoft在线合作伙伴支持

MCSE / MCSD


安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有赋予任何权利。

Hello Gregory,

Thanks for your post. As I understand, the problem you are facing is to get
a screen shot with ToolTips and Cursor. Please correct me if there is any
misunderstanding. I''d like to share the following information with you:

1. Based on my experience and research, we are able to grab a screen shot
with "Tool Tips". With a ToolTip window open, you can simply press the "Pr
Scrn" (print screen key in keyboard), paste the screen shot to Paint.exe,
and you will see the ToolTip. You may perform some actions (say,
moving/clicking the mouse), which will disable the ToolTip, in order to
trigger your ScreenShot function, I believe that''s the reason why the
ToolTip is not shown in your screen shot.

To work around the problem, you can use keyboard message to start the
ScreenShot function.

If it''s system-wide, that is, you need to grab screen shot when your VB
.NET application is not active, you will need to call SetWindowsHookEx to
install a global hook to monitor keyborad message for grabbing a screen
shot. We have to use Visual C++ to create a native system-wide Hook DLL,
because a global hook must have a native dynamic-link library (DLL) export
to inject itself in another process that requires a valid, consistent
function to call into. This requires a DLL export, which .NET Framework
does not support. Managed code has no concept of a consistent value for a
function pointer because these function pointers are proxies that are built
dynamically. I believe the following MSDN articles are helpful:

HOW TO: Set a Windows Hook in Visual C# .NET
http://support.microsoft.com/?kbid=318804

SetWindowsHookEx
http://msdn.microsoft.com/library/de...us/winui/winui
/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows
hookex.asp

Hooks
http://msdn.microsoft.com/library/de...us/winui/winui
/windowsuserinterface

2. As far as know, it''s by design that cursor is excluded from the screen
shot. You may have to get the cursor information and add it to the bitmap
of screenshot manually.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于如何使用“工具提示”抓取屏幕截图在VB.Net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆