-
This is a function that will retrieve the first line of an edit box by passing the handle. It works great on Windows 2000, but crashes VB on Windows 98. WHY?!?!
Code:
Public Function GetLineText(hwnd As Long) As String
Dim li As Long, liCnt As Long, CurrentLine As String, result As Long
li = SendMessage(hwnd, EM_LINEINDEX, 1, ByVal 0&)
liCnt = SendMessage(hwnd, EM_LINELENGTH, li, ByVal 0&)
CurrentLine = MKI(CInt(liCnt)) & String(liCnt + 1, 0)
result = SendMessage(hwnd, EM_GETLINE, 1, ByVal CurrentLine)
CurrentLine = Left(CurrentLine, liCnt)
GetLineText = CurrentLine
End Function
Public Function MKI(x As Integer) As String
'This Function Sets up the EM_GETLINE Buffer.
Dim y As Long
y = CLng(x) And &HFFFF&
MKI = Chr(y And &HFF&) & Chr((y And &HFF00&) \ &H100&)
End Function
I really need to get this working on Windows 9x!
Thanks,
Jordan
-
There's got to be an equivalent function. Research.
-
How do you guarantee that liCnt is returning an integer from SendMessage?
MKI(CInt(liCnt)... will cause a problem otherwise. Why not use CLng instead and pass as a long to MKI(x As Integer). Maybe you cannot change that function declaration for some reason, but you immediately cast it back to Long anyway. WHY???!
Hope it helps,
Cheers,
Paul.
-
This one works:
Code:
Function API_EM_GetLn(tb As Control, ByVal LnNr As Long) As String
'Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam As Any)
Dim ln As String
Dim LnLen As Long
ln = Space$(256)
LnLen = SendMessage(tb.hwnd, EM_GETLINE, LnNr, ln)
API_EM_GetLn = Left$(ln, LnLen)
End Function
[Edited by rfo on 11-03-2000 at 08:03 AM]