VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 抓屏演示
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11257, 日期:2001-06-14
示例二:抓屏演示


  本示例程序将演示如何拷贝屏幕图象。


  实现步骤:

  1. 建立一个新项目,将其命名为Demo4.vbp。

  2. 增加模块Demo4.bas,在Demo4.bas中加入如下代码:


Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Const SRCCOPY = &HCC0020


   3. 在窗体Form1的Command1_Click处理程序中加入以下代码:

Private Sub Command1_Click()
Dim i As Long
Dim wScreen As Long
Dim hscreen As Long
Dim w As Long
Dim h As Long
Picture1.Cls
wScreen = Screen.Width \ Screen.TwipsPerPixelX
hscreen = Screen.Height \ Screen.TwipsPerPixelY
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
hdcScreen = GetDC(0)
i = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen,
hscreen, vbSrcCopy)
Picture1.Refresh
End Sub