Trancedified
asked on
**Saving a Printscreen**
Hi,
I'm developing a VB6 application & I found one way to save a printscreen.....
I have a Picturebox called Picture20 on my form where the property .Visible is = False. So what I want to do is disable all my buttons, kind of cleaning up the form before I take a screenshot.
'Disabling form controls
button1.visible = false
listbox1.visible = false
Set Picture20.Picture = CaptureActiveWindow()
SavePicture Picture20.Picture, ("C:\mypicture.bmp")
But when I save the image, button1 and listbox1 is still visible.
This other way works too, but I am unable to save the image as a .bmp or .jpg, etc. using:
SavePicture Picture1.Picture, ("C:\mypicture.bmp")
apparently it is only available in memory?
Here is the walkthrough:
A timer control's interval is set to 100, button1 is clicked (making other controls invisible, and activating the screenshot)
'Global declarations
Private Declare Sub Sleep Lib "kernel32" (ByVal sleepTime As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Private Declare Sub keybd_event Lib "USER32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
Dim blnAboveVer4 As Boolean
'//Disables controls and activates the timer
Private Sub button1_Click()
button1.visible = false
listbox1.visible = false
Me.Timer1.Enabled = True
End Sub
'//Timer is now shut off while the controls are invisible and quickly takes the screenshot
Public Sub Timer1_Timer()
Timer1.Enabled = False
cboSelection.Visible = False
'//Takes the screenshot
If blnAboveVer4 Then
keybd_event VK_SNAPSHOT, 1, 0, 0
Else
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End If
'//Enables the controls again so I can use it
button1.Visible = True
listbox1.Visible = True
End Sub
For this case the way I tested to see if the VB Controls are invisible during the screenshot is by printing it out. First there's another form called "Final" and a picturebox. The clipboard screenshot is set to a picturebox (Picture1).
Printer.Orientation = vbPRORLandscape
Final.Picture1.Picture = Clipboard.GetData()
Printer.PaintPicture Final.Picture1.Picture, 0, 0
Printer.EndDoc
I wish we could just manually paste the image into Microsoft Paint and then save it, but that wouldn't be "User Friendly."
If you have any way of combining both of these codes so that it saves with the controls being .Visible = False that'd be great, or if you have any other code solutions that do the same idea, please reply.
Thanks for your time.
Chris
I'm developing a VB6 application & I found one way to save a printscreen.....
I have a Picturebox called Picture20 on my form where the property .Visible is = False. So what I want to do is disable all my buttons, kind of cleaning up the form before I take a screenshot.
'Disabling form controls
button1.visible = false
listbox1.visible = false
Set Picture20.Picture = CaptureActiveWindow()
SavePicture Picture20.Picture, ("C:\mypicture.bmp")
But when I save the image, button1 and listbox1 is still visible.
This other way works too, but I am unable to save the image as a .bmp or .jpg, etc. using:
SavePicture Picture1.Picture, ("C:\mypicture.bmp")
apparently it is only available in memory?
Here is the walkthrough:
A timer control's interval is set to 100, button1 is clicked (making other controls invisible, and activating the screenshot)
'Global declarations
Private Declare Sub Sleep Lib "kernel32" (ByVal sleepTime As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Private Declare Sub keybd_event Lib "USER32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
Dim blnAboveVer4 As Boolean
'//Disables controls and activates the timer
Private Sub button1_Click()
button1.visible = false
listbox1.visible = false
Me.Timer1.Enabled = True
End Sub
'//Timer is now shut off while the controls are invisible and quickly takes the screenshot
Public Sub Timer1_Timer()
Timer1.Enabled = False
cboSelection.Visible = False
'//Takes the screenshot
If blnAboveVer4 Then
keybd_event VK_SNAPSHOT, 1, 0, 0
Else
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End If
'//Enables the controls again so I can use it
button1.Visible = True
listbox1.Visible = True
End Sub
For this case the way I tested to see if the VB Controls are invisible during the screenshot is by printing it out. First there's another form called "Final" and a picturebox. The clipboard screenshot is set to a picturebox (Picture1).
Printer.Orientation = vbPRORLandscape
Final.Picture1.Picture = Clipboard.GetData()
Printer.PaintPicture Final.Picture1.Picture, 0, 0
Printer.EndDoc
I wish we could just manually paste the image into Microsoft Paint and then save it, but that wouldn't be "User Friendly."
If you have any way of combining both of these codes so that it saves with the controls being .Visible = False that'd be great, or if you have any other code solutions that do the same idea, please reply.
Thanks for your time.
Chris
Does it work if you set the timer interval to 1000?
ASKER
vinnyd79,
Yeah that is how I had it with the second method of saving a printscreen. When I try to save the image that is loaded into a picturebox.. I get an error like:
"Invalid property value"
and it points to:
SavePicture Picture1.Picture, ("C:\mypicture.bmp")
Chris
Yeah that is how I had it with the second method of saving a printscreen. When I try to save the image that is loaded into a picturebox.. I get an error like:
"Invalid property value"
and it points to:
SavePicture Picture1.Picture, ("C:\mypicture.bmp")
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
zzzzzooc,
Awesome code! It is a lot shorter than other printscreen routines I've seen. Some had to have a long module attached to your project, others had longer pieces of code to do such a simple task.
Thanks for your quick reply.
Chris
Awesome code! It is a lot shorter than other printscreen routines I've seen. Some had to have a long module attached to your project, others had longer pieces of code to do such a simple task.
Thanks for your quick reply.
Chris
>> Awesome code! It is a lot shorter than other printscreen routines I've seen.
Shorter doesn't always mean better. This is a sloppy (but easy) method of doing this. Take into account that users may have information in the clipboard they need when you replace it with a screenshot.
Good luck.
Shorter doesn't always mean better. This is a sloppy (but easy) method of doing this. Take into account that users may have information in the clipboard they need when you replace it with a screenshot.
Good luck.