Date: 02-16-2022
Return to Index
created by gbSnippets
'By default, a textbox has a 32K limit on the amount of text a user can type or
'paste into the control This can be changed, up to 64K.
'If user exceeds the default limit, a WM_COMMAND message containing an EN_MAXTEXT
'notification message is sent.
'Primary Code:
Local iLength&
iResult& = SendMessage(hEdit, %EM_GetLimitText, 0,0) 'current limit
iResult& = SendMessage(hEdit, %EM_SetLimitText, 0,0) '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 %ENMaxText
'notification message). $crlf characters are included in the count.
#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$ = "sample"
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.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(hEdit, %EM_GetLimitText, 0,0) 'current limit
MsgBox "Current Limit: " + Str$(iResult&)
iResult& = SendMessage(hEdit, %EM_SetLimitText, 10,0) 'FFFF=64K FFFFF=1M FFFFFFFF = 4G
iResult& = SendMessage(hEdit, %EM_GetLimitText, 0,0) 'current limit
MsgBox "New Limit: " + Str$(iResult&)
End If
End Function
'gbs_00137
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm