' 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
Dim border_width As Single
' 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(Width - ScaleWidth + wid, _
vbPixels, vbTwips)
picHidden.Height = ScaleY(Height - ScaleHeight + hgt, _
vbPixels, vbTwips)
' Copy the desktop's image.
picHidden.AutoRedraw = True
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
' Copy the part of the screen under the form onto the
' form.
picHidden.Visible = False
border_width = (Width - ScaleWidth) / 2
PaintPicture picHidden.Picture, _
0, 0, ScaleWidth, ScaleHeight, _
Left + border_width, _
Top + (Height - ScaleHeight - border_width), _
ScaleWidth, ScaleHeight
End Sub
|