' Copy the desktop's image into the form.
Private Sub GrabScreen()
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
Width = ScaleX(Width - ScaleWidth + wid, vbPixels, _
vbTwips)
Height = ScaleY(Height - ScaleHeight + hgt, vbPixels, _
vbTwips)
' Copy the desktop's image.
StretchBlt _
hdc, x, y, wid, hgt, _
desktop_dc, 0, 0, desktop_wid, desktop_hgt, _
SRCCOPY
Picture = Image
' Release the desktop's device context.
ReleaseDC desktop_win, desktop_dc
End Sub
|