Discussion:
Screen shot using VB6. I need help. lol please?
(too old to reply)
ObiWan
2024-02-16 08:10:45 UTC
Permalink
:: On Thu, 15 Feb 2024 21:28:19 -0800 (PST)
:: (microsoft.public.vb.general.discussion)
I have no idea of how to even start this coding but need vb6 code
If the date = the 4th of each month then
If register (A) <> 0 then Register (A) = 0
Take a screen shot of desktop and store it in C:\file as
“screenshot1.jpg” End if
If the date => then the 5th of each month then register (A) = 1
See here (first reply)

https://stackoverflow.com/questions/38374540/vb6-screen-shot-function

wrap the code inside a function, and change the code to use the hDC of
a picture control (may be invisible), so that you may then pick the
image and save it to a file, done that, try the function and adjust it
as desired and then add some separate code to call the function when
desired and save the returned image to file
ObiWan
2024-02-16 08:55:55 UTC
Permalink
:: On Fri, 16 Feb 2024 09:10:45 +0100
:: (microsoft.public.vb.general.discussion)
Post by ObiWan
https://stackoverflow.com/questions/38374540/vb6-screen-shot-function
Ok, here's your code, put it inside a class module (CScrCpy.cls), and
instance the class in your code, to call the copy function pass it a
valid PictureBox control (may be invisible !) and call the ScrCpy it
will copy the desktop image to the picturebox, to save the image just
call the ImgSave method passing it the picturebox and the desired path
and filename

here's the code (watch the wrap !)

Option Explicit

'
' clsScrCpy - copies the screen contents to a picturebox
' and allows to save the image to a file
'

' APIs
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
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

' constants
Private Const SM_XVIRTUALSCREEN = 76
Private Const SM_YVIRTUALSCREEN = 77
Private Const SM_CXVIRTUALSCREEN = 78
Private Const SM_CYVIRTUALSCREEN = 79

' internal screen copy function
Private Sub ScrCopy(picCtl As PictureBox)
Dim Left As Long
Dim Top As Long
Dim Width As Long
Dim Height As Long
Dim hDC As Long, hDCdest As Long

' get the desktop hDC
hDC = GetWindowDC(GetDesktopWindow)

' get the desktop infos
Left = GetSystemMetrics(SM_XVIRTUALSCREEN)
Top = GetSystemMetrics(SM_YVIRTUALSCREEN)
Width = GetSystemMetrics(SM_CXVIRTUALSCREEN)
Height = GetSystemMetrics(SM_CYVIRTUALSCREEN)

' ensure the picture has a valid hDC and is clear
picCtl.AutoRedraw = True
picCtl.Cls

' set width and height to match destkop size
picCtl.Width = Screen.Width
picCtl.Height = Screen.Height

' get the picture hDC
hDCdest = picCtl.hDC

' copy the desktop to the picture
BitBlt hDCdest, 0, 0, Width, Height, hDC, Left, Top, vbSrcCopy
End Sub

' public method to copy screen to picturebox
Public Sub ScrCpy(picCtl As PictureBox)
ScrCopy picCtl
End Sub

' public method to save picture to file
Public Sub ImgSave(picCtl As PictureBox, byval sPathName As String)
SavePicture picCtl.Image, sPathName
End Sub
ObiWan
2024-02-16 09:40:34 UTC
Permalink
:: On Fri, 16 Feb 2024 09:55:55 +0100
:: (microsoft.public.vb.general.discussion)
Post by ObiWan
' public method to save picture to file
Public Sub ImgSave(picCtl As PictureBox, byval sPathName As String)
SavePicture picCtl.Image, sPathName
End Sub
Before I forget, the above will save the picture as a "BMP" file, if
you want to save the picture using a different format, see this code

https://www.vbforums.com/showthread.php?808301-VB6-PicSave-Simple-SavePicture-as-GIF-PNG-JPEG

