Results 1 to 3 of 3

Thread: [RESOLVED] Screencapture class problem

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    44

    Resolved [RESOLVED] Screencapture class problem

    Hi all,

    I have found this screencapture class.
    VB Code:
    1. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As String) As Integer
    2.  
    3.     Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    4.  
    5.     Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
    6.  
    7.     Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
    8.  
    9.     Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
    10.  
    11.     Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
    12.  
    13.     Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
    14.  
    15.     Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
    16.  
    17.     Const SRCCOPY As Integer = &HCC0020
    18.  
    19.  
    20.  
    21.  
    22.     Public Shared Function GetScreen()
    23.         Dim oBackground As Bitmap
    24.         Dim FW, FH As Integer
    25.         Dim hSDC, hMDC As Integer
    26.         Dim hBMP, hBMPOld As Integer
    27.         Dim r As Integer
    28.  
    29.         hSDC = CreateDC("DISPLAY", "", "", "")
    30.         hMDC = CreateCompatibleDC(hSDC)
    31.  
    32.         FW = GetDeviceCaps(hSDC, 8)
    33.         FH = GetDeviceCaps(hSDC, 10)
    34.  
    35.         hBMP = CreateCompatibleBitmap(hSDC, FW, FH)
    36.  
    37.         hBMPOld = SelectObject(hMDC, hBMP)
    38.         r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)
    39.         hBMP = SelectObject(hMDC, hBMPOld)
    40.  
    41.         r = DeleteDC(hSDC)
    42.         r = DeleteDC(hMDC)
    43.  
    44.         oBackground = Image.FromHbitmap(New IntPtr(hBMP))
    45.         DeleteObject(hBMP)
    46.         Return oBackground
    47.     End Function
    But when I use it, it only makes an screenshot of my background how can I let it make a screenshot of an program that I am running instead?

    Already thanks,

    Smurf

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Screencapture class problem

    you don't need to use all those API functions:

    vb Code:
    1. Dim img As New Bitmap(Me.Width, Me.Height)
    2. Dim gr As Graphics = Graphics.FromImage(img)
    3. gr.CopyFromScreen(Me.Left, Me.Top, 0, 0, New Size(Me.Width, Me.Height))
    4. img.Save("test.bmp")
    5. Process.Start("test.bmp")

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Screencapture class problem

    This is from the CodeBank.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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