|
-
Apr 30th, 2000, 08:00 AM
#1
Thread Starter
Member
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
-
Apr 30th, 2000, 12:29 PM
#2
Addicted Member
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
-
Apr 30th, 2000, 12:34 PM
#3
Member
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).
-
Apr 30th, 2000, 11:52 PM
#4
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]
-
May 1st, 2000, 05:43 AM
#5
Thread Starter
Member
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
------------------------------------------------------------
-
May 1st, 2000, 10:05 AM
#6
Member
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.
-
May 3rd, 2000, 07:38 AM
#7
Addicted Member
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...
-
May 3rd, 2000, 10:08 AM
#8
Addicted Member
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  )
-
May 3rd, 2000, 04:02 PM
#9
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|