.API Summary (Edit Controls)

Category: Controls - Edit Controls

Date: 02-16-2022

Return to Index


 
'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. All of these
'message can also be applied to RichEdit 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(StartPos), VarPTR(EndPos))  'selection start, end+1
   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, StartPos, 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(temp$))  'specified line, zero-based
   SendMessage(hEdit, %WM_GetText, TextLength, StrPTR(temp$)   'all text (use Em_GetTextLength for TextLength)
   
   'Replace Text
   SendMessage(hEdit, %EM_ReplaceSel, %True, StrPTR(temp$))
   
   '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
 
   'Set Text
   SendMessage(hEdit, %WM_SetText, 0, StrPTR(temp$)   'set text (replace all)
 
'gbs_00960
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm