PrintScreen




Public Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte,
ByVal bScan As Byte,
ByVal dwFlags As Long,
ByVal dwExtraInfo As Long)
Public Const TheScreen = 0
Public Const TheForm = 1
'On a form, add a command button and either an image control or a

'picturebox. Add the following code to the form:

Private Sub Command1_Click()

'call the Windows keybd_event sub, passing the built-in

'VB keyboard constant vbKeySnapshot (44) to the sub.

'The four parameters for keybd_event are:

'BYTE bVk 'virtual-key code

'BYTE bScan 'hardware scan code

'DWORD dwFlags 'flags specifying various function options

'DWORD dwExtraInfo 'additional data associated with keystroke

'The bScan parameter value determines what to copy...

'passing 0 (TheScreen) copies the screen, passing 1 (TheForm) copies

'the active form.

keybd_event vbKeySnapshot, TheScreen, 0&, 0&

'pause to let Windows update the clipboard

DoEvents

'retrieve the clipboard bitmap to the control (vbCFBitmap = 2)

Image1 = Clipboard.GetData(vbCFBitmap)
End Sub

The following code will copy the contents of the desktop
(the screen) into a picturebox or image control on a form.
Unlike the examples listed at the top of this page, this
method uses the Windows API to actually printscreen to the
clipboard first, and then retrieve that bitmap into the
image control.










( printscreen.html )- by Paolo Puglisi - Modifica del 17/12/2023