Imports System.Runtime.InteropServices

Namespace Systems
    Public Class Win32API
        'Константы
        'Стандартный стиль окна
        Public Const WS_POPUP = &H80000000
        Public Const WS_VISIBLE = &H10000000
        Public Const WS_CLIPSIBLINGS = &H4000000
        Public Const WS_CLIPCHILDREN = &H2000000
        Public Const WS_SYSMENU = &H80000
        'Расширенный стиль окна
        Public Const WS_EX_LEFT = &H0
        Public Const WS_EX_LTRREADING = &H0
        Public Const WS_EX_LAYERED = &H80000
        Public Const WS_EX_TRANSPARENT = &H20
        Public Const WS_EX_TOPMOST = &H8
        'Позволяет получить/установить расширеные стили
        Public Const GWL_EXSTYLE = -20
        '
        Public Const ULW_ALPHA As Int32 = &H2
        '
        Public Const AC_SRC_OVER As Byte = &H0
        Public Const AC_SRC_ALPHA As Byte = &H1

        'Структуры
        'Структура точка, необходима для API
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure Point
            Public x As Int32
            Public y As Int32

            Public Sub New(ByVal x As Int32, ByVal y As Int32)
                Me.x = x
                Me.y = y
            End Sub
        End Structure

        'Структура Размер необходима для API
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure Size
            Public cx As Int32
            Public cy As Int32

            Public Sub New(ByVal cx As Int32, ByVal cy As Int32)
                Me.cx = cx
                Me.cy = cy
            End Sub
        End Structure

        'Нужна для обновления многослойного окна
        <StructLayout(LayoutKind.Sequential, Pack:=1)> _
        Public Structure BLENDFUNCTION
            Public BlendOp As Byte
            Public BlendFlags As Byte
            Public SourceConstantAlpha As Byte
            Public AlphaFormat As Byte

            Public Sub New(ByVal BledOp As Byte, ByVal BlendFlags As Byte, ByVal SourceContrastAlpha As Byte, ByVal AlphaFormat As Byte)
                Me.BlendOp = BledOp
                Me.BlendFlags = BlendFlags
                Me.SourceConstantAlpha = SourceContrastAlpha
                Me.AlphaFormat = AlphaFormat
            End Sub
        End Structure

        'Объявления API
        'Получает контекст устройства 0-дисплей
        <DllImport("user32.dll")> _
        Public Shared Function GetDC(ByVal hWnd As IntPtr) As IntPtr
        End Function

        'Освобождает контекст
        <DllImport("user32.dll", ExactSpelling:=True)> _
        Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
        End Function

        'Удоляет контекст
        <DllImport("gdi32.dll")> _
        Public Shared Function DeleteDC(ByVal hdc As IntPtr) As Boolean
        End Function

        'Создает совместимый контекст с заданным устройством
        <DllImport("gdi32.dll")> _
        Public Shared Function CreateCompatibleDC(ByVal hDC As IntPtr) As IntPtr
        End Function

        'Выберает объект в заданный контекст
        <DllImport("gdi32.dll", ExactSpelling:=True)> _
        Public Shared Function SelectObject(ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
        End Function

        'Удоляет объект
        <DllImport("gdi32.dll")> _
        Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
        End Function

        'Обновляет многослойное окно
        <DllImport("user32.dll")> _
        Public Shared Function UpdateLayeredWindow(ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Win32API.Point, ByRef psize As Win32API.Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Win32API.Point, _
                    ByVal crKey As Int32, ByRef pblend As Win32API.BLENDFUNCTION, ByVal dwFlags As Int32) As Boolean
        End Function

        'Устанавливает стили окна
        <DllImport("user32.dll")> _
        Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal Index As Integer, ByVal gwNewLong As Integer) As Integer
        End Function

        'Получает стили окна
        <DllImport("user32.dll")> _
        Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal Index As Integer) As Integer
        End Function
    End Class
End Namespace