截屏函数

 1 Option Explicit
 2 
 3 Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As LongAs Long
 4 Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As LongAs Long
 5 Private Declare Function EmptyClipboard Lib "user32" () As Long
 6 Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As LongAs Long
 7 Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As LongAs Long
 8 Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As LongAs Long
 9 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 LongAs Long
10 Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As LongAs Long
11 Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As LongAs Long
12 Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As LongAs Long
13 Private Declare Function CloseClipboard Lib "user32" () As Long
14 
15 Sub ScrnCap(Lt, Top, Rt, Bot)
16     Dim rWidth, rHeight, SourceDC, DestDC, BHandle, Wnd, DHandle
17     rWidth = Rt - Lt
18     rHeight = Bot - Top
19     SourceDC = CreateDC("DISPLAY"000)
20     DestDC = CreateCompatibleDC(SourceDC)
21     BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
22     SelectObject DestDC, BHandle
23     BitBlt DestDC, 00, rWidth, rHeight, SourceDC, Lt, Top, &HCC0020
24     Wnd = Screen.ActiveForm.hwnd
25     OpenClipboard Wnd
26     EmptyClipboard
27     SetClipboardData 2, BHandle
28     CloseClipboard
29     DeleteDC DestDC
30     ReleaseDC DHandle, SourceDC
31 End Sub
32 
33 Private Sub Command1_Click()
34     Call ScrnCap(001024768)
35 End Sub
36 

 

posted @ 2009-12-29 18:52  clown  阅读(486)  评论(0编辑  收藏  举报