HTH
ObiWan
2024-02-16 11:21:40 UTC
Permalink
:: On Fri, 16 Feb 2024 10:40:34 +0100
:: (microsoft.public.vb.general.discussion)
Post by ObiWan
Before I forget, the above will save the picture as a "BMP" file, if
you want to save the picture using a different format, see this code
https://www.vbforums.com/showthread.php?808301-VB6-PicSave-Simple-SavePicture-as-GIF-PNG-JPEG
The alternative, to spare space and keep the images "protected" could
be using a "zip" file, in such a case, the code may save the image as
standard BMP, which can be efficiently compressed, the BMP would then
be added to a password protected "zip" archive and the original "BMP"
would then be deleted; this way the images would be protected from an
unauthorized access and, at the same time, would take less disk space
Kim Hawker
2024-02-17 04:22:02 UTC
Permalink
Post by ObiWan
:: On Fri, 16 Feb 2024 10:40:34 +0100
:: (microsoft.public.vb.general.discussion)
Wow, ObiWan, thank you for your knowledge, this looks very complicated, I don't know if I can understand it enough to even code this. It'll probably take me a very long time to get this to work if I even can. did you try and test this code?
again Thank you for your efforts. I'll see what I can do. damn. lol
ObiWan
2024-02-19 08:15:28 UTC
Permalink
:: On Fri, 16 Feb 2024 20:22:02 -0800 (PST)
:: (microsoft.public.vb.general.discussion)
Post by Kim Hawker
Wow, ObiWan, thank you for your knowledge, this looks very
complicated, I don't know if I can understand it enough to even code
this. It'll probably take me a very long time to get this to work if
I even can. did you try and test this code? again Thank you for your
efforts. I'll see what I can do. damn. lol
Yes, I wrote and tested the code to grab an image of the screen and
save it (as BMP) to a file, and it works, didn't try the code used to
convert the BMP to another format, but if you're ok with BMP files then
the screen grab code may fit the bill, just create a new class module
in VB, paste the code into it and use the class in your code
ObiWan
2024-02-19 08:21:35 UTC
Permalink
:: On Mon, 19 Feb 2024 09:15:28 +0100
:: (microsoft.public.vb.general.discussion)
Post by ObiWan
Yes, I wrote and tested the code to grab an image of the screen and
save it (as BMP) to a file, and it works, didn't try the code used to
convert the BMP to another format, but if you're ok with BMP files
then the screen grab code may fit the bill, just create a new class
module in VB, paste the code into it and use the class in your code
to be clear, assuming the class module is named "clsScrCpy" your code
to call it would be something like

Sub GrabScreen()
Dim CSCRCP As clsScrCpy

Set CSCRCP = New clsScrCpy
CSCRCP.ScrCpy Picture1
CSCRCP.ImgSave Picture1, "c:\temp\image.bmp"
End Sub


where Picture1 is a picturebox placed on some form (it doesn't need to
be visible) and "c:\temp\image.bmp" is the pathname of the file where
you want to save the screen capture, nothing difficult as you see
ObiWan
2024-02-19 14:06:31 UTC
Permalink
:: On Mon, 19 Feb 2024 09:21:35 +0100
:: (microsoft.public.vb.general.discussion)
Post by ObiWan
to be clear, assuming the class module is named "clsScrCpy" your code
to call it would be something like
Or, even better, add to your project a form, call it "frmScrCpy", then
add to the form a picture control and add the "GrabScreen" method as
seen in the previous post, but changing it this way

Public Sub GrabScreen(ByVal sFile As String)
Dim CSCRCP As clsScrCpy

Set CSCRCP = New clsScrCpy
CSCRCP.ScrCpy Picture1
CSCRCP.ImgSave Picture1, sFile
End Sub

now, when you'll need to generate a screen capture, you may just use
some code like this in your app

Load frmScrCpy
frmScrCpy.Move -10000,-10000
frmScrCpy.GrabScreen "c:\foo\bar.bmp"
Unload frmScrCpy
Set frmSrcCpy=Nothing

:)
ObiWan
2024-02-23 10:57:18 UTC
Permalink
:: On Thu, 15 Feb 2024 21:28:19 -0800 (PST)
:: (microsoft.public.vb.general.discussion)
I have no idea of how to even start this coding but need vb6 code
any update ?

Loading...