This allows a VB program to capture either the screen or the program window.
It has been tested under Win95 and NT4.0. It derives from a routine by Dan Appleman (VisualBasic 5.0 Programmer's Guide to the WIN32 API, page 303) which unfortunately does not work reliably under all conditions. Dan Appleman's exhaustive preliminary tutorial, though, is all it takes to understand the code.
Inputs
mode - 0 = screen, 1 = window
a reference to an image control
Assumes
'Create a form, define two command controls and an image control, insert the following code:
Private Sub Command1_Click()
GetWindowSnapShot 0, Image1
End Sub
Private Sub Command2_Click()
GetWindowSnapShot 1, Image1
End Sub
Side Effects
no known side effect
API DeclarationsDeclare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(LpVersionInformation As OSVERSIONINFO) As Long
Public Const VK_MENU = &H12
Public Const KEYEVENTF_KEYUP = &H2
Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type