Re: screenshots?



Michael Hath*** <lord_mykhal@xxxxxxxxx> wrote in
news:Xns9695DAD5C102Blordmykhalcharternet@xxxxxxxxxxx:

> "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 Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long)
> As Long ' <== Add this line.
> 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
> WinDC = GetWindowDC(0) ' <== Add this line
>
> ' ***** Replace this *****
> ' BitBlt Picture1.hDC, 0, 0, (WinRect.Right - WinRect.Left),
> (WinRect.Bottom - WinRect.Top), Me.hDC, 0, 0, SRCCOPY
> ' with this
> BitBlt Picture1.hDC, 0, 0, (WinRect.Right - WinRect.Left),
> (WinRect.Botton - WinRect.Top), WinDC, WinRect.Left, WinRect.Top,
> SRCCOPY
>
> ' ***** Added below
> ' Save as so
> SavePixture Picture1.Image, "C:\sample.bmp"
> End Sub
>

After posting this, I noticed a rather ugly bug. If you want the form's
caption bar in the snapshot, you must make an adjust me to the code
(which are included above, see comments).

(Sorry about that. I really should stop typing code this late at night. I
always end up spending the next day re-doing all my late-night work.)
.


Loading