Results 1 to 4 of 4

Thread: Can you get this to work in Windows 98?

  1. #1
    Guest
    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

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    There's got to be an equivalent function. Research.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    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.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4
    Member
    Join Date
    Oct 2000
    Posts
    35
    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]
    rfo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width