Page 1 of 2 12 LastLast
Results 1 to 40 of 64

Thread: [RESOLVED] Screenshot-Help me

  1. #1

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Resolved [RESOLVED] Screenshot-Help me

    I want to get the whole screen in image control and then save it to my folder.
    Every thing is working fine except the image saved in the folder. Is there any problem in the following code? I also want that the image saved should be overwritten.

    vb Code:
    1. Private Sub Command1_Click()
    2. Timer1.Enabled = True
    3. Me.WindowState = vbMinimized
    4. End Sub
    5.  
    6. Private Sub Timer1_Timer()
    7. On Error GoTo errhandler
    8. Label1.Caption = Val(Label1.Caption) + 1
    9. For i = 1 To 10
    10.     Clipboard.Clear
    11.     keybd_event vbKeySnapshot, 0, 0, 0
    12.     DoEvents
    13.         Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    14.         SavePicture Image1.Picture, "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
    15.    
    16.      Next i
    17. errhandler:
    18.     MsgBox " completed"
    19.     Timer1.Enabled = False
    20. End Sub
    Last edited by vivek_master146; Jun 22nd, 2007 at 06:36 AM.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    I'm not sure you can do it this way. In case it may help I have attached a screen capture project I made some time ago.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    By the way, there's a mistake in the ini file:

    Must be:
    ;Default data directory
    Dir=C:

    rather than
    ;Default data directory
    Dir=C:\

    i.e., the backslash is automatically appended by the code.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Ur project is ok. But i want a program which should save no. of images which are specfied in the textbox and should use timer to save image at particular interval and it should also overwrite it without any error.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  5. #5
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    It shoudn't be to difficult to modify the project so as to have the program minimize the window state and, using a timer, set the code to capture the screen as many times as needed. To be sure, it's going to require a bit of work, of course.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  6. #6

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Ya. Because i will have to go through the whole code and i have just few months exp. in vb its bit diff. for me. can u modify my above code so that i can save it to a folder with interval and the files should also be overwritten
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  7. #7
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    Sorry, don't have much time now, but I can have a go at it maybe tomorrow in case no one provides any more suitable code. But I don't think you have to understand much of the code, just place the "shooting" code in the timer event to start with. See what's going on in the "Crop/Capture" button's click event handler. Thereafter modify as necessary, i.e., try to deal with all the errors that will pop up.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Screenshot

    To overwrite the files
    Code:
    If Dir("C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp") > vbNullString Then Kill "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
    SavePicture Image1.Picture, "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Ok. I have got the code.its working fine except it generates error sometimes.The error is "Can't open clipboard" in the line "Set Image1.Picture = Clipboard.GetData(vbCFBitmap)". The code is:


    vb Code:
    1. Private Sub Timer1_Timer()
    2. i = i + 1
    3. Label1.Caption = Val(Label1.Caption) + 1
    4.     Clipboard.Clear
    5.     keybd_event vbKeySnapshot, 0, 0, 0
    6.     DoEvents
    7.    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    8.         SavePicture Image1.Picture, "C:\Documents and Settings\Vivek\My Documents\screenshots\image" & i & ".bmp"
    9.     Image1.Picture = Nothing
    10.     If i = 10 Then
    11.     Timer1.Enabled = False
    12.     End If
    13. End Sub
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  10. #10

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    I typed "On error resume next".Now its working.But i m not satisfied. i dont want to get that error.Help!
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  11. #11

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    When am i clicking on another window then the error is displaying otherwise when i am just kepping my pc idle then no error is dispalyed. Should i use api function other than timer?
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  12. #12
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    Hi vivek ...
    Is it must to use this code to capture window. or you can accept a different code to do the same jop.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  13. #13

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot


    Is it must to use this code to capture window. or you can accept a different code to do the same jop.
    This is for what i am asking for? Is there any other way i could do or by making some modifications in my code?
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  14. #14
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    I think it's better to use more advanced API that gives you the ability to capture window. and to get such a code just search the forum for a Capture word .
    or get this direct link to ready project made by Moeur member
    http://www.vbforums.com/attachment.p...8&d=1123272285
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  15. #15

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Hey! I want to capture images at intervals and save them in a folder. i have done it. but the only prob is the error.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  16. #16
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    can you explain what error ...?
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  17. #17
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    Quote Originally Posted by vivek_master146
    Hey! I want to capture images at intervals and save them in a folder. i have done it..
    Does that mean it actually worked in some cases?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  18. #18
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    Hi krtxmrtz ...
    It works if you used the right code.!!!
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  19. #19
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    What is keybd_event?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  20. #20
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    it's an API function to send buttons press event for keyboard
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  21. #21
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot

    Quote Originally Posted by ashraf fawzy
    it's an API function to send buttons press event for keyboard
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    I see.
    All I can say is I've found this site http://www.cgi-interactive-uk.com/sc..._creation.html with code very similar to Vivek_Master146's, only there is a slight difference: rather than

    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)

    they have this other statement,

    ScreenCapture.Picture = Clipboard.GetData(vbCFBitmap)

    i.e., without the "Set" command. I wonder if that could make a difference such as to cause the error. On the other hand, the code on that site is using a picturebox. I wonder if Image1 in Vivek_Master146's code is an Image control or a Picturebox.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  22. #22

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    It is a image control
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  23. #23
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    I think if you like , you should use the the link I provided above , it gives you more abilities to capture windows or just part of it.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  24. #24
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Screenshot

    vivek_master, i don't want to have you change your whole way of thinking, but the only useful function i can think of for this is you have two computers any you are monitoring the snapshot from another computer. If this is why you are doing this, windows has built-in tools for this.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  25. #25

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    I am attaching the project. The error is not displaying if the project is in focus and when i m mizimizing the project then the error is displaying.Help!
    Attached Files Attached Files
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  26. #26

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    I just want to keep a check on the activities of the cpomputer by capturing screenshot at intervals and saving it to a folder?
    Quote Originally Posted by Lord Orwell
    vivek_master, i don't want to have you change your whole way of thinking, but the only useful function i can think of for this is you have two computers any you are monitoring the snapshot from another computer. If this is why you are doing this, windows has built-in tools for this.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  27. #27
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    Try to add this without any modification :and let me know :

    Private Sub Timer1_Timer()
    keybd_event vbKeySnapshot, 0, 0, 0
    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    SavePicture Image1.Picture, "C:\image1.bmp"
    End Sub
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  28. #28

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Quote Originally Posted by ashraf fawzy
    Try to add this without any modification :and let me know :

    Private Sub Timer1_Timer()
    keybd_event vbKeySnapshot, 0, 0, 0
    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    SavePicture Image1.Picture, "C:\image1.bmp"
    End Sub
    Ur code will generate error as the name image1.bmp is same. and if u write a code to overwrite it then also it will save 1 image i.e.image1. i want to save multiple images.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  29. #29
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    Take an advice from a friend : No need to do jop with hard way , while you have to do it with easy way . there's too ways to do this jop ,nice and easy without dealing with keyboard event or clipboard data ,and both of them not truly under control from you.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  30. #30
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    ok , plz tell me the truly aim of your program to tell you the best way - from my point of view - to do it.cause there's too many different solution at my mind , but I need to decide the best for the your situation.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  31. #31

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    I just want to capture whole screen and then save it to a folder at intervals.Simple!
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  32. #32
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    and just for your knowledge , it'll not give you an erro if you saved the picture over old captured picture , unless you set the attribute of the picture file to readonly.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  33. #33
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    ok , I can't help you any more about this task while you working in keybd_event function - It's not at my own library , but with your code and with my little help of explaning about error at saving picture , I'm sure you can deal with this.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  34. #34

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    Ok I know if its attribute is archive then i will not give error. But it will not solve my purpose.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  35. #35
    Addicted Member Ashraf Alshahawy's Avatar
    Join Date
    May 2007
    Location
    Egypt
    Posts
    241

    Re: Screenshot

    ok ..you can use the increment I + 1 to save your ten captured pictures
    but I can't give you a promise that Clipboard.GetData will not raise an error ,
    cause I told you , you dealing with somthing not stable (Clipboard) which many programs dealing with it , at the same time your program does. I hope that I made the proplem of your code more clear.
    Some times when you make a step forward ...You can't get back. Be sure where you make your steps.

  36. #36

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot

    There is nobody to solve my problem.I just want to capture whole screen and then save it to a folder at intervals.Simple!
    What is the prb. in my code?
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

  37. #37
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Screenshot-Help me hack!

    Please stop bumping your threads.

  38. #38
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Screenshot-Help me hack!

    Are you still using
    Code:
    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    I just ran your code, with
    Code:
    Image1.Picture = Clipboard.GetData(vbCFBitmap)
    for 25 pictures, with the form being minimized in the 3rd one, and it didn't throw an error.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  39. #39
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Screenshot-Help me hack!

    Quote Originally Posted by Al42
    Are you still using
    Code:
    Set Image1.Picture = Clipboard.GetData(vbCFBitmap)
    I just ran your code, with
    Code:
    Image1.Picture = Clipboard.GetData(vbCFBitmap)
    for 25 pictures, with the form being minimized in the 3rd one, and it didn't throw an error.
    That's what I pointed out in post #21.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  40. #40

    Thread Starter
    Fanatic Member vivek_master146's Avatar
    Join Date
    Apr 2006
    Location
    Delhi,India
    Posts
    787

    Re: Screenshot-Help me hack!

    I tried both the method set and without set. then also it is displaying error?It will give error when i minizmize the project and click on another window.
    Dont rely only on your luck. Work hard until You get success.
    vb Code:
    1. Private sub Time_ispassing
    2. While Me.Notgetsuccess
    3. trygain=tryagain+1
    4. Me.workhard
    5. wend
    6. end sub

Page 1 of 2 12 LastLast

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