Rectangle Screendump to ClipBoard

  • Thread starter Leendert van Staalduinen
  • Start date
L

Leendert van Staalduinen

My question is not really OWC-specific, but I use it for my OWC Chart.
I want to copy the Chart as shown on the screen directly to the
clipboard with a one-click action.
The following solutions are NOT what I am looking for:
- Send to a .GIF file and copy it from a .GIF viewer (e.g. IrfanView)
to the clipboard. I can do that, it works very nice, but that's too
much actions.
- Make a screen dump of the total screen (e.g. with "keybd_event
vbKeySnapshot ..."). I can do that, it is a one-click action, but it
shows the total screen (and I do not want to crop the overload).
- Have a program that makes screendumps, possibly of just a rectangle.
I can do that, it works nice as well, but that's too much actions.

Am I too demanding? Maybe. In my fantasy I would use a fixed rectangle
(e.g. with GetWindowRect) and dump the content of that rectangle to
the clipboard.
I guess, that has been done before.

Leendert van Staalduinen.
 
L

l.van.staalduinen

Alvin said:
what are you trying to do? maybe there is a workaround

What am I trying to do? Well I think I expressed my goal pretty clear.
In fact after writing this posting, I realised I could program just
what I want. Well, here is my solution (with a little bit of help from
my friends).

The intMargin parameter is pure luxury. It is an extra to show the
border just like you want it. The procedure works flawlessly in Access
2000 with OWC9 for the PivotTable as well as the Chart.

Public Sub CaptureScreen(ctlPicture As Access.Control, intMargin As
Integer)
' Screen Capture Procedure, coordinates are expressed in pixels: _
- ctlPicture: the control to be captured, _
- intMargin an optional margin for the capture, 050103.
' Source: Copy what you see in the Screen or in a Form into the
clipboard _
(www.andreavb.com/tip090001.html). Equivalents are found
"everywhere".
Dim lnghSourceDC As Long
Dim lnghMemoryDC As Long
Dim lnghBitmap As Long ' Handle to the Bitmap.
Dim rctControl As RECT
Dim lngHwndPictureControl As Long ' Handle of the Picture
Control.

On Error GoTo PROC_ERROR
' Based on the AccessWeb (Dev Ashish): "hWnd of Controls". See also
in basDatePicker, 050103.
ctlPicture.SetFocus
lngHwndPictureControl = GetFocus

Call GetWindowRect(lngHwndPictureControl, rctControl) ' Get size
of control.
With rctControl
..Left = .Left - intMargin
..Top = .Top - intMargin
..Right = .Right + intMargin
..Bottom = .Bottom + intMargin
End With

'lngHMSourceDC = CreateDC("DISPLAY", "", "", dm) ' The
AndreaVB approach.
lnghSourceDC = GetDC(GetDesktopWindow())
lnghMemoryDC = CreateCompatibleDC(lnghSourceDC)
With rctControl
lnghBitmap = CreateCompatibleBitmap(lnghSourceDC, .Right -
..Left, .Bottom - .Top)
Call SelectObject(lnghMemoryDC, lnghBitmap)
Call BitBlt(lnghMemoryDC, 0, 0, .Right - .Left, .Bottom - .Top,
_
lnghSourceDC, .Left, .Top, &HCC0020) ' &HCC0020
= 13369376.
End With
Call OpenClipboard(Access.Application.Screen.ActiveForm.Hwnd)
Call EmptyClipboard
Call SetClipboardData(2&, lnghBitmap) ' CF_BITMAP
= 2.
Call CloseClipboard
Call DeleteDC(lnghMemoryDC)
Call ReleaseDC(lnghBitmap, lnghSourceDC)

PROC_Exit:
Exit Sub

PROC_ERROR:
'Call clsEH.ErrorHandler(VBA.Err.Number, conModuleName,
"Form_Open")
Debug.Print "In CaptureScreen: " & Err & " " & Error
MsgBox Error, vbExclamation, "Error in CaptureScreen: " & Err
Resume PROC_Exit
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top