Results 1 to 3 of 3

Thread: Capture Desktop Image to File

  1. #1
    assbeef
    Guest

    Capture Desktop Image to File

    Can someone give me code to capture an image of your desktop and save it to a bmp file?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    VB Code:
    1. Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
    2.  
    3. Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
    4.  
    5. Dim dhandle As Long
    6. dhandle = GetDesktopWindow
    7. Dim ddc As Long
    8. ddc = GetDC(dhandle)

    Now just use BitBlt to draw the contents of the ddc DC to your pic box. Then just use the SavePicture method to save it to a file.
    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this:

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Private Const VK_SNAPSHOT = &H2C




    'Author: Dalin Nie (Edited by Matthew Gates)
    'Origin: http://www.vbcode.com
    'Purpose: This function capture the screen or the active window of your computer. Programmatically and save it to a .bmp file.
    'VB version: VB 6,VB 5,VB 4/32
    'Save Screen As Bitmap

    Private Function SaveScreen(ByVal theFile As String) As Boolean
    On Error Resume Next

    'To get the Entire Screen
    Call keybd_event(vbKeySnapshot, 1, 0, 0)

    'To get the Active Window
    'Call keybd_event(vbKeySnapshot, 0, 0, 0)

    SavePicture Clipboard.GetData(vbCFBitmap), theFile

    SaveScreen = True
    Exit Function
    End Function


    'Usage


    Call SaveScreen("C:\Windows\Desktop\shot1.bmp")

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