Try this slightly tweaked routine. The values set for the voffset and
hoffset values work on my system using small fonts. You may need to tweak
the values to correctly clip for large font systems. Basically this uses the
form's scaleheight and scalewidth rather than its width/height to size the
bitmap, then offsets the bitblt'ed image to subtract the borders and
titlebar.
Private Function GetOLEScreenSna pshot() As Picture
Dim hWndSrc As Long
Dim hDCSrc As Long
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim WidthSrc As Long
Dim HeightSrc As Long
Dim Pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
Dim vOffset As Long
Dim hOffset As Long
'CaptureWindow
WidthSrc = Me.ScaleWidth \ Screen.TwipsPer PixelX
HeightSrc = Me.ScaleHeight \ Screen.TwipsPer PixelY
vOffset = ((Me.Width - Me.ScaleWidth) / 1.75) \ Screen.TwipsPer PixelX
hOffset = ((Me.Height - Me.ScaleHeight) / 1.15) \ Screen.TwipsPer PixelY
'Get a handle to the desktop window and get the proper device context
hWndSrc = Me.hWnd
hDCSrc = GetWindowDC(hWn dSrc)
'Create a memory device context for the copy process
hDCMemory = CreateCompatibl eDC(hDCSrc)
'Create a bitmap and place it in the memory DC
hBmp = CreateCompatibl eBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hD CMemory, hBmp)
Print vOffset, hOffset
'Copy the on-screen image into the memory DC
Call BitBlt(hDCMemor y, 0, 0, WidthSrc, HeightSrc, _
hDCSrc, vOffset, hOffset, vbSrcCopy)
'Remove the new copy of the the on-screen image
hBmp = SelectObject(hD CMemory, hBmpPrev)
'Release the device context resources back to the system
Call DeleteDC(hDCMem ory)
Call ReleaseDC(hWndS rc, hDCSrc)
'Fill in OLE IDispatch Interface ID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
'Fill Pic with necessary parts
With Pic
.Size = Len(Pic) 'Length of structure
.Type = vbPicTypeBitmap 'Type of Picture (bitmap)
.hBmp = hBmp 'Handle to bitmap
.hPal = 0& 'Handle to palette (may be null)
End With
'Create OLE Picture object
Call OleCreatePictur eIndirect(Pic, IID_IDispatch, 1, IPic)
'Return the new Picture object
Set GetOLEScreenSna pshot = IPic
End Function
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Pavan Arise" <pa*********@ya hoo.com> wrote in message
news:eb******** *************** **@posting.goog le.com...
: Thank you Randy Birch for the invaluable piece of code. I have the
: program working perfectly as I wanted. But there is a small problem
: here. I was trying to save just the form content only. By the way it
: is now, the title bar (Wher the caption is written) is also getting
: saved. I tried to change the form borderstyle setting to 0 (None) &
: refreshing the form before calling the GetOLEScreenSna pshot sub, but
: for some reason, the form border isn't changing and the form along
: with the titlebar is getting saved. There were some other buttons on
: the form which were not saved when I had them as visible =false during
: runtime. Is it that the borderstyle doesn't change during runtime, or
: are there any other changes to be made for having the titlebar not to
: be saved with the form. Thank you again and any suggestions are
: appreciated.