I needed this feature to capture an image of the Task Manager.
When the user clicks the Go button, the program sets the tmrGrabScreen Timer's Interval property to the number of seconds indicated and enables the Timer.
When the Timer fires, it disables itself and calls subroutine GrabScreen.
|
' Copy the desktop's image into the file.
Private Sub GrabScreen(ByVal file_name As String)
Dim desktop_rect As RECT
Dim desktop_win As Long
Dim desktop_dc As Long
Dim desktop_wid As Long
Dim desktop_hgt As Long
Dim x As Long
Dim y As Long
Dim wid As Long
Dim hgt As Long
' Get the desktop size in pixels.
desktop_win = GetDesktopWindow()
desktop_dc = GetDC(desktop_win)
GetWindowRect desktop_win, desktop_rect
desktop_wid = desktop_rect.Right
desktop_hgt = desktop_rect.Bottom
' Get the printable area.
x = 0
wid = desktop_wid
y = 0
hgt = desktop_hgt
picHidden.Width = ScaleX(wid, vbPixels, vbTwips)
picHidden.Height = ScaleY(hgt, vbPixels, vbTwips)
' Copy the desktop's image.
StretchBlt _
picHidden.hDC, x, y, wid, hgt, _
desktop_dc, 0, 0, desktop_wid, desktop_hgt, _
SRCCOPY
picHidden.Picture = picHidden.Image
' Release the desktop's device context.
ReleaseDC desktop_win, desktop_dc
' Save the result into the file.
SavePicture picHidden.Picture, file_name
End Sub
|