Date: 02-16-2022
Return to Index
created by gbSnippets
'Working with text in an Edit Control can be done with both DDT and API statements.
'However, DDT has no statements which deal with selections, so it is common to use
'API when dealing with Edit Controls.
'Here's a summary of useful API to manipulate text in Edit Controls.
'But, in summary, here are the basic statements used. These can be used
'individually to get information, whereas the Functions in the compilable example
'below return several pieces of information with each call.
'API
'Get Character Positions
SendMessage(hEdit, %EM_GetSel, VarPTR(iStartPos&), VarPTR(iStopPos&)) 'start pos, 1st unselected
SendMessage(hEdit, %EM_LineIndex, LineNumber, 0) 'position of 1st char in line LineNumber
SendMessage(hEdit, %EM_LineIndex, -1, 0) 'position of 1st char in current line
'Get Line Numbers
SendMessage(hEdit, %EM_LineFromChar, -1, 0) 'CURRENT line
SendMessage(hEdit, %EM_LineFromChar, iStartPos&, 0) 'line containing specified character
'Get Length
SendMessage(hEdit, %EM_LineLength, CharPos, 0) 'length LINE
SendMessage(hEdit, %WM_GetTextLength, 0, 0) 'lenght ALL TEXT (+1 to cover terminating Chr$(0))
'Get LineCount
SendMessage(hEdit, %EM_GetLineCount, 0,0) 'total line count in control
'Get Text
SendMessage(hEdit, %EM_GetLine, LineNumber, StrPTR(buf$)) 'specified line, zero-based
SendMessage(hEdit, %EM_GetSelText, 0, StrPTR(buf$)) 'selected text
SendMessage(hEdit, %WM_GetText, TextLength, StrPTR(temp$) 'all text (use Em_GetTextLength for TextLength)
'Replace Text
SendMessage(hEdit, %EM_ReplaceSel, %True, StrPTR(buf$))
'Select Text
SendMessage(hEdit, %EM_SetSel, StartPos, EndPos 'select StartPos-EndPos
SendMessage(hEdit, %EM_SetSel, 0, -1 'select All
SendMessage(hEdit, %EM_SetSel, -1, 0 'select None
'gbs_00926
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm