5个回答
展开全部
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
先找到你要截图的那个窗体的 句柄 然后根据这个句柄得到改窗体的DC 创建一个bitmap 然后填充 得到的bitmap后 显示到picturebox里面
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
先找到你要截图的那个窗体的 句柄 然后根据这个句柄得到改窗体的DC 创建一个bitmap 然后填充 得到的bitmap后 显示到picturebox里面
追问
怎么把图片自动保存在硬盘上啊。
追答
我给的是C#代码 你改成VB的就可以了 picturebox显示图片了以后 你看看 picturebox控件 有没有 save的方法 然后指定保存文件路径 就可以了
展开全部
按方向键上面不是有6个小键? 其中有一个叫Print什么的。然后去打开画图,右击粘贴就有了。
更多追问追答
追问
我说的是用代码。 还有,不是截取屏幕,而是截取VB当前窗体中的内容。
追答
不是有高手回答了?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-06-04
展开全部
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Sub Command1_Click()
SourceDC = CreateDC("DISPLAY", 0, 0, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, (Me.Width / Screen.TwipsPerPixelX), (Me.Height / Screen.TwipsPerPixelY)) '显示区域设置
SelectObject DestDC, Bhandle
BitBlt DestDC, -Me.Left / Screen.TwipsPerPixelX, -Me.Top / Screen.TwipsPerPixelY, Me.Width, Me.Height, SourceDC, 0, 0, &HCC0020 '设置抓图区域
Wnd = Me.hwnd
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, Bhandle
CloseClipboard
DeleteDC DestDC
ReleaseDC Bhandle, SourceDC
Picture1.Picture = Clipboard.GetData()
End Sub
点击command1截屏,自己调试
截屏到剪贴板,在picture1中显示
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Sub Command1_Click()
SourceDC = CreateDC("DISPLAY", 0, 0, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, (Me.Width / Screen.TwipsPerPixelX), (Me.Height / Screen.TwipsPerPixelY)) '显示区域设置
SelectObject DestDC, Bhandle
BitBlt DestDC, -Me.Left / Screen.TwipsPerPixelX, -Me.Top / Screen.TwipsPerPixelY, Me.Width, Me.Height, SourceDC, 0, 0, &HCC0020 '设置抓图区域
Wnd = Me.hwnd
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, Bhandle
CloseClipboard
DeleteDC DestDC
ReleaseDC Bhandle, SourceDC
Picture1.Picture = Clipboard.GetData()
End Sub
点击command1截屏,自己调试
截屏到剪贴板,在picture1中显示
追问
这个不错,。
参考资料: http://wenwen.soso.com/z/q121677228.htm
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要保存当前窗体用模拟按下Print按键
以下是vb.net代码需要CheckBox1控件
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Try
If CheckBox1.Checked = True Then
SendKeys.Send("{PRTSC}") '模拟按下Print按键
delay(500)
Dim img As Image = My.Computer.Clipboard.GetImage
img.Save("d:\button.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub delay(ByVal t As Integer) '延时程序
Dim temp As Integer = Environment.TickCount
While Environment.TickCount - temp <= t
Application.DoEvents()
End While
End Sub
以下是vb.net代码需要CheckBox1控件
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Try
If CheckBox1.Checked = True Then
SendKeys.Send("{PRTSC}") '模拟按下Print按键
delay(500)
Dim img As Image = My.Computer.Clipboard.GetImage
img.Save("d:\button.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub delay(ByVal t As Integer) '延时程序
Dim temp As Integer = Environment.TickCount
While Environment.TickCount - temp <= t
Application.DoEvents()
End While
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是想用vb编写截图软件程序?
更多追问追答
追问
并不用多么强大的功能,就把当前窗体中的内容保存成图片就可以了。
追答
那你可以用一般的截图软件就好了,用vb开发类似截图功能,也挺烦的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询