Results 1 to 8 of 8

Thread: Screenshots

  1. #1
    Guest
    This will take a picture of the screen.

    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 Const VK_SNAPSHOT = &H2C
    
    
    Public 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
    Clipboard.Clear
    Exit Function
    End Function
    
    Usage:
    
    Call SaveScreen("C:\Windows\Desktop\ss.bmp")

  2. #2
    Guest

    Thumbs up

    Thx, but it uses the clipboard, all previous data is lost if you use this code

  3. #3
    Guest
    So copy the previous data to a variable or something and re-copy it.

    Code:
    Public Function SaveScreen(ByVal theFile As String) As Boolean
    On Error Resume Next
        prevclip = Clipboard.GetText()
        '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
    Clipboard.Clear
    Clipboard.SetText prevclip
    Exit Function
    End Function
    
    Usage:
    
    Call SaveScreen("C:\Windows\Desktop\ss.bmp")

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    This code copys the screen to Picture1:
    Code:
    Picture1.Autoredraw = True
    
    Dim ScreenDC as long
    
    ScreenDC = GetDC(0&)
    BitBlt Picture1.hdc,0,0,1024,768,ScreenDC,0,0,SRCCopy
    Picture1.Refresh
    Note: 1024=The screenwidth (pixels)
    768=The screenheight(pixels)
    Don't forget to add the API Declarations, I can't include them, because I don't have VB here.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    The smiley screwed up the code :-(

  6. #6
    Guest

    Thumbs up

    Thx guys, this works

  7. #7
    New Member
    Join Date
    Jul 2000
    Posts
    1

    Lightbulb

    Great !!!

    It works......
    Spezial thanks from Germany......

  8. #8
    New Member
    Join Date
    Nov 2001
    Posts
    10

    I get an error

    I tried this code

    Picture1.Autoredraw = True
    Dim ScreenDC as long
    ScreenDC = GetDC(0&)
    BitBlt Picture1.hdc,0,0,1024,768,ScreenDC,0,0,SRCCopyPicture1.Refresh

    I get the error sub or function not declared on GetDC

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