[API]
RECT
GetDC
CreateCompatibleBitmap
ReleaseDC
CreateCompatibleDC
SelectObject
DeleteObject
DeleteDC
BitBlt
FillRect
LoadCursorA
CreateWindowExA
CreateWindowExW
DefWindowProcA
DefWindowProcW
SetWindowLongA
SetWindowLongW
GetWindowLongA
GetWindowLongW
DrawIconEx
DestroyWindow

[INCLUDE]
RegisterClassEx
Unicode
DrawSignalStrengthEx

[DEFINE]
Private SignalStrengthControl_NumCtls As Long
Private Const SignalStrengthControl_ClassName As String = "SignalStrength"

[CODE]
Public Function SignalStrengthControl_Create(ByVal hWndParent As Long, ByVal x As Long, ByVal y As Long, Optional ByVal xStyles As DrawSignalStrength_Styles = DSSS_Visible, Optional ByVal SignalStrength As Single = 0, Optional ByVal hIcon As Long) As Long
  Dim xType1 As WNDCLASSEX
  Dim xLong1 As Long
  Dim xLong2 As Long

  xLong1 = xStyles
  xLong1 = (xLong1 And &H100000F0) Or &H40000100 Or SignalStrengthControl_StrFloatToInt(SignalStrength)
  
  If SignalStrengthControl_NumCtls = 0& Then
    With xType1
      .cbSize = 48&
      .Style = &H83&
      .hInstance = App.hInstance
      .hCursor = LoadCursorA(App.hInstance, &H7F00&)
      .hbrBackground = 19&
      .ClassName = SignalStrengthControl_ClassName
      #If SignalStrengthControl_HasIcons Then
        .cbWndExtra = 4&
        #End If
      End With
    Call RegisterClassEx(xType1, AddressOf SignalStrengthControl_Proc)
    End If
  
  #If SignalStrengthControl_HasIcons Then
    xLong2 = 48&
    #Else
    xLong2 = 32&
    #End If

  If IsUnicode Then
    SignalStrengthControl_Create = CreateWindowExW(0&, ByVal StrPtr(SignalStrengthControl_ClassName), ByVal 0&, xLong1, x, y, xLong2, 16&, hWndParent, 0&, App.hInstance, ByVal 0&)
    Else
    SignalStrengthControl_Create = CreateWindowExA(0&, SignalStrengthControl_ClassName, "", xLong1, x, y, xLong2, 16&, hWndParent, 0&, App.hInstance, ByVal 0&)
    End If
  If Not SignalStrengthControl_Create = 0& Then
    #If SignalStrengthControl_HasIcons Then
      If Not hIcon = 0& Then
        If IsUnicode Then
          Call SetWindowLongW(SignalStrengthControl_Create, 0&, hIcon)
          Else
          Call SetWindowLongA(SignalStrengthControl_Create, 0&, hIcon)
          End If
        End If
      #End If
    Call SignalStrengthControl_Draw(SignalStrengthControl_Create)
    End If
  End Function

Private Function SignalStrengthControl_StrFloatToInt(ByVal SignalStrength As Single) As Long
  SignalStrengthControl_StrFloatToInt = Fix(SignalStrength * 6)
  If SignalStrengthControl_StrFloatToInt < 0& Then
    SignalStrengthControl_StrFloatToInt = 0&
    ElseIf SignalStrengthControl_StrFloatToInt > 5& Then
    SignalStrengthControl_StrFloatToInt = 5&
    End If
  End Function

Private Sub SignalStrengthControl_Draw(ByVal hWnd As Long)
  Dim hDC As Long
  Dim hBmp As Long
  Dim hBmpOld As Long
  Dim hDC2 As Long
  Dim xStyles As Long
  Dim OffsetX As Long
  Dim xType1 As RECT

#If SignalStrengthControl_HasIcons Then
  Dim hIcon As Long
  Dim xIconOff As Long
  #End If

  hDC = GetDC(0&)
  If Not hDC = 0& Then
    #If SignalStrengthControl_HasIcons Then
      hBmp = CreateCompatibleBitmap(hDC, 48&, 16&)
      #Else
      hBmp = CreateCompatibleBitmap(hDC, 32&, 16&)
      #End If
    Call ReleaseDC(0&, hDC)
    If Not hBmp = 0& Then
      hDC = CreateCompatibleDC(0&)
      If Not hDC = 0& Then
        hBmpOld = SelectObject(hDC, hBmp)
        If Not hBmpOld = 0& Then
          hDC2 = GetDC(hWnd)
          If Not hDC2 = 0& Then
            If IsUnicode Then
              xStyles = GetWindowLongW(hWnd, -16&)
              Else
              xStyles = GetWindowLongA(hWnd, -16&)
              End If
            If IsUnicode Then
              hIcon = GetWindowLongW(hWnd, 0&)
              Else
              hIcon = GetWindowLongA(hWnd, 0&)
              End If
            #If SignalStrengthControl_HasIcons Then
              If hIcon = 0& Then
                If (xStyles And CLng(DrawSignalStrength_Styles.DSSS_NoIconRight)) Then
                  OffsetX = 16&
                  ElseIf (xStyles And CLng(DrawSignalStrength_Styles.DSSS_NoIconCenter)) Then
                  OffsetX = 8&
                  'Else
                  'OffsetX = 0&
                  End If
                Else
                OffsetX = 16&
                End If
              '#Else
              'OffsetX = 0&
              xType1.Right = 48&
              #Else
              xType1.Right = 32&
              #End If
            xType1.Bottom = 16&
            #If DrawSignalStrength_WhiteBackgrounds Then
              If (xStyles And CLng(DrawSignalStrength_Styles.DSSS_WhiteBG)) = 0& Then
                Call FillRect(hDC, xType1, 16&)
                Else
                Call FillRect(hDC, xType1, 6&)
                End If
              #Else
              Call FillRect(hDC, xType1, 16&)
              #End If
            Call DrawSignalStrengthEx(hDC, OffsetX, 0&, (xStyles And &H7&), xStyles)
            #If SignalStrengthControl_HasIcons Then
              If Not hIcon = 0& Then
                Call DrawIconEx(hDC, 0&, 0&, hIcon, 16&, 16&, 0&, 0&, 3&)
                End If
              Call BitBlt(hDC2, 0&, 0&, 48&, 16&, hDC, 0&, 0&, vbSrcCopy)
              #Else
              Call BitBlt(hDC2, 0&, 0&, 32&, 16&, hDC, 0&, 0&, vbSrcCopy)
              #End If
            Call ReleaseDC(hWnd, hDC2)
            End If
          Call SelectObject(hDC, hBmpOld)
          End If
        Call DeleteDC(hDC)
        End If
      'If CreateSignalStrengthBitmap = 0& Then
        Call DeleteObject(hBmp)
      '  End If
      End If
    End If
  End Sub

Private Function SignalStrengthControl_Proc(ByVal hWnd As Long, ByVal message As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case message
    Case &H14&
    Case &HF& ', &H14& 'WM_PAINT = &HF
      If IsUnicode Then
        SignalStrengthControl_Proc = DefWindowProcW(hWnd, message, wParam, lParam)
        Else
        SignalStrengthControl_Proc = DefWindowProcA(hWnd, message, wParam, lParam)
        End If
      Call SignalStrengthControl_Draw(hWnd)
    Case Else
      If IsUnicode Then
        SignalStrengthControl_Proc = DefWindowProcW(hWnd, message, wParam, lParam)
        Else
        SignalStrengthControl_Proc = DefWindowProcA(hWnd, message, wParam, lParam)
        End If
    End Select
  End Function

Public Function SignalStrengthControl_Destroy(ByRef hWnd As Long)
  If Not hWnd = 0& Then
    Call DestroyWindow(hWnd)
    hWnd = 0&
    End If
  If SignalStrengthControl_NumCtls = 0& Then
    Call UnregisterClass(SignalStrengthControl_ClassName)
    End If
  End Function