如何用VB抓图?
下面的例子将演示怎样把桌面图片用BitBlt函数复制到窗体中,你可以利用它制作抓图程序,或是制作屏保程序。
把以下代码加入模块:
Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hSrcDC As Integer, ByVal xSrc As Integer, _
ByVal ySrc As Integer, ByVal dwRop As _
Long) As Integer
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Public Const SRCCOPY = &HCC0020
Public Const SRCAND = &H8800C6
Public Const SRCINVERT = &H660046
窗体代码:
设置窗体属性如下:
AutoRedraw True
BorderStyle 0 - None
WindowState 2 - Maximized
现在,把下面的代码加入到窗体中。
Private Sub Form_Load()
Dim DeskhWnd As Long, DeskDC As Long
'得到桌面的hWnd
DeskhWnd& = GetDesktopWindow()
DeskDC& = GetDC(DeskhWnd&)
BitBlt Form1.hDC, 0&, 0&, _Screen.Width, Screen.Height, DeskDC&, _
0&, 0&, SRCCOPY
End Sub
向窗体添加一个命令按钮,并加入以下代码:
Private Sub Command1_Click()
Unload Me
End
End Sub
初来学习
我照着上面的代码 做 怎么 这句
BitBlt Form1.hDC, 0&, 0&, _Screen.Width, Screen.Height, DeskDC&, _
0&, 0&, SRCCOPY
提示错误 请指教 谢谢