VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
Here is how to perform a screenshot and save it to Paint automatically
with a timestamp file name. I dont know if anyone find this useful,
but it shows the mechanics of automating a program on the same
calling thread.
VB Code:
Option Explicit
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 FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE As Long = &H10
Private Const WM_QUIT As Long = &H12
Private Const VK_SNAPSHOT As Byte = 44
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_V = &H56
Private Const VK_F = &H46
Private Const VK_S = &H53
Private Const VK_MENU = &H12
Private Const KEYEVENTF_KEYUP = &H2
Private Const BM_CLICK As Long = &HF5
Private Const WM_SETTEXT As Long = &HC
Private Sub Command1_Click()
Dim strFilePathName As String
Dim lHwnd As Long
Dim lHwndC As Long
Dim lHwndC1 As Long
Dim lHwndC2 As Long
Dim dDelay As Date
Dim sFileName As String
Clipboard.Clear
DoEvents
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
DoEvents
'PATH DEPENDS UPON OS (WIN2K AND BELOW - XP = C:\Windows\System32\mspaint.exe)
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
This code is brilliant - thanks for sharing.
I wanted to ask, I need to take this code one step further. I need to save the .bmp as a .jpg. I can make the extension in the file name as NAME.jpg, but the file type stays as bitmap.
Do you know how to change the combo box file type to jpg? (I need to change the file type to jpg to save space).
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
Originally Posted by janineweyers
This code is brilliant - thanks for sharing.
I wanted to ask, I need to take this code one step further. I need to save the .bmp as a .jpg. I can make the extension in the file name as NAME.jpg, but the file type stays as bitmap.
Do you know how to change the combo box file type to jpg? (I need to change the file type to jpg to save space).
Thanks in advance.
VB doesn't directly support saving to JPEG.
But you can use this code here so you don't have to use a 3rd party OCX/DLL file.
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
HI everybody.
First of all thank's to RobDog888 for this cool code.
It's very useful also because it explains tips about FindWindowEX and so on...
I run the project but it doesn't work .
Is it my fault ? When i run program, paint starts, then nothing to do...
I would like use this program. May you help me ?
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
Is there any chance to make this work on windows 7? It always stop when paint is launch and would it possible just capture active documents like what Alt + Screenshot do not the whole windows?
I'm living in VBForum bcz its members deserve respect and appreciation
Posts
333
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
Thank you Rob. For your brilliant code. I have used it all work fine except it's not change File Name in Combobox? and i have do some code to see as below:
Code:
'
'
'
lHwndC = FindWindowEx(lHwnd, 0&, "COMBOBOXEX32", "")
If (lHwndC = 0) Then
MsgBox ("lHwndC , window not found") ' msgbox shows as lHwndC not found
End If
Do Until lHwndC <> 0
lHwndC = FindWindowEx(lHwnd, 0&, "COMBOBOXEX32", vbNullString)
Loop
lHwndC1 = FindWindowEx(lHwndC, 0&, "COMBOBOX", vbNullString)
'
'
'
Please Why it's File Name not updated? Please assist?
I'm living in VBForum bcz its members deserve respect and appreciation
Posts
333
Re: VB6 - Automaticall save screenshot to MS Paint and save with a timestamp filename
Now i got above post to work and it's working. Thank you again gor your awesome code.
I just wondering how to change the directory of saved image path as i point you in attached image by using vb6 code? for example i want to saved picture in directory E:\Damage. Thank you