Click to See Complete Forum and Search --> : Screen Grabber
Rh0ads
Feb 16th, 2001, 04:14 PM
I've seen a lot of examples of how to capture pictures of the screen. But how do i capture only one window, specified by it's handle. Also, how do i turn a bitmap file to a gif or jpg?
Vlatko
Feb 16th, 2001, 07:06 PM
To capture the only the window, use its handle to get the window's rectangle(GetWindowRect). Then use those coordinates as parameters in the BitBlt API so that only that region is blited.
You could can get a picture of the active window. You can use the SetForegroundWindow API function to give a window focus and make it the active window.
Private Declare Sub keybd_event Lib "user32" (Byval _
bVk As Byte, Byval bScan As Byte, Byval dwFlags As _
Long, Byval dwExtraInfo As Long)
Private Declare Function SetForegroundWindow _
Lib "user32" (Byval hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
(Byval hwnd As Long, Byval nCmdShow As Long) As _
Long
Private Declare Sub Sleep Lib "kernel32" _
(Byval dwMilliseconds As Long)
Private Const SW_SHOWNORMAL = 1
Private Const VK_SNAPSHOT = &H2C
Private Function SaveScreen(Byval theFile As String, hWin As Long) As Boolean
On Error Resume Next
ShowWindow hWin, SW_SHOWNORMAL
SetForegroundWindow hWin
Doevents
Sleep 1
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
Savepicture Clipboard.GetData(vbCFBitmap), theFile
SaveScreen = True
Exit Function
End Function
Private Sub Command1_Click()
Call SaveScreen("C:\Windows\Desktop\Screen1.bmp", hWin)
End Sub
Lord Orwell
Feb 17th, 2001, 09:49 PM
using the api keybd_event, send the following keypress: alt-printscreen.
alt-printscreen will capture the foreground form to the clipboard.
If this isn't what you are looking for, a small sub i am working on can do what you want (except file convert). I have attached it. Use the sub CopyWindowGraphics
by passing it the handle to a window you want copied, and where you want to copy it to (form, picturebox, other window)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.