VB编程的高手进

用VB写一个截图的软件要求:一按command1就在picture1中显示出来
2024-11-28 18:06:28
推荐回答(2个)
回答1:

看一下,这个是截图并在image显示的,你只要将image修改为picture是一样的
VB 截图 抓图

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()
Me.Visible = False
SourceDC = CreateDC("DISPLAY", 0, 0, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, 800, 600)
SelectObject DestDC, Bhandle
BitBlt DestDC, 0, 0, 800, 600, SourceDC, 0, 0, &HCC0020
Wnd = Screen.ActiveForm.hwnd
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, Bhandle
CloseClipboard
DeleteDC DestDC
ReleaseDC Dhandle, SourceDC
Me.Picture = Clipboard.GetData()
Me.Visible = True
End Sub

Private Sub Command2_Click()
Me.Picture = Me.Image
''保存捕捉的图片
CommonDialog1.Filter = "BMP文件(*.bmp)|*.bmp|JPG文件(*.jpg)|*.jpg"
CommonDialog1.ShowSave
CommonDialog1.Flags = &H2 + &H4 + &H8
If CommonDialog1.FileName <> "" Then
SavePicture Me.Picture, CommonDialog1.FileName
End If
End Sub

Private Sub Command3_Click()
End
End Sub

回答2:

Private sub command1_click()
picture1.picture.show
end sub