Click to See Complete Forum and Search --> : changing files


ant
July 16th, 2001, 05:43 PM
I have a screen capturer. When the user presses a key it captures the screen. Then it saves the picture into a file. How do i make it that if there's an image called cap1, it will save the image as cap2, or cap3 etc. Help please!

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: christopherfolger@hotmail.com
for the address

John G Duffy
July 16th, 2001, 06:26 PM
Here is one way. Loop, using DIR to see if a named fiel exists by creating the Filename dynamically then testing for it.

private Sub Command1_Click()
Dim strX
Dim X
for X = 1 to 1000
strX = Dir("C:\My Documents\Cap" & X)
If strX = "" then Exit for

next X
MsgBox "Cap" & X & " Not found"
End Sub




John G

ant
July 16th, 2001, 06:42 PM
Ok, so how would i add that in to this code:?


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 Sub Command1_Click()
Dim wScreen as Long
Dim hScreen as Long
Dim w as Long
Dim h as Long
Picture1.Cls

wScreen = Screen.Width \ Screen.TwipsPerPixelX
hScreen = Screen.Height \ Screen.TwipsPerPixelY

Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight


hdcScreen = GetDC(0)

r = StretchBlt(Picture1.hdc, 0, 0, w, h, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)


End Sub



private Sub Form_Load()
KeyPreview = true
End Sub

private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
Select Case KeyCode
Case vbKeyC: Command1_Click

End Select
End Sub



It's supposed to save the picture as the filename of cap0,1,2... which ever is available

--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: christopherfolger@hotmail.com
for the address

John G Duffy
July 16th, 2001, 07:14 PM
I would create a function out of the code I gave with the function returning the next useable name
Something like this:

option Explicit

private Sub Command1_Click()
MsgBox GetGoodFileName
End Sub

public Function GetGoodFileName()
Dim strX
Dim X
for X = 1 to 1000
strX = Dir("C:\My Documents\Cap" & X)
If strX = "" then Exit for
next X
If X < 1000 then
GetGoodFileName = "C:\My Documents\Cap" & X
else
GetGoodFileName = ""
End If
End Function



As to where to insert this code, put it just before the statement you are using to save the picture. Your supplied routine does not show this. Command1 appears to be inserting the screen image into the picturebox but there is no save code. Possibly insert the code just after the Stretchblt then doing a
'
PICTURE1.Picture = Picture1.Image
'
followed by a
'
SavePicture

John G