Advertisement
julioCCs

SS

Nov 11th, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.46 KB | None | 0 0
  1. 'http://www.facebook.com/GtaIVScripting
  2. 'https://www.youtube.com/user/GTAScripting
  3.  
  4. Imports System.Runtime.InteropServices
  5.  
  6. Public Class myClassName
  7.     '...
  8.     'this method will return a Bitmap or nothing if something goes wrong
  9.     '
  10.     Private Function CaptureScreen()
  11.         Dim m_HBitmap As IntPtr = Nothing
  12.         Dim bmp As System.Drawing.Bitmap = Nothing
  13.         Dim w, h As Int16
  14.         Dim hDC As IntPtr = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetForegroundWindow)
  15.         Dim hMemDC As IntPtr = PlatformInvokeGDI32.CreateCompatibleDC(hDC)
  16.  
  17.         w = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CXSCREEN)
  18.  
  19.         h = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CYSCREEN)
  20.  
  21.         m_HBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, w, h)
  22.  
  23.  
  24.         If (m_HBitmap <> IntPtr.Zero) Then
  25.             Dim hOld As IntPtr = PlatformInvokeGDI32.SelectObject(hMemDC, m_HBitmap)
  26.  
  27.             PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0, w, h, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY)
  28.  
  29.             PlatformInvokeGDI32.SelectObject(hMemDC, hOld)
  30.  
  31.             PlatformInvokeGDI32.DeleteDC(hMemDC)
  32.  
  33.             PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetForegroundWindow, hDC)
  34.  
  35.             bmp = System.Drawing.Image.FromHbitmap(m_HBitmap)
  36.  
  37.             PlatformInvokeGDI32.DeleteObject(m_HBitmap)
  38.  
  39.             Return bmp
  40.         Else
  41.             Return Nothing
  42.         End If
  43.     End Function
  44. End Class
  45. '
  46. ' this two classes contains dll imports of windows API
  47. Public Class PlatformInvokeGDI32
  48.     Public Const SRCCOPY As Int32 = 13369376
  49.  
  50.     <DllImport("gdi32.dll")> _
  51.     Public Shared Function DeleteDC(ByVal hDc As IntPtr) As IntPtr
  52.     End Function
  53.     <DllImport("gdi32.dll")> _
  54.     Public Shared Function DeleteObject(ByVal hDc As IntPtr) As IntPtr
  55.     End Function
  56.     <DllImport("gdi32.dll")> _
  57.     Public Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal xDest As Int32, ByVal yDest As Int32,
  58.  ByVal wDest As Int32, ByVal hDest As Int32, ByVal hdcSource As IntPtr, ByVal xSrc As Int32, ByVal ySrc As Int32, ByVal RasterOp As Int32) As Boolean
  59.     End Function
  60.     <DllImport("gdi32.dll")> _
  61.     Public Shared Function CreateCompatibleBitmap(ByVal hdc As IntPtr, ByVal nWidth As Int32, ByVal nHeight As Int32) As IntPtr
  62.     End Function
  63.     <DllImport("gdi32.dll")> _
  64.     Public Shared Function CreateCompatibleDC(ByVal hdc As IntPtr) As IntPtr
  65.     End Function
  66.     <DllImport("gdi32.dll")>
  67.     Public Shared Function SelectObject(ByVal hdc As IntPtr, ByVal bmp As IntPtr) As IntPtr
  68.     End Function
  69. End Class
  70. '
  71. Public Class PlatformInvokeUSER32
  72.     Public Const SM_CXSCREEN As Int32 = 0
  73.     Public Const SM_CYSCREEN As Int32 = 1
  74.  
  75.     <DllImport("user32.dll")> _
  76.     Public Shared Function GetForegroundWindow() As IntPtr
  77.     End Function
  78.     <DllImport("user32.dll")> _
  79.     Public Shared Function GetDC(ByVal ptr As IntPtr) As IntPtr
  80.     End Function
  81.     <DllImport("user32.dll")>
  82.     Public Shared Function GetSystemMetrics(ByVal abc As Int32) As Int32
  83.     End Function
  84.     <DllImport("user32.dll")>
  85.     Public Shared Function GetWindowDC(ByVal ptr As Int32) As IntPtr
  86.     End Function
  87.     <DllImport("user32.dll")>
  88.     Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr
  89.     End Function
  90.     <DllImport("dwmapi.dll")>
  91.     Public Shared Function Win32DwmEnableComposition(ByVal uCompositionAction As Int32) As Int32
  92.     End Function
  93. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement