Results 1 to 3 of 3

Thread: Screenshot taking

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Screenshot taking

    Hi i found some code to take screenshot from screen it works perfectly - but needs some changes and my vb.net - skill is pretty low -can someone help me plz? Code is here:
    Code:
    Imports System.Runtime.InteropServices
    Module Module1
    
        <DllImport("user32.dll")> _
        Public Function GetDesktopWindow() As IntPtr
        End Function
    
        <DllImport("user32.dll")> _
        Public Function GetDC(ByVal hWnd As IntPtr) As IntPtr
        End Function
    
        <DllImport("user32.dll")> _
        Public Function GetWindowDC(ByVal ptr As IntPtr) As IntPtr
        End Function
    
        <DllImport("user32.dll")> _
        Public Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
        End Function
    
        <DllImport("gdi32.dll")> _
        Public Function BitBlt(ByVal hdcDest As IntPtr, ByVal xDest As Integer, ByVal yDest As Integer, ByVal wDest As Integer, ByVal hDest As Integer, ByVal hdcSource As IntPtr, _
        ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal rop As CopyPixelOperation) As Boolean
        End Function
    
    
        Public Function GetScreenSnapshot(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) 
            Dim hwNd As Long
            Dim targetDC As Long
            Dim picHandle As Long
            Dim picHDC As Long
            Const vbSRCCOPY As Long = &HCC0020
    
            hwNd = GetDC(GetDesktopWindow)
    
    
            targetDC = GetWindowDC(hwNd)
            picHandle = Form2.PictureBox1.Handle
            picHDC = GetDC(picHandle)
    
            BitBlt(picHDC, 0, 0, width, height, hwNd, x, y, vbSRCCOPY)
        
            ReleaseDC(picHandle, picHDC)
            ReleaseDC(hwNd, targetDC)
           
        End Function
    
    End Module

    so now as it is - it taking part of screen and then drawing it into Form2.PictureBox1 - i need this code to return bitmap( without using any picture boxes) just bitmap of screened area. Any help? ( i put bold that part of code that probably need be changed to return bitmap instead of drawing image to picture box)
    P.S I probably can do like this "Mbitmap = picturebox1.image" аnd then "return Mbitmap" - but it not good solution -need smth that writes directly to bitmap without using picture box.

    P.S Sry for my bad english
    Last edited by biggreen; Jul 13th, 2011 at 11:07 AM.

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