01-15-2021, 06:34 AM
there is a bug in the code where the dialog will still close with e3 and e4 not having text if you just put text in e6 and check a gender. Also don't need to add code from ID_OK to CBN_DBLCLK to check can simply click the ok button and checks will be done and if correct dialog will close.
here is updated code fixing bugs above.
Also added a a balloon tooltip for the edit controls as better visual cue when the conditions are not met.
here is updated code fixing bugs above.
Also added a a balloon tooltip for the edit controls as better visual cue when the conditions are not met.
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 Edit 0x54030080 0x200 8 12 96 13 ""
;4 Edit 0x54030080 0x200 116 12 96 13 ""
;6 Edit 0x54230084 0x200 8 40 96 70 ""
;5 ComboBox 0x54230641 0x0 116 40 96 70 ""
;7 Static 0x54000000 0x0 8 0 48 12 "e3"
;8 Static 0x54000000 0x0 116 0 48 12 "e4"
;9 Static 0x54000000 0x0 8 28 48 13 "e6"
;10 Static 0x54000000 0x0 116 28 48 13 "cb5"
;11 Button 0x54032009 0x0 8 123 46 10 "male"
;12 Button 0x54002009 0x0 54 123 50 10 "female"
;13 Static 0x54000000 0x4 8 112 48 13 "Gender:[]"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""
str controls = "3 4 6 5 11 12"
str e3 e4 e6 cb5 o11mal o12fem
cb5="&one[]onee[]two[]three[]four[]five"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
out e3
out e4
out e6
out cb5
#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 CBN_DBLCLK<<16|5
,but id(1 hDlg)
,case CBN_EDITCHANGE<<16|5 ;;cb5 type letters automatic completion
,sub.CB_AutoComplete lParam
,case IDOK
,_s.getwintext(id(3 hDlg)); _s.trim
,if(_s.len=0 or findrx(_s "^-?(\D+(\.\D*)?)?$")<0)
,,act id(3 hDlg) ;;editable text
,,sub.SetEditBallonTip(3 hDlg _s.len)
,,ret
,_s.getwintext(id(4 hDlg)) _s.trim
,str pattern="[^\x80-\xff]+"
,if(_s.len=0 or findrx(_s pattern)!=-1)
,,act id(4 hDlg)
,,sub.SetEditBallonTip(4 hDlg _s.len)
,,ret
,_s.getwintext(id(6 hDlg)); _s.trim
,if(_s.len =0)
,,act id(6 hDlg) ;;editable text
,,sub.SetEditBallonTip(6 hDlg)
,,ret
,if(!IsDlgButtonChecked(hDlg 11))
,,if(!IsDlgButtonChecked(hDlg 12))
,,,out "check gender"
,,,ret
,case IDCANCEL
ret 1
#sub CB_AutoComplete
function hcb
ifk(B) ret
ifk(X) ret
str s ss; int i
s.getwintext(hcb)
if(s.len)
,i=CB_FindItem(hcb s)
,if(i>=0)
,,CB_GetItemText(hcb i ss)
,,if(ss.len>s.len)
,,,ss.setwintext(hcb)
,,,SendMessage(hcb CB_SETEDITSEL 0 ss.len<<16|s.len)
#sub SetEditBallonTip
function cid hwnd [etLen]
EDITBALLOONTIP ebt
ebt.cbStruct=sizeof(ebt)
ebt.pszTitle=@"Unacceptable Character"
ebt.ttiIcon=TTI_ERROR
sel cid
,case 3
,if(etLen=0)
,,ebt.pszText=@"Cannot be Empty"
,else
,,ebt.pszText=@"You may only type letters a-z here"
,case 4
,if(etLen=0)
,,ebt.pszText=@"Cannot be Empty"
,else
,,ebt.pszText=@"You may only type double byte characters here"
,case 6
,ebt.pszText=@"Cannot be Empty"
SendMessage(id(cid hwnd) EM_SHOWBALLOONTIP 0 &ebt)