Attribute VB_Name = "modTextBoxFunctions"
Option Explicit

Const EM_GETSEL = &HB0
Const EM_SETSEL = &HB1
Const EM_GETRECT = &HB2
Const EM_SETRECT = &HB3
Const EM_SETRECTNP = &HB4
Const EM_SCROLL = &HB5
Const EM_LINESCROLL = &HB6
Const EM_SCROLLCARET = &HB7
Const EM_GETMODIFY = &HB8
Const EM_SETMODIFY = &HB9
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Const EM_SETHANDLE = &HBC
Const EM_GETHANDLE = &HBD
Const EM_GETTHUMB = &HBE
Const EM_LINELENGTH = &HC1
Const EM_REPLACESEL = &HC2
Const EM_GETLINE = &HC4
Const EM_LIMITTEXT = &HC5
Const EM_CANUNDO = &HC6
Const EM_UNDO = &HC7
Const EM_FMTLINES = &HC8
Const EM_LINEFROMCHAR = &HC9
Const EM_SETTABSTOPS = &HCB
Const EM_SETPASSWORDCHAR = &HCC
Const EM_EMPTYUNDOBUFFER = &HCD
Const EM_GETFIRSTVISIBLELINE = &HCE
Const EM_SETREADONLY = &HCF
Const EM_SETWORDBREAKPROC = &HD0
Const EM_GETWORDBREAKPROC = &HD1
Const EM_GETPASSWORDCHAR = &HD2
Const EM_SETMARGINS = &HD3
Const EM_GETMARGINS = &HD4
Const EM_SETLIMITTEXT = EM_LIMITTEXT
Const EM_GETLIMITTEXT = &HD5
Const EM_POSFROMCHAR = &HD6
Const EM_CHARFROMPOS = &HD7

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Sub TextBoxSetTabSize(ctlTextBox As TextBox, ByVal nTabSize As Integer)
    Dim nRet As Long
    Dim nTabSizeDBU As Long
    
    nTabSizeDBU = nTabSize * 4
    nRet = SendMessage(ctlTextBox.hwnd, EM_SETTABSTOPS, 1, nTabSizeDBU)
End Sub

Public Function TextBoxLineFromChar(ctlTextBox As TextBox, ByVal nCharOffset As Long) As Long
    Dim nRet As Long
    
    nRet = SendMessage(ctlTextBox.hwnd, EM_LINEFROMCHAR, nCharOffset, 0)
    
    TextBoxLineFromChar = nRet
End Function

Public Function TextBoxLineIndex(ctlTextBox As TextBox, ByVal nLineIndex As Long) As Long
    Dim nRet As Long
    
    nRet = SendMessage(ctlTextBox.hwnd, EM_LINEINDEX, nLineIndex, 0)
    
    TextBoxLineIndex = nRet
End Function
