Results 1 to 9 of 9

Thread: screen capture or whatever

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    55

    Exclamation

    how can i use a timer to capture the screen every like minute or so then save it as a picture then compress it so later on i can decompress it
    ill use this to take pictures of pc games and stuff like that

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Lightbulb 1st part of an answer

    As an initial step you could try using the sendkeys() function to sent "alt" + "prtscrn" - that would at least capture the screen if in fact it is possible to send this combination of keys.

    Then you'd have to work with the clipboard the get it from there...this is where my knowledge ends.

    might help tho


  3. #3
    Member
    Join Date
    Feb 2000
    Posts
    52
    I've just spent the last three months of my spare time writing exactly what you're asking for. I could give you my code, but then you wouldn't learn anything, and I would just absolutely hate to deny anyone the learning experience that I have had . I will point you in the right direction, however.

    You'll need to familiarize yourself with the win32 API. A very good reference is "Dan Appleman's Programmer's Guide to the WIN32 API". But you can also find good online references.

    The essence of window captures (a specialized case of a screen capture):

    hWndActive = GetForegroundWindow()
    lRet = GetWindowRect(hWndActive, rct)
    dcActive = GetWindowDC(hWndActive)

    picCapture.width = rct.Right - rct.Left
    picCapture.height = rct.Bottom - rct.Top

    lRet= BitBlt(picCapture.hdc, 0, 0, picCapture.width, picCapture.height, dcActive, 0, 0, SRCCOPY)

    In order to save your images to a file in bitmap format, you'll need to be familiar with BITMAP, BITMAPINFOHEADER, BITMAPINFO, BITMAPFILEHEADER and RGBQUAD structures. You can look these up on MSDN (Microsoft Developer's Network) for descriptions of what they do, but the format is all C++, so you have to be able to convert to VB format (not really that hard) in order to use the code.

    To get the data out of your picture box (picCapture) in order to write it to a file, you'll need to use a GetDIBits() call:

    retVal = GetDIBits(picCapture.hdc, picCapture.Image, 0, bitmap.bmHeight, ByVal capturebuff_gptr, bitmapinfo, DIB_RGB_COLORS)


    And WriteFile() (after using CreateFile() to open) to write your data:

    ' write the bitmapinfo to the file
    retVal = WriteFile(hFile, bitmapinfo, Len(bitmapinfo), bytes_written, 0)
    ' write the data to the file
    retVal = WriteFile(hFile, ByVal capturebuff_gptr, buff_size, bytes_written, 0)

    Computing buff_size is a bit tricky. API bitmaps have to fall on long boundaries, meaning the total byte count has to be a multiple of 4 bytes. The correct math depends on the number of colors which GetDIBits() converted your bitmap into (it will do that). Use this as an exercise to keep your synapses firing crisply.

    Well, that's definitely enough to get you started. Doing compression is a whole 'nother ballgame. Be happy to handle regular files at first. Then worry about compression. I wrote a DLL in C++ to do my compression, but you can do it with VB if time is not a serious issue. When you come to it, you'll need to look up a run-length encoding scheme and vary it to suit your purposes (and programming ability- compression gets real complicated real quick). Don't even begin to consider any other compression schemes unless you know what a Fourier Transform is and can compute one by hand in less than an hour.

    When you come to particular issues you're having trouble with, post for help and be specific (in other words, don't be a whiney ass and ask someone to do all of the work for you).

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If you don't mind to use a picturebox and save the image to a bitmap in screen resolution, you can use the savepicture method.
    Otherwise you can use the procedure I posted earlier, to save it at a different resolution.
    http://forums.vb-world.net/showthread.php?threadid=6440

    Sorry ShepherdOfChaos, but I think it will take 3 month if he follows your directions.


    P.S.

    The solution funkyd77 suggested won't work. The helpfile clearly states that you can't use SendKeys to send the printscreen key.

    [Edited by Frans C on 05-01-2000 at 12:56 PM]

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    55

    Cool

    Thats all real helpful but i know how to use bitblt so ill make my program invisible and then in the timer ill say some thing like copy from 0,0 to max,max using srccopy then have the src set up as picturebox.
    Then itll save it as a bitmap then i need to learn how to compress files but i dont know exaclty how.
    i just know that you call some commands to shorten the file by renaming it with a uderscore at the end like
    "picture1.bmp" to "picture1.bm_"
    and when i do this id like to encrypt it so if i make an install programm i can make it so you cant iew the files without installing them

    Any body know a good site that teaches encryption of files and/or file compression

    Thanx

    ------------------------------------------------------------
    Computers are our future, past, and present.
    -TheVbUser
    ------------------------------------------------------------

  6. #6
    Member
    Join Date
    Feb 2000
    Posts
    52
    Originally posted by Frans C
    ...you can use the savepicture method.

    Sorry ShepherdOfChaos, but I think it will take 3 month if he follows your directions.

    Depends on what he wants to do, how much he wants to learn, and how powerful he wants his program to be. For my purposes, I had to reject using savepicture and standard compression very early on (though I did use them a bit while other components were being developed).

    If he really only wants to do what he wrote, he'd be better off downloading someone else's screen capture project. There are about a Gazillion out there. And it would only take about 3 minutes to download and install. I suspect, however, that what he really is trying to do is be quite devious, and write a spying program for hacking purposes. And if that's what he really wants, the "idiot proof" programming methods will not do at all. He has to tackle the real operating system (win32API) and not the candy-ass version handed down by VB.

  7. #7
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196
    Originally posted by Frans C

    P.S.

    The solution funkyd77 suggested won't work. The helpfile clearly states that you can't use SendKeys to send the printscreen key.

    [Edited by Frans C on 05-01-2000 at 12:56 PM]

    oh yeah - looks like i didnt read down far enough in the help file. Its somewhat stupid then that it mentions the code for the Print Screen key in the table with all the other keys, and then at the bottom says: note - you cant use printscreen. Silly buggers - oh well - hi ho...

  8. #8
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Wink

    You are correct when you say that SendKeys will not work, however, the keybd_event API call does.
    If you want the code to implement a screen capture this way just post a reply. It's a bit long so I don't want to post it if you don't want it
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I think Shepardofchaos way was the best, im using something similar to it. But when it comes to saving the picture i would use savepicture, then after that u need to compress the file, by either zipping it or executing a converter to make jpg's or gifs. To encrypt, try search for it here, i have seen some good ways of encrypting here. I liked that one that xors the byte array against a result of a random seed.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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