| VB5, VB6 When you put the API calls in a BAS module, they're easy to use with any form. You can also import the module into other projects. Option Explicit Private Declare Function SetWindowLong Lib _ "user32" Alias "SetWindowLongA" (ByVal hWnd As _ Long, ByVal nIndex As Long, ByVal dwNewLong As _ Long) As Long Private Declare Function GetWindowLong Lib _ "user32" Alias "GetWindowLongA" (ByVal hWnd As _ Long, ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Public ES As Long Private Declare Function SendMessageAsLong Lib _ "user32" Alias "SendMessageA" (ByVal hWnd As _ Long, ByVal wMsg As Long, ByVal wParam As _ Long, ByVal lParam As Long) As Long Private Declare Function SendMessageAsString Lib _ "user32" Alias "SendMessageA" (ByVal hWnd As _ Long, ByVal wMsg As Long, ByVal wParam As _ Long, ByVal lParam As String) As Long Private Const Max_Chars_Per_Line = 80 Private Const EM_GETLINE = &HC4 Private Const EM_GETLINECOUNT = &HBA Private Const EM_LINEFROMCHAR = &HC9 Private Const EM_LINELENGTH = &HC1 Private Const EM_UNDO = &HC7 Private Const ES_LOWERCASE = &H10& Private Const ES_UPPERCASE = &H8& Public Retn As Long Public Function GetLineCount (Source As TextBox) _ As Long GetLineCount = SendMessageAsLong(Source.hWnd, _ EM_GETLINECOUNT, 0, 0) End Function Public Function GetLineLength (Source As TextBox, _ LineNum As Long) As Long GetLineLength = SendMessageAsLong(Source.hWnd, _ EM_LINELENGTH, LineNum, 0) End Function Public Function GetCurrentLineNumber (Source As _ TextBox) As Long GetCurrentLineNumber = SendMessageAsLong _ (Source.hWnd, EM_LINEFROMCHAR, -1, 0) End Function Public Function GetLine (Source As TextBox, _ LineNumber As Long) As String Dim ByteLo As Byte Dim ByteHi As Byte Dim Buffer As String Dim ReturnedSize As Long ByteLo = Max_Chars_Per_Line And (255) ByteHi = Int(Max_Chars_Per_Line / 256) Buffer = Chr$(ByteLo) + Chr$(ByteHi) + _ Space$(Max_Chars_Per_Line - 2) ReturnedSize = SendMessageAsString _ (Source.hWnd, EM_GETLINE, LineNumber, Buffer) GetLine = Left$(Buffer, ReturnedSize) End Function Public Function Undo (Source As TextBox) As Long Undo = SendMessageAsLong(Source.hWnd, EM_UNDO, _ 0, 0) End Function Public Sub GetES(Source As TextBox) ES = GetWindowLong(Source.hWnd, GWL_STYLE) End Sub Public Function LowerCase (Source As TextBox) _ As Long LowerCase = SetWindowLong(Source.hWnd, _ GWL_STYLE, ES Or ES_LOWERCASE) End Function Public Function UpperCase (Source As TextBox) _ As Long UpperCase = SetWindowLong(Source.hWnd, _ GWL_STYLE, ES Or ES_UPPERCASE) End Function Public Function RestoreMixedCase (Source As _ TextBox) As Long RestoreMixedCase = SetWindowLong(Source.hWnd, _ GWL_STYLE, ES) 'presume ES is correct End Function |
Put API Controls in BAS Module |
India web developer web development India | Freelance web development ecommerce web developer | Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design