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

Thread: Capture Screen + Save

  1. #1
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125

    Capture Screen + Save

    hello,

    How can I take a screenshot, and then write it to a bmp file, p.e. the program automaticly takes the shot, and then writes it to a folder.

    Thanks
    Bert Willekens,

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Links to similar requests and answers

    Here I posted links to find code about capturing screen.
    http://www.codeguru.com/forum/showth...hlight=capture

    Cesare Imperiali
    Last edited by Cimperiali; April 12th, 2003 at 09:18 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    As per your request via Private mail...

    Howe to take screenshots of current form every 5 minutes and save them as bmp files:
    Download attached zip file. It is a working Vb example. Open it by doubleclicking on the Vbp file.

    To capture entire screen, look for next reply...
    Attached Files Attached Files
    Last edited by Cimperiali; April 11th, 2003 at 07:36 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Capture the whole screen

    Previous example captured only current form. To capture whole screen, I did it a bit different:
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Third: reduce bmp to 256 (or less) colors

    This third example is the same as above, but it has one extra feature: reduces size of saved Bmp to 256 (or less, if you enter code and modify passed values) colors. This is usefiul to reduce size of Bmp saved (around 1/3 lighter each).
    Wraning: in this example as in the previous one, I changed the timer to trig every 3 seconds instead of every 5 minutes (to test without waiting too much)...
    The module that reduces colors of Bmp is not mine: code comes from http://www.Planet-Source-Code.com/vb...36162&lngWId=1 Credits on this feature must go to that author. I modified a bit the code changing all the "if...end if" in a more structured "If...ElseIf...End If"
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Capture Screen + Save

    Fourth... as per request by one user, the same code as last one with a different filename....
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Apr 2003
    Posts
    322

    Re: Capture Screen + Save

    Quote Originally Posted by Cimperiali
    Fourth... as per request by one user, the same code as last one with a different filename....
    I've just tried using this as an example for a program I'm working on. It seems to work.
    I'm curious why you used the SetTimer/Killtimer, instead of the timer component in vb.

    thanks

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Capture Screen + Save

    Because the originalrequest where all this started from was to take
    a screenshot every 5 minutes. With Api Timer, you can set that intreval without
    having to skip cycles as you have to do with a "normal" timer control.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  9. #9
    Join Date
    Apr 2003
    Posts
    322

    Re: Capture Screen + Save

    Quote Originally Posted by Cimperiali
    Because the originalrequest where all this started from was to take
    a screenshot every 5 minutes. With Api Timer, you can set that intreval without
    having to skip cycles as you have to do with a "normal" timer control.
    Thanks for the explantion- but do you mean skip CPU cycles?
    Why is that an issue based on the original 5 minute interval?

    Where is it documented that the vb timer skips cycles, and the timer that you used does not?

    I don't believe I have read anything about this cycle issue, in regard to the timers.

    SetTimer
    The SetTimer function creates a timer with the specified time-out value.
    UINT SetTimer(
    HWND hWnd, // handle of window for timer messages
    UINT nIDEvent, // timer identifier
    UINT uElapse, // time-out value
    TIMERPROC lpTimerFunc // address of timer procedure
    );

    Parameters
    hWnd
    Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
    nIDEvent
    Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored.
    uElapse
    Specifies the time-out value, in milliseconds.
    lpTimerFunc
    Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc <timers_52xv.htm>.
    If lpTimerFunc is NULL, the system posts a WM_TIMER <timers_1w6q.htm> message to the application queue. The hwnd member of the message's MSG <JavaScript:alink_1.Click()> structure contains the value of the hWnd parameter.
    Return Values
    If the function succeeds, the return value is an integer identifying the new timer. An application can pass this value, or the string identifier, if it exists, to the KillTimer <timers_88xe.htm> function to destroy the timer.
    If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError <errors_3uwi.htm>.
    Remarks
    An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.
    The wParam parameter of the WM_TIMER message contains the value of the nIDEvent parameter.



    Thanks- this is really getting interesting

  10. #10
    Join Date
    May 2005
    Location
    Sunny Adelaide
    Posts
    66

    Re: Capture Screen + Save

    Quote Originally Posted by cappy2112
    Thanks for the explantion- but do you mean skip CPU cycles?
    Why is that an issue based on the original 5 minute interval?
    Nah, Cimperiali is talking about the maximum interval that you can set the timers to. The native VB timer object has a maximum interval of 65,535 ms, which is just over a minute. Therefore, if the interval is set to 1 minute, 4 out of every 5 _Timer events need to be disregarded, in order to achieve the 5 minute interval requested. With the API timer, you can set an actual 5 minute interval (I presume, haven't tried) so there is no need to "skip cycles".

    Cimperiali - I hope I interpreted your post right
    You are here.

  11. #11
    Join Date
    Apr 2003
    Posts
    322

    Re: Capture Screen + Save

    Quote Originally Posted by penagate
    Nah, Cimperiali is talking about the maximum interval that you can set the timers to. The native VB timer object has a maximum interval of 65,535 ms, which is just over a minute. Therefore, if the interval is set to 1 minute, 4 out of every 5 _Timer events need to be disregarded, in order to achieve the 5 minute interval requested. With the API timer, you can set an actual 5 minute interval (I presume, haven't tried) so there is no need to "skip cycles".

    Cimperiali - I hope I interpreted your post right

    Ahh- I see. Yes, it makes total sense now.

    Thanks to both of you !

  12. #12
    Join Date
    Apr 2003
    Posts
    322

    Re: Capture Screen + Save

    Quote Originally Posted by penagate
    Nah, Cimperiali is talking about the maximum interval that you can set the timers to. The native VB timer object has a maximum interval of 65,535 ms, which is just over a minute. Therefore, if the interval is set to 1 minute, 4 out of every 5 _Timer events need to be disregarded, in order to achieve the 5 minute interval requested. With the API timer, you can set an actual 5 minute interval (I presume, haven't tried) so there is no need to "skip cycles".

    Cimperiali - I hope I interpreted your post right

    Wait- now I'm confused. Both timers have a 65535 ms interval resolution- at least from my documentation.

    So I don't see how you could get much over 1 minute with either timer.

  13. #13
    Join Date
    Jul 2010
    Posts
    1

    Re: Capture Screen + Save

    The application in captureandsave256bmp.zip works fine. But I wonder why the author save the file as BMP, cant it be saved as jpg or other format which would reduce the file size?

  14. #14
    Join Date
    Apr 2009
    Posts
    394

    Re: Capture Screen + Save

    Ahhhh!!!! Look its a necrophilliac, a necromonger, no! It's a necroposter!!! To which we all say ewwwww!!! Disgusting!

    Okay, enough ragging on you. Please, in the future six, create a new thread and copy the url into your new thread.

    Now, to answer your question...

    Look up the SavePicture function to know why it is saved as a BMP...

    Then use your best friends (yahoo, google, ask, answers, bing) to search for vb6 save as jpg and see the vbaccelerator example.

    Then remember that the jpg/jpeg libraries were still under copy right law at the time vb6.0 came out...



    Good Luck

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center