Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Limiting the text within an edit box control
#1
I need the text within an edit box to match a specific regular expression.

The event I have chosen is: when the edit box loses focus: EN_KILLFOCUS.

If the text within the current edit box does not match the specified regular expression: display a prompt text, and keep the text caret still within the edit box.

If the text within the current edit box matches the specified regular expression: do not display a prompt text, and move the text caret to inside the control after a mouse click.

The code below works as expected when I only add EN_KILLFOCUS event to one edit box.
However, when I add EN_KILLFOCUS event to all edit boxes, the position of the text caret is incorrect (as shown in the image below).
https://i.ibb.co/27D7KkZ/a.gif

How solve this problem? Thank you in advance for any suggestions and help.

Macro rxMatch2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x204 8 48 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3 4 5"
str e3 e4 e5
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,
,case EN_KILLFOCUS<<16|3
,sub.rxMatch(3 hDlg "^\d\D*$" "Not match ^\d\D*$")

,case EN_KILLFOCUS<<16|4
,sub.rxMatch(4 hDlg "^\d\D*$" "Not match ^\d\D*$")

,case EN_KILLFOCUS<<16|5
,sub.rxMatch(5 hDlg "^\d\D*$" "Not match ^\d\D*$")
ret 1

#sub rxMatch
function _id hDlg $_rx $_tip

int h=id(_id hDlg)
_s.getwintext(h)

if findrx(_s _rx)=-1
,RECT r; GetWindowRect h r
,act h
,OnScreenDisplay _tip 5 r.right r.top 0 10 1 4|8|16 "o1" 0xE0FFFF
#2
Already resolved, validation is done when clicking the OK button. 
The above approach is more direct, but I haven't found a solution yet.

Macro rxMatch2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 8 96 12 ""
;4 Edit 0x54030080 0x200 8 28 96 13 ""
;5 Edit 0x54030080 0x204 8 48 96 13 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3 4 5"
str e3 e4 e5
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,foreach _s "3[]4[]5"
,,out _s
,,if(!sub.rxMatch(val(_s) hDlg "^\d\D*$" "Not match ^\d\D*$")) ret
,
,case IDCANCEL
ret 1

#sub rxMatch
function _id hDlg $_rx $_tip

int h=id(_id hDlg)
_s.getwintext(h)

if findrx(_s _rx)=-1
,RECT r; GetWindowRect h r
,act h
,OnScreenDisplay _tip 5 r.right r.top 0 10 1 4|8|16 "o1" 0xE0FFFF
,ret
ret 1


Forum Jump:


Users browsing this thread: 1 Guest(s)