Complete screen capture

Posted on 2005-04-06
Last Modified: 2010-04-23
I am attempting a screen capture using the following code:

Protected Sub CaptureScreen()
        Dim hSDC, hMDC As Integer
        Dim hBMP, hBMPOld As Integer
        Dim r As Integer
        hSDC = CreateDC("DISPLAY", "", "", "")
        hMDC = CreateCompatibleDC(hSDC)
        FW = GetDeviceCaps(hSDC, 8)
        FH = GetDeviceCaps(hSDC, 10)
        hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
        hBMPOld = SelectObject(hMDC, hBMP)
        r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
        hBMP = SelectObject(hMDC, hBMPOld)
        r = DeleteDC(hSDC)
        r = DeleteDC(hMDC)
        oBackground = Image.FromHbitmap(New IntPtr(hBMP))
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
        Me.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
        PictureBox1.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
        PictureBox1.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height

        PictureBox1.Image = oBackground
        PictureBox1.Image.Save("C:\netdiag\screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    End Sub


The screen is captured, but specifically some text in a form from another application is not captured.  I do know that the other application's form is a transparent panel/background with non-transparent text, the form is set to TopMost=true (it appears as black text with a transparent background over the desktop contents).  When I use the traditional print screen key this form is captured along with the rest of the screen.

Any help would be most appreciated.  Thanks.
Question by:ddrudik
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    LVL 27

    Author Comment

    Thanks, but that yielded the same result.
    LVL 85

    Accepted Solution

    How about this way then?

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
        Private Const VK_SNAPSHOT As Short = &H2CS

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PictureBox1.Image = GetScreen()
        End Sub

        Private Function GetScreen() As Bitmap
                keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
                Dim data As IDataObject = Clipboard.GetDataObject()
                If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                    Dim bmp As Bitmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
                    Return bmp
                End If
            Catch ex As Exception
            End Try
        End Function

    End Class
    LVL 27

    Author Comment

    Idle Mind, perfect as usual. Thanks a million!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now