Results 1 to 6 of 6

Thread: [RESOLVED] how to make a full screen screenshot

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2008
    Posts
    43

    Resolved [RESOLVED] how to make a full screen screenshot

    hi everybody
    im working on this little application for myself... when its done i want it to take screen shots of the entire screen at a given time. like every hour for example.
    right now im still stuck on the fist part. how to you take a full screen screen shot? anyone know? i know the crtl + PrtSc option, but i want to make an application which can do it by itself.
    so far i only found
    public sub command1_Click()
    Me.PrintForm
    End Sub
    but thats no use as it only takes a picture of the application. i need the whole screen.
    please help. have been trying to figure out for days...
    thanks in advance!!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to make a full screen screenshot

    Quote Originally Posted by theonlyhugeg
    please help. have been trying to figure out for days...
    thanks in advance!!
    For days? A simple search would have had you up & running in 5 minutes. Just searching this forum for Screen Capture has 12 pages of postings.

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: how to make a full screen screenshot

    the simple way is using the keybd_event api call. You tell it to raise a "prt scr" keypress and it will take a snapshot of the whole screen. Ctrl-prtscr if i remember correctly doesn't take the whole screen. It takes the active window.

    Note that you HAVE to use the api keybd_event for this. Sendkeys, etc. will NOT work.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2008
    Posts
    43

    Re: how to make a full screen screenshot

    Quote Originally Posted by LaVolpe
    For days? A simple search would have had you up & running in 5 minutes. Just searching this forum for Screen Capture has 12 pages of postings.
    hi
    i have indeed found something very useful.
    currently im using this:


    Option Explicit

    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 GetVersionExA Lib "kernel32" _
    (lpVersionInformation As OSVERSIONINFO) As Integer

    Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    End Type

    Private Const KEYEVENTF_KEYUP = &H2
    Private Const VK_SNAPSHOT = &H2C
    Private Const VK_MENU = &H12

    Dim blnAboveVer4 As Boolean

    Private Sub Command1_Click()
    If blnAboveVer4 Then
    keybd_event VK_SNAPSHOT, 0, 0, 0
    Else
    keybd_event VK_SNAPSHOT, 1, 0, 0
    End If
    End Sub

    Private Sub Command2_Click()
    If blnAboveVer4 Then
    keybd_event VK_SNAPSHOT, 1, 0, 0
    Else
    keybd_event VK_MENU, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
    End If
    End Sub

    Private Sub Command3_Click()
    ' Load the captured image into a PictureBox and print it
    Picture1.Picture = Clipboard.GetData()


    End Sub

    Private Sub Form_Load()
    Dim osinfo As OSVERSIONINFO
    Dim retvalue As Integer

    osinfo.dwOSVersionInfoSize = 148
    osinfo.szCSDVersion = Space$(128)
    retvalue = GetVersionExA(osinfo)
    If osinfo.dwMajorVersion > 4 Then blnAboveVer4 = True

    Picture1.Visible = True
    Command1.Caption = "Print Screen"
    Command2.Caption = "Alt+Print Screen"
    Command3.Caption = "Print Image"
    End Sub


    the print image command doesnt actually print the image, it only puts it in the picture box, and thats exactly what i want. but it doesnt show the entire screen as it wont fit. i know it is very simple to resize the screenshot into the picture box, and i knew how to do this before but i just cant remember and cant seem to find the right one which works for this method. also is there a way to safe the resized picture by itself in a predefined location without the user having to do this?
    if anyone knows please help
    thanks

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to make a full screen screenshot

    hmmm... Since you showed initiative, let me show you a fairly simple alternative.

    1. Add a picturebox to your form, set properties > AutoRedraw=True, Visible=False, Appearance=Flat, BorderStyle=0
    2. Add this code to a timer event, click event, or to a private function/sub.
    Code:
    ' these Declarations go in the declaration section
    Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Private Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
    Private Const CAPTUREBLT As Long = &H40000000
    
    Private Sub Command1_Click()
        Dim dtopDC As Long, dtopHwnd As Long
        
        ' clear the picture box & resize it if needed
        Picture1.Cls
        ' adjust next line if form's scalemode is not vbTwips so picbox is screen width/height
        Picture1.Move Picture1.Left, Picture1.Top, Screen.Width, Screen.Height
        
        ' get the desktop window handle and its DC
        dtopHwnd = GetDesktopWindow
        dtopDC = GetWindowDC(dtopHwnd)
        ' paint the desktop into the hidden picturebox & release desktop DC
        BitBlt Picture1.hdc, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY, dtopDC, 0, 0, vbSrcCopy Or CAPTUREBLT
        ReleaseDC dtopHwnd, dtopDC
        
        ' save the picture
        SavePicture Picture1.Image, "C:\screenshot.bmp"
    
    End Sub
    Edit: regarding seeing the entire screen shot. You can see above, one way to size the picbox to the screen dimensions. But you still won't get the entire image in view because form borders & titlebar will take away from the amount of space for your picbox. Of course, you could copy the screenshot into a hidden picbox (as shown above) then scale the image, say 25% or so, to a visible picbox. The hidden picbox would be used for saving fullscreen or you can save the 25% scaled version, or both.
    Last edited by LaVolpe; Jan 6th, 2008 at 12:06 AM.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2008
    Posts
    43

    Re: how to make a full screen screenshot

    thanks for that code!
    i can finally start with the real application now.

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