Results 1 to 4 of 4

Thread: Screen Grabber

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210
    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?
    < o >

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    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.


    Code:
    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

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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)
    Attached Files Attached Files
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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