Re: screenshots?



"Coder" <greg114497@xxxxxxxxx> wrote in news:1121563120.694540.73540
@o13g2000cwo.googlegroups.com:

> I was seeking a way for users to create their own snapshots. I
> understand the part about saving the invisible picture box, but I do
> not know how I would place a copy of the window contents into the
> picture box in order to save it.
>
>

You'll need to dip into the Windows API. Here are the API declares that
you'll need (NOTE: If you place these into a class or form module, you'll
need to add the Private type to each line.)

Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As
Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As
Long) As Long

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect
As RECT) As Long

Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Const SRCCOPY = &HCC0020 ' (DWORD) dest = source


Now, in your code where you would be creating the snapshot, you must
first get your window's region (RECT). You would do this like so:

Dim WinRect as RECT
GetWindowRect Form1.hWnd, WinRect

Next, you copy the data over with a call to BitBlt

BitBlt Picture1.hDC, 0, 0, (WinRect.Right - WinRect.Left),
(WinRect.Bottom - WinRect.Top), Me.hDC, 0, 0, SRCCOPY


Now your picture box will contain your form's snapshot. Of course, you
need to replace all instances of Form1 with whatever your form's name is
as well as Picture1 references. Here is the entire code that I used to
test this:

' Form1 module.
' This form contains two text boxes and two command buttons. One command
' button creates the snapshot. The other controls are for visual appeal.
Option Explicit

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal
x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop
As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long,
lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Private Sub Command1_Click()
Dim WinRect As RECT
Dim WinDC As Long

' Extract our window
GetWindowRect Me.hwnd, WinRect

BitBlt Picture1.hDC, 0, 0, (WinRect.Right - WinRect.Left),
(WinRect.Bottom - WinRect.Top), Me.hDC, 0, 0, SRCCOPY
End Sub
.


Loading