PublicSharedFunction cap()Function cap() As Bitmap Dim desktopbmp As Bitmap =New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim g As Graphics = Graphics.FromImage(desktopbmp) g.CopyFromScreen(0, 0, 0, 0, _ New Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, _ System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)) Dim rect As Rectangle =New Rectangle(Cursor.Position.X - Cursor.Current.HotSpot.X, _ Cursor.Position.Y - Cursor.Current.HotSpot.Y, _ Cursor.Current.Size.Width, Cursor.Current.Size.Height) Cursor.Current.Draw(g, rect) Return desktopbmp End Function
Imports System Imports System.Collections.Generic Imports System.Text Imports System.Runtime.InteropServices Namespace ScreenshotCaptureWithMouseNamespace ScreenshotCaptureWithMouse.ScreenCapture Class Win32StuffClass Win32Stuff Class Variables#Region "Class Variables" PublicConst SM_CXSCREEN AsInteger=0 PublicConst SM_CYSCREEN AsInteger=1 PublicConst CURSOR_SHOWING As Int32 =1 <StructLayout(LayoutKind.Sequential)> _ PublicStructure ICONINFOStructure ICONINFO Public fIcon AsBoolean ' Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies Public xHotspot As Int32 ' Specifies the x-coordinate of a cursor's hot spot. If this structure defines an icon, the hot Public yHotspot As Int32 ' Specifies the y-coordinate of the cursor's hot spot. If this structure defines an icon, the hot Public hbmMask As IntPtr ' (HBITMAP) Specifies the icon bitmask bitmap. If this structure defines a black and white icon, Public hbmColor As IntPtr ' (HBITMAP) Handle to the icon color bitmap. This member can be optional if this End Structure <StructLayout(LayoutKind.Sequential)> _ PublicStructure POINTStructure POINT Public x As Int32 Public y As Int32 End Structure <StructLayout(LayoutKind.Sequential)> _ PublicStructure CURSORINFOStructure CURSORINFO Public cbSize As Int32 ' Specifies the size, in bytes, of the structure. Public flags As Int32 ' Specifies the cursor state. This parameter can be one of the following values: Public hCursor As IntPtr ' Handle to the cursor. Public ptScreenPos As POINT ' A POINT structure that receives the screen coordinates of the cursor. End Structure #End Region Class Functions#Region "Class Functions" <DllImport("user32.dll", EntryPoint:="GetDesktopWindow")> _ PublicSharedFunction GetDesktopWindow()Function GetDesktopWindow() As IntPtr End Function <DllImport("user32.dll", EntryPoint:="GetDC")> _ PublicSharedFunction GetDC()Function GetDC(ByVal ptr As IntPtr) As IntPtr End Function <DllImport("user32.dll", EntryPoint:="GetSystemMetrics")> _ PublicSharedFunction GetSystemMetrics()Function GetSystemMetrics(ByVal abc AsInteger) AsInteger End Function <DllImport("user32.dll", EntryPoint:="GetWindowDC")> _ PublicSharedFunction GetWindowDC()Function GetWindowDC(ByVal ptr As Int32) As IntPtr End Function <DllImport("user32.dll", EntryPoint:="ReleaseDC")> _ PublicSharedFunction ReleaseDC()Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDc As IntPtr) As IntPtr End Function <DllImport("user32.dll", EntryPoint:="GetCursorInfo")> _ PublicSharedFunction GetCursorInfo()Function GetCursorInfo(ByRef pci As CURSORINFO) AsBoolean End Function <DllImport("user32.dll", EntryPoint:="CopyIcon")> _ PublicSharedFunction CopyIcon()Function CopyIcon(ByVal hIcon As IntPtr) As IntPtr End Function <DllImport("user32.dll", EntryPoint:="GetIconInfo")> _ PublicSharedFunction GetIconInfo()Function GetIconInfo(ByVal hIcon As IntPtr, ByRef piconinfo As ICONINFO) AsBoolean End Function #End Region End Class End Namespace
GDIStuff.vb
Imports System Imports System.Collections.Generic Imports System.Text Imports System.Runtime.InteropServices Namespace ScreenshotCaptureWithMouseNamespace ScreenshotCaptureWithMouse.ScreenCapture Class GDIStuffClass GDIStuff Class Variables#Region "Class Variables" PublicConst SRCCOPY AsInteger=13369376 #End Region Class Functions#Region "Class Functions" <DllImport("gdi32.dll", EntryPoint:="CreateDC")> _ PublicSharedFunction CreateDC()Function CreateDC(ByVal lpszDriver As IntPtr, ByVal lpszDevice AsString, ByVal lpszOutput As IntPtr, ByVal lpInitData As IntPtr) As IntPtr End Function <DllImport("gdi32.dll", EntryPoint:="DeleteDC")> _ PublicSharedFunction DeleteDC()Function DeleteDC(ByVal hDc As IntPtr) As IntPtr End Function <DllImport("gdi32.dll", EntryPoint:="DeleteObject")> _ PublicSharedFunction DeleteObject()Function DeleteObject(ByVal hDc As IntPtr) As IntPtr End Function <DllImport("gdi32.dll", EntryPoint:="BitBlt")> _ PublicSharedFunction BitBlt()Function BitBlt(ByVal hdcDest As IntPtr, ByVal xDest AsInteger, ByVal yDest AsInteger, ByVal wDest AsInteger, ByVal hDest AsInteger, ByVal hdcSource As IntPtr, _ ByVal xSrc AsInteger, ByVal ySrc AsInteger, ByVal RasterOp AsInteger) AsBoolean End Function <DllImport("gdi32.dll", EntryPoint:="CreateCompatibleBitmap")> _ PublicSharedFunction CreateCompatibleBitmap()Function CreateCompatibleBitmap(ByVal hdc As IntPtr, ByVal nWidth AsInteger, ByVal nHeight AsInteger) As IntPtr End Function <DllImport("gdi32.dll", EntryPoint:="CreateCompatibleDC")> _ PublicSharedFunction CreateCompatibleDC()Function CreateCompatibleDC(ByVal hdc As IntPtr) As IntPtr End Function <DllImport("gdi32.dll", EntryPoint:="SelectObject")> _ PublicSharedFunction SelectObject()Function SelectObject(ByVal hdc As IntPtr, ByVal bmp As IntPtr) As IntPtr End Function #End Region End Class End Namespace
CaptureScreen.vb
Imports System.Drawing Imports System.Runtime.InteropServices Namespace ScreenshotCaptureWithMouseNamespace ScreenshotCaptureWithMouse.ScreenCapture Class CaptureScreenClass CaptureScreen 'This structure shall be used to keep the size of the screen. PublicStructure SIZEStructure SIZE Public cx AsInteger Public cy AsInteger End Structure PrivateSharedFunction CaptureDesktop()Function CaptureDesktop() As Bitmap Dim size As SIZE Dim hBitmap As IntPtr Dim hDC As IntPtr = Win32Stuff.GetDC(Win32Stuff.GetDesktopWindow()) Dim hMemDC As IntPtr = GDIStuff.CreateCompatibleDC(hDC) size.cx = Win32Stuff.GetSystemMetrics(Win32Stuff.SM_CXSCREEN) size.cy = Win32Stuff.GetSystemMetrics(Win32Stuff.SM_CYSCREEN) hBitmap = GDIStuff.CreateCompatibleBitmap(hDC, size.cx, size.cy) If hBitmap <> IntPtr.Zero Then Dim hOld As IntPtr =DirectCast(GDIStuff.SelectObject(hMemDC, hBitmap), IntPtr) GDIStuff.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, _ 0, 0, GDIStuff.SRCCOPY) GDIStuff.SelectObject(hMemDC, hOld) GDIStuff.DeleteDC(hMemDC) Win32Stuff.ReleaseDC(Win32Stuff.GetDesktopWindow(), hDC) Dim bmp As Bitmap = System.Drawing.Image.FromHbitmap(hBitmap) GDIStuff.DeleteObject(hBitmap) GC.Collect() Return bmp EndIf ReturnNothing End Function PrivateSharedFunction CaptureCursor()Function CaptureCursor(ByRef x AsInteger, ByRef y AsInteger) As Bitmap Dim bmp As Bitmap Dim hicon As IntPtr Dim ci AsNew Win32Stuff.CURSORINFO() Dim icInfo As Win32Stuff.ICONINFO ci.cbSize = Marshal.SizeOf(ci) If Win32Stuff.GetCursorInfo(ci) Then If ci.flags = Win32Stuff.CURSOR_SHOWING Then hicon = Win32Stuff.CopyIcon(ci.hCursor) If Win32Stuff.GetIconInfo(hicon, icInfo) Then x = ci.ptScreenPos.x -CInt(icInfo.xHotspot) y = ci.ptScreenPos.y -CInt(icInfo.yHotspot) Dim ic As Icon = Icon.FromHandle(hicon) bmp = ic.ToBitmap() Return bmp EndIf EndIf EndIf ReturnNothing End Function PublicSharedFunction CaptureDesktopWithCursor()Function CaptureDesktopWithCursor() As Bitmap Dim cursorX AsInteger=0 Dim cursorY AsInteger=0 Dim desktopBMP As Bitmap Dim cursorBMP As Bitmap Dim g As Graphics Dim r As Rectangle desktopBMP = CaptureDesktop() cursorBMP = CaptureCursor(cursorX, cursorY) If desktopBMP IsNot NothingThen If cursorBMP IsNot NothingThen r =New Rectangle(cursorX, cursorY, cursorBMP.Width, cursorBMP.Height) g = Graphics.FromImage(desktopBMP) g.DrawImage(cursorBMP, r) g.Flush() Return desktop Else Return desktopBMP EndIf EndIf ReturnNothing End Function End Class End Namespace
Public Shared Function cap()Function cap() As Bitmap Dim desktopbmp As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) Dim g As Graphics = Gra