Date: 02-16-2022
Return to Index
created by gbSnippets
'By default, a RichEdit control has a 32K limit on the amount of text a user can type or
'paste into the control The text limit for both an edit control and the RichEdit control
'can be increased using the EM_SetLimitText, but only up to 64K. For a larger text
'limit, you must use EM_EXLimitText.
'Whatever limit is set, if a user exceeds the limit, a WM_COMMAND message containing
'an EN_MAXTEXT notification code is sent.
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Primary Code:
Local iMaxChar&
iResult& = SendMessage(hRichEdit, %EM_GetLimitText, 0,0) 'current limit
iResult& = SendMessage(hRichEdit, %EM_EXLimitText, 0,iMaxChar&) 'set new limit
'Compilable Example: (Jose Includes)
'This example limits the number of characters to 10. If the user trys to
'type in more than 10 chars, a message is displayed (responds to the EN_MaxText
'notification message). $crlf characters are included in the count.
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
Global hDlg as Dword, hRichEdit as Dword
Function PBMain() As Long
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "edit control."
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, 500, buf$,20,40,160,100, style&, %WS_EX_ClientEdge
Control Handle hDlg, 500 To hRichEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctlmsg = %EN_MaxText Then
MsgBox "I'm full!"
End If
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local iResult&
iResult& = SendMessage(hRichEdit, %EM_GetLimitText, 0,0) 'current limit
MsgBox "Current Limit: " + Str$(iResult&)
iResult& = SendMessage(hRichEdit, %EM_EXLimitText, 10,0) 'FFFF=64K FFFFF=1M FFFFFFFF = 4G
iResult& = SendMessage(hRichEdit, %EM_GetLimitText, 0,0) 'current limit
MsgBox "New Limit: " + Str$(iResult&)
End If
End Function
'gbs_00231
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm