Advertisement
Guest User

Win32API.vb

a guest
Feb 26th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.38 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Imports System.Drawing
  3.  
  4. Friend Module Win32API
  5.  
  6. #Region " Constants & Enums "
  7.     Public Const LR_LOADFROMFILE = &H10
  8.  
  9. #Region " TernaryRasterOperations "
  10.     ''' <summary>
  11.     '''     Specifies a raster-operation code. These codes define how the color data for the
  12.     '''     source rectangle is to be combined with the color data for the destination
  13.     '''     rectangle to achieve the final color.
  14.     ''' </summary>
  15.     Public Enum TernaryRasterOperations As UInteger
  16.         ''' <summary>dest = source</summary>
  17.         SRCCOPY = &HCC0020
  18.         ''' <summary>dest = source OR dest</summary>
  19.         SRCPAINT = &HEE0086
  20.         ''' <summary>dest = source AND dest</summary>
  21.         SRCAND = &H8800C6
  22.         ''' <summary>dest = source XOR dest</summary>
  23.         SRCINVERT = &H660046
  24.         ''' <summary>dest = source AND (NOT dest)</summary>
  25.         SRCERASE = &H440328
  26.         ''' <summary>dest = (NOT source)</summary>
  27.         NOTSRCCOPY = &H330008
  28.         ''' <summary>dest = (NOT src) AND (NOT dest)</summary>
  29.         NOTSRCERASE = &H1100A6
  30.         ''' <summary>dest = (source AND pattern)</summary>
  31.         MERGECOPY = &HC000CA
  32.         ''' <summary>dest = (NOT source) OR dest</summary>
  33.         MERGEPAINT = &HBB0226
  34.         ''' <summary>dest = pattern</summary>
  35.         PATCOPY = &HF00021
  36.         ''' <summary>dest = DPSnoo</summary>
  37.         PATPAINT = &HFB0A09
  38.         ''' <summary>dest = pattern XOR dest</summary>
  39.         PATINVERT = &H5A0049
  40.         ''' <summary>dest = (NOT dest)</summary>
  41.         DSTINVERT = &H550009
  42.         ''' <summary>dest = BLACK</summary>
  43.         BLACKNESS = &H42
  44.         ''' <summary>dest = WHITE</summary>
  45.         WHITENESS = &HFF0062
  46.         ''' <summary>
  47.         ''' Capture window as seen on screen.  This includes layered windows
  48.         ''' such as WPF windows with AllowsTransparency="true"
  49.         ''' </summary>
  50.         CAPTUREBLT = &H40000000
  51.     End Enum
  52. #End Region
  53. #End Region
  54.  
  55. #Region " Structures "
  56.     <StructLayout(LayoutKind.Explicit)> Public Structure STRUCT_BITMAP
  57.         <FieldOffset(0)> Public bmType As Int32
  58.         <FieldOffset(4)> Public bmWidth As Int32
  59.         <FieldOffset(8)> Public bmHeight As Int32
  60.         <FieldOffset(12)> Public bmWidthBytes As Int32
  61.         <FieldOffset(16)> Public bmPlanes As Int16
  62.         <FieldOffset(18)> Public bmBitsPixel As Int16
  63.         <FieldOffset(20)> Public bmBits As Int32
  64.     End Structure
  65.     Public Structure CUSTOM_BITMAP
  66.         Dim hBmp As IntPtr
  67.         Dim hDC As IntPtr
  68.         Dim hOld As IntPtr
  69.         Dim Info As STRUCT_BITMAP
  70.     End Structure
  71.  
  72.     <StructLayout(LayoutKind.Sequential)> _
  73.     Public Structure STRUCT_RECT
  74.         Public left As Int32
  75.         Public top As Int32
  76.         Public right As Int32
  77.         Public bottom As Int32
  78.     End Structure
  79. #End Region
  80.  
  81. #Region " API Methods "
  82.     ''' <summary>
  83.     '''    Performs a bit-block transfer of the color data corresponding to a
  84.     '''    rectangle of pixels from the specified source device context into
  85.     '''    a destination device context.
  86.     ''' </summary>
  87.     ''' <param name="hdc">Handle to the destination device context.</param>
  88.     ''' <param name="nXDest">The leftmost x-coordinate of the destination rectangle (in pixels).</param>
  89.     ''' <param name="nYDest">The topmost y-coordinate of the destination rectangle (in pixels).</param>
  90.     ''' <param name="nWidth">The width of the source and destination rectangles (in pixels).</param>
  91.     ''' <param name="nHeight">The height of the source and the destination rectangles (in pixels).</param>
  92.     ''' <param name="hdcSrc">Handle to the source device context.</param>
  93.     ''' <param name="nXSrc">The leftmost x-coordinate of the source rectangle (in pixels).</param>
  94.     ''' <param name="nYSrc">The topmost y-coordinate of the source rectangle (in pixels).</param>
  95.     ''' <param name="dwRop">A raster-operation code.</param>
  96.     ''' <returns>
  97.     '''    <c>true</c> if the operation succeeded, <c>false</c> otherwise.
  98.     ''' </returns>
  99.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  100.     Public Function BitBlt(ByVal hdc As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As TernaryRasterOperations) As Boolean
  101.     End Function
  102.  
  103.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  104.     Public Function CreateCompatibleDC(ByVal hRefDC As IntPtr) As IntPtr
  105.     End Function
  106.  
  107.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  108.     Public Function CreateCompatibleBitmap(ByVal hdc As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr
  109.     End Function
  110.  
  111.     <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> _
  112.     Public Function GetDC(ByVal hwnd As IntPtr) As IntPtr
  113.     End Function
  114.  
  115.     <DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> _
  116.     Public Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  117.     End Function
  118.  
  119.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  120.     Public Function SelectObject(ByVal hdc As IntPtr, ByVal hObject As IntPtr) As IntPtr
  121.     End Function
  122.  
  123.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  124.     Public Function DeleteObject(ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  125.     End Function
  126.  
  127.     <DllImport("gdi32.dll", ExactSpelling:=True, SetLastError:=True)> _
  128.     Public Function DeleteDC(ByVal hdc As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  129.     End Function
  130.  
  131.  
  132.  
  133.     'Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal Width As Long, ByVal Height As Long, ByVal opmode As Long) As Long
  134.     <DllImport("user32.dll", SetLastError:=True)> _
  135.     Public Function LoadImage(ByVal hInst As IntPtr, ByVal lpszName As String, ByVal uType As UInt32, ByVal cxDesired As Integer, ByVal cyDesired As Integer, ByVal fuLoad As UInt32) As IntPtr
  136.     End Function
  137.     'Public Declare Function GetObject Lib "gdi32" (ByVal hObject As Long, ByVal nCount As Long, ByVal lpObject As IntPtr) As Long
  138.     <DllImport("gdi32.dll", SetLastError:=True)> _
  139.     Public Function GetObject(ByVal hgdiobj As IntPtr, ByVal cbBuffer As Integer, ByVal lpvObject As IntPtr) As Integer
  140.     End Function
  141.     'Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
  142.     <DllImport("gdi32.dll", SetLastError:=True)> _
  143.     Public Function GetPixel(ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer) As UInteger
  144.     End Function
  145.     'Public Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
  146.     <DllImport("gdi32.dll", SetLastError:=True)> _
  147.     Public Function SetPixel(ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer, ByVal crColor As Integer) As UInteger
  148.     End Function
  149.  
  150.     <DllImport("user32.dll")> _
  151.     Public Function FillRect(ByVal hDC As IntPtr, ByRef lprc As STRUCT_RECT, ByVal hbr As IntPtr) As Integer
  152.     End Function
  153.  
  154.     <DllImport("gdi32.dll")> _
  155.     Public Function CreateSolidBrush(ByVal crColor As UInteger) As IntPtr
  156.     End Function
  157.  
  158. #End Region
  159.  
  160. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement