?
Solved

Complete screen capture

Posted on 2005-04-06
4
Medium Priority
?
400 Views
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))
        DeleteObject(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

        CaptureScreen()
        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.
0
Comment
Question by:ddrudik
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13721383
0
 
LVL 27

Author Comment

by:ddrudik
ID: 13721437
Thanks, but that yielded the same result.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 13721745
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
        Try
            keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
            Application.DoEvents()
            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)
                Clipboard.SetDataObject(0)
                Return bmp
            End If
        Catch ex As Exception
        End Try
    End Function

End Class
0
 
LVL 27

Author Comment

by:ddrudik
ID: 13721810
Idle Mind, perfect as usual. Thanks a million!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

807 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