I've been asked if I can capture part of the screen within my VB6 project...
There seems to be loads of resources to capture to BMP, not so many to capture to jpg, as jpg is the format I would like to save to.
Most of the examples I see are to capture the whole screen.
I have a control AcroPDF1 which shows pdf's, sometimes we need to capture part of AcroPDF1 contents (ie the pdf document) and add it to our image list.
A strange request I know, would be easier to just send the pdf to a client, but some clients software only supports jpg.
So, I would need to find the dimensions of AcroPDF1 and capture its visible contents ( not the whole document if more than 1 )
Any ideas'
Screen Capture
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Screen Capture
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78531
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Screen Capture
Wouldn't it be easier to install a free screen capture program that can save to JPG?
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Screen Capture
Hi Hans, yes it would, I have ScreenHunter, a free program which does this and highly recommended.
Personally I would rather the function be in my project, I can have total control of the file this way, rotation, save location etc.
Cheers
Personally I would rather the function be in my project, I can have total control of the file this way, rotation, save location etc.
Cheers
Cheers ...
Dave.
Dave.
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Screen Capture
Ok well I've got something here.
This captures a window area (Command4) and saves as jpg to a specified folder. The save part I can deal with.
The window area I want to capture is the AcroPDF1 left, Top, Width, Height. How do I pass the dimensions to the capture function?
This captures a window area (Command4) and saves as jpg to a specified folder. The save part I can deal with.
The window area I want to capture is the AcroPDF1 left, Top, Width, Height. How do I pass the dimensions to the capture function?
Code: Select all
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, _
ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, _
ByVal nStretchMode As Long) As Long
Private Const mResizeFactor As Double = 2.7 'Change the picture Size with this value
Private Sub Command2_Click()
Load Form2
Form2.Visible = True
End Sub
Private Sub Command3_Click()
MsgBox "Height" & " " & Me.AcroPDF1.Height
MsgBox "Width" & " " & Me.AcroPDF1.Width
MsgBox "Left" & " " & Me.AcroPDF1.Left
MsgBox "Top" & " " & Me.AcroPDF1.Top
End Sub
Private Sub Command4_Click()
Dim ret As Long
Static i As Long
i = i + 1
ret = GetDC(GetDesktopWindow)
If ret Then
StretchBlt Picture1.hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, _
Screen.Height / Screen.TwipsPerPixelY, ret, 0, 0, _
Picture1.ScaleWidth * mResizeFactor, _
Picture1.ScaleHeight * mResizeFactor, vbSrcCopy
SavePicture Picture1.Image, Form2.Text2.Text & "\imageDW" & i & ".jpg"
Picture1.Picture = Nothing
End If
End Sub
Private Sub Form_Load()
Form2.Text2.Text = GetSetting(App.EXEName, "Interval", "Foldername")
With Picture1
.AutoRedraw = True
.ScaleMode = vbPixels
End With
SetStretchBltMode Picture1.hdc, 4 ' (HalfTone, looks better)
Me.AcrobatPath = "L:\MMPDF\Utilities\PDFViewer.pdf"
Me.AcroPDF1.LoadFile Me.AcrobatPath
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
End Sub
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78531
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Screen Capture
If I read the documentation of StretchBlt correctly, you have the switched the source and destination rectangles. Also, I don't understand the purpose of mResizeFactor.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Screen Capture
Yes, I thought I could just pass the parameters through via the :
If ret Then
StretchBlt Picture1.hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, _
Screen.Height / Screen.TwipsPerPixelY, ret, 0, 0, _
Picture1.ScaleWidth * mResizeFactor, _
Picture1.ScaleHeight * mResizeFactor, vbSrcCopy
But I don't understand where the sizes come into it. Could I resize the picture control to fit AcroPDF1 and hide it?
If ret Then
StretchBlt Picture1.hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, _
Screen.Height / Screen.TwipsPerPixelY, ret, 0, 0, _
Picture1.ScaleWidth * mResizeFactor, _
Picture1.ScaleHeight * mResizeFactor, vbSrcCopy
But I don't understand where the sizes come into it. Could I resize the picture control to fit AcroPDF1 and hide it?
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78531
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Screen Capture
You can easily resize the picture control.
Does this work? I have no way to test it myself.
Does this work? I have no way to test it myself.
Code: Select all
Private Sub Command4_Click()
Static i As Long
i = i + 1
If ret Then
StretchBlt _
Me.AcroPDF1.hdc, 0, 0, Me.AcroPDF1.Width, Me.AcroPDF1.Height, _
Me.Picture1.hdc, 0, 0, Me.Picture1.Width, Me.Picture1.Height, _
vbSrcCopy
SavePicture Picture1.Image, Form2.Text2.Text & "\imageDW" & i & ".jpg"
Picture1.Picture = Nothing
End If
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Screen Capture
No, couldn't get it to work. The Acropdf1 doesn't respond to hdc property.
This one will have to go on the shelf for now.
Thanks for trying to help Hans.
Appreciated -)
This one will have to go on the shelf for now.
Thanks for trying to help Hans.
Appreciated -)
Cheers ...
Dave.
Dave.