CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: changing files

  1. #1
    Join Date
    May 2001
    Posts
    155

    changing files

    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: [email protected]
    for the address

  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: changing files

    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

  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: changing files

    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: [email protected]
    for the address

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: changing files

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured