[API]
RECT
CreateCompatibleDC
DeleteDC
SelectObject
AdjustWindowRect

[INCLUDE]
DrawText
SendMessage
CreateWindowEx

[CODE]
Public Function AutoSizeXBox_CreateLite(ByVal Caption As String, ByVal dwStyles As Long, ByVal x As Long, ByVal y As Long, ByVal xMaxWidth As Long, ByVal xHeight As Long, ByVal hWndParent As Long, Optional ByVal hFont As Long) As Long
  Dim xType1 As RECT
  Dim xType2 As RECT
  Dim hFontOld As Long
  Dim hdc As Long
  Dim xLong1 As Long
  Dim xSp As Long
  Const XBoxSp As Long = 4&
  
  xSp = XBoxSp + xHeight
  hdc = CreateCompatibleDC(0&)
  If Not hdc = 0& Then
    If hFont = 0& Then
      If Not hWndParent = 0& Then
        hFont = SendMessage(hWndParent, &H31&, 0&, 0&)
        End If
      End If
    If Not hFont = 0& Then Call SelectObject(hdc, hFont)

    xType1.Right = &H3FFF&
    xType1.Bottom = &H3FFF&
    If Not DrawText(hdc, Caption, xType1, &H420&) = 0& Then
      xType2 = xType1
      If Not AdjustWindowRect(xType2, dwStyles, 0&) = 0& Then
        xLong1 = xType1.Right + xSp - xType1.Left
        If xLong1 > xMaxWidth Then 
          xLong1 = xMaxWidth
          #If AutoXBoxSize_CanEllipsis And Ellipsis_TextEnd Then
            Caption = Ellipsis_TextEnd(hdc, Caption, xMaxWidth - xSp + xType1.Right - (xType2.Right - xType2.Left))
            #End If
          EndIf
        AutoSizeXBox_CreateLite = CreateWindowEx(0&, "BUTTON", Caption, dwStyles, x, y, xLong1, xHeight, hWndParent, 0&, 0&)
        If Not (AutoSizeXBox_CreateLite = 0& or hFont = 0&) Then 
          Call SendMessage(AutoSizeXBox_CreateLite, &H30&, hFont, 0&)
          End If
        End If
      End If
    Call DeleteDC(hdc)
    End If
  End Function