| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1476 人关注过本帖
标题:[原创]vb.net做的抓屏程序
只看楼主 加入收藏
guyan1220
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-5-22
收藏
 问题点数:0 回复次数:11 
[原创]vb.net做的抓屏程序
Tnbkojab.rar (9.43 KB) [原创]vb.net做的抓屏程序


2006-05-25 22:31
Viviwei
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:344
专家分:0
注 册:2006-4-11
收藏
得分:0 
还行!~以后多多加油!~~

爱上思考,爱上编程,爱上.net!
2006-05-26 16:07
boxou
Rank: 1
等 级:新手上路
帖 子:135
专家分:0
注 册:2006-4-28
收藏
得分:0 

老大,我想要源程序哦,我的EMAIL是:regcn168@163.com


孔夫子说:博学、审问、慎思、明辩、力行[欢迎各位加入爱好者群:25620461]
2006-05-31 18:24
guyan1220
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-5-22
收藏
得分:0 

好的给你门源程序!
Public Class Form1
Inherits System.Windows.Forms.Form
Dim bmp As New Bitmap(800, 600)
#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents Timer2 As System.Windows.Forms.Timer
Friend WithEvents saved As System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Button1 = New System.Windows.Forms.Button
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
Me.saved = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'Button1
'
Me.Button1.BackColor = System.Drawing.Color.Purple
Me.Button1.Font = New System.Drawing.Font("华文新魏", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(0, Byte))
Me.Button1.Location = New System.Drawing.Point(16, 216)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "抓屏"
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.Color.Red
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(24, 16)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(248, 176)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.PictureBox1.TabIndex = 1
Me.PictureBox1.TabStop = False
'
'Button2
'
Me.Button2.BackColor = System.Drawing.Color.Purple
Me.Button2.Font = New System.Drawing.Font("华文新魏", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(0, Byte))
Me.Button2.Location = New System.Drawing.Point(208, 216)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(72, 24)
Me.Button2.TabIndex = 2
Me.Button2.Text = "退出"
'
'Button3
'
Me.Button3.BackColor = System.Drawing.Color.Purple
Me.Button3.Font = New System.Drawing.Font("华文新魏", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button3.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(0, Byte))
Me.Button3.Location = New System.Drawing.Point(112, 216)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(72, 24)
Me.Button3.TabIndex = 3
Me.Button3.Text = "保存"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Maroon
Me.Label1.Location = New System.Drawing.Point(208, 248)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(0, 22)
Me.Label1.TabIndex = 4
'
'Timer1
'
Me.Timer1.Interval = 1000
'
'Timer2
'
Me.Timer2.Interval = 50
'
'saved
'
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(128, Byte))
Me.ClientSize = New System.Drawing.Size(296, 270)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.MinimumSize = New System.Drawing.Size(302, 302)
Me.Name = "Form1"
Me.Opacity = 0
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "捕捉电脑屏幕"
Me.ResumeLayout(False)

End Sub

#End Region
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 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
Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.ActiveForm.Opacity = 0
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
PictureBox1.Image = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
Form1.ActiveForm.Opacity = 1
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer2.Enabled = True
End
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = TimeOfDay
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer2.Enabled = True
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Form1.ActiveForm.Opacity < 1 Then
Form1.ActiveForm.Opacity = Form1.ActiveForm.Opacity + 0.02
ElseIf Form1.ActiveForm.Opacity = 1 Then
Timer2.Enabled = False
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bmp = New Bitmap(PictureBox1.Image)
saved.Filter = "*.bmp|*.bmp"
saved.FileName = "图片名"
saved.ShowDialog()
If saved.FileName <> "" Then
bmp.Save(saved.FileName)
Me.Text = saved.FileName
End If
End Sub


End Class

2006-06-01 10:23
sbudyu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-4-23
收藏
得分:0 

挺好的,如果有注释会更好。

2006-06-02 22:54
guyan1220
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-5-22
收藏
得分:0 
以后,我会学着添加注释的,里面只不过是用了几个API函数
2006-06-03 09:39
guyan1220
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-5-22
收藏
得分:0 
关于把图片保存成文件 这里的代码说的很清楚。你可以看一下!
2006-06-11 13:02
猴子啊
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-16
收藏
得分:0 
请问,那些TIMER控件要作什么用啊, 能解释一下吗,谢谢!!!
2006-06-11 14:25
guyan1220
Rank: 1
等 级:新手上路
帖 子:100
专家分:0
注 册:2006-5-22
收藏
得分:0 
关于timer控件,我想做一种效果:载入窗体时,窗体由透明渐变成非透明状态。所以用到了timer控件!
2006-06-11 15:29
猴子啊
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-4-16
收藏
得分:0 

懂了,谢谢!!!

2006-06-12 12:52
快速回复:[原创]vb.net做的抓屏程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018087 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved