Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'http://www.facebook.com/GtaIVScripting
- 'https://www.youtube.com/user/GTAScripting
- Imports System.Runtime.InteropServices
- Public Class myClassName
- '...
- 'this method will return a Bitmap or nothing if something goes wrong
- '
- Private Function CaptureScreen()
- Dim m_HBitmap As IntPtr = Nothing
- Dim bmp As System.Drawing.Bitmap = Nothing
- Dim w, h As Int16
- Dim hDC As IntPtr = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetForegroundWindow)
- Dim hMemDC As IntPtr = PlatformInvokeGDI32.CreateCompatibleDC(hDC)
- w = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CXSCREEN)
- h = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CYSCREEN)
- m_HBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, w, h)
- If (m_HBitmap <> IntPtr.Zero) Then
- Dim hOld As IntPtr = PlatformInvokeGDI32.SelectObject(hMemDC, m_HBitmap)
- PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0, w, h, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY)
- PlatformInvokeGDI32.SelectObject(hMemDC, hOld)
- PlatformInvokeGDI32.DeleteDC(hMemDC)
- PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetForegroundWindow, hDC)
- bmp = System.Drawing.Image.FromHbitmap(m_HBitmap)
- PlatformInvokeGDI32.DeleteObject(m_HBitmap)
- Return bmp
- Else
- Return Nothing
- End If
- End Function
- End Class
- '
- ' this two classes contains dll imports of windows API
- Public Class PlatformInvokeGDI32
- Public Const SRCCOPY As Int32 = 13369376
- <DllImport("gdi32.dll")> _
- Public Shared Function DeleteDC(ByVal hDc As IntPtr) As IntPtr
- End Function
- <DllImport("gdi32.dll")> _
- Public Shared Function DeleteObject(ByVal hDc As IntPtr) As IntPtr
- End Function
- <DllImport("gdi32.dll")> _
- Public Shared Function BitBlt(ByVal hdcDest As IntPtr, ByVal xDest As Int32, ByVal yDest As Int32,
- 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
- End Function
- <DllImport("gdi32.dll")> _
- Public Shared Function CreateCompatibleBitmap(ByVal hdc As IntPtr, ByVal nWidth As Int32, ByVal nHeight As Int32) As IntPtr
- End Function
- <DllImport("gdi32.dll")> _
- Public Shared Function CreateCompatibleDC(ByVal hdc As IntPtr) As IntPtr
- End Function
- <DllImport("gdi32.dll")>
- Public Shared Function SelectObject(ByVal hdc As IntPtr, ByVal bmp As IntPtr) As IntPtr
- End Function
- End Class
- '
- Public Class PlatformInvokeUSER32
- Public Const SM_CXSCREEN As Int32 = 0
- Public Const SM_CYSCREEN As Int32 = 1
- <DllImport("user32.dll")> _
- Public Shared Function GetForegroundWindow() As IntPtr
- End Function
- <DllImport("user32.dll")> _
- Public Shared Function GetDC(ByVal ptr As IntPtr) As IntPtr
- End Function
- <DllImport("user32.dll")>
- Public Shared Function GetSystemMetrics(ByVal abc As Int32) As Int32
- End Function
- <DllImport("user32.dll")>
- Public Shared Function GetWindowDC(ByVal ptr As Int32) As IntPtr
- End Function
- <DllImport("user32.dll")>
- Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr
- End Function
- <DllImport("dwmapi.dll")>
- Public Shared Function Win32DwmEnableComposition(ByVal uCompositionAction As Int32) As Int32
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement