Date: 02-16-2022
Return to Index
created by gbSnippets
'The following code uses various message to get the topline of a RichEdit
'control and then the text from that line.
'Primary Code:
Function GetTopLine(ByVal hEdit as DWord) As String
Local buf$, iTopLine&, iLineLength&, iCharPos&
iTopLine& = SendMessage(hEdit, %EM_GetFirstVisibleLine,0,0) 'visible line# at top of control
iCharPos& = SendMessage(hEdit, %EM_LineIndex, iTopLine&, 0) 'position of 1st char in top line
iLineLength& = SendMessage(hEdit, %EM_LineLength, iCharPos&, 0) 'length of line starting at that char position
buf$ = Space$(iLineLength&)
SendMessage(hEdit, %EM_GetLine, iTopLine&, StrPTR(buf$)) 'entire line of text
Function = buf$
End Function
'Compilable Example: (Jose Includes)
'This example gets the text of the topmost visible line
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord, hEdit As DWord
Function PBMain() As Long
Local style&, buf$
style& = %WS_TabStop Or %WS_Border Or %ES_Left Or %ES_AutoHScroll Or %ES_MultiLine Or %ES_NoHideSel Or %ES_WantReturn
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "edit control."
Dialog New Pixels, 0, "TextBox Test",300,300,200,200, %WS_SysMenu, 0 To hDlg
Control Add Button, hDlg, 100,"Push", 50,20,100,20
Control Add TextBox, hDlg, 200,buf$, 50,50,100,100, style&
Control Handle hDlg, 200 To hEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
MsgBox GetTopLine(hEdit)
End If
End Function
Function GetTopLine(ByVal hEdit as DWord) As String
Local buf$, iTopLine&, iLineLength&, iCharPos&
iTopLine& = SendMessage(hEdit, %EM_GetFirstVisibleLine,0,0) 'visible line# at top of control
iCharPos& = SendMessage(hEdit, %EM_LineIndex, iTopLine&, 0) 'position of 1st char in top line
iLineLength& = SendMessage(hEdit, %EM_LineLength, iCharPos&, 0) 'length of line starting at that char position
buf$ = Space$(iLineLength&)
SendMessage(hEdit, %EM_GetLine, iTopLine&, StrPTR(buf$)) 'entire line of text
Function = buf$
End Function
'gbs_00134
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm