|
-
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).
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
|