Posts: 125
Threads: 20
Joined: Jan 2021
01-13-2021, 11:19 PM
(This post was last modified: 01-14-2021, 08:45 AM by macman.)
hello everyone,
I have a dialog problem:
When I press the OK button or Press enter or double-click an item in CB5, check the following conditions,
E3 cannot be empty, it must be an En letter, match [A-Za-z]
E4 cannot be empty, it must be a double byte character, match [\x80-\xff]
E6 cannot be empty
Gender two choice one
When all conditions are met, close the dialog box and output the value of the controls
If One of the condition does not met, the input point flashes in the control, prompting to re-enter
hope someone can complete this example. Thanks in advance
Macro Macro3
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_EDITCHANGE<<16|5 ;;cb5 type letters automatic completion
,sub.CB_AutoComplete lParam
,case IDOK
,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)
Posts: 229
Threads: 22
Joined: Sep 2007
i think this will help to some degree
Function Function4
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"
o11mal=1
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_EDITCHANGE<<16|5 ;;cb5 type letters automatic completion
,sub.CB_AutoComplete lParam
,case IDOK
,_s.getwintext(id(3 hDlg)); _s.trim
,
,if(_s.len and findrx(_s "^-?(\D+(\.\D*)?)?$")<0)
,,act id(3 hDlg) ;;editable text
,,ret
,_s.getwintext(id(4 hDlg)) _s.trim
,
,str pattern="[^\x80-\xff]+"
,if(_s.len and findrx(_s pattern)!=-1) ret
,_s.getwintext(id(6 hDlg)); _s.trim
,
,if(_s.len =0)
,,act id(6 hDlg) ;;editable text
,,ret
,
,if(!IsDlgButtonChecked(hDlg 11))
,,if(!IsDlgButtonChecked(hDlg 12))
,,,out "check gender"
,,,ret
,case IDCANCEL
Posts: 125
Threads: 20
Joined: Jan 2021
01-14-2021, 10:57 PM
(This post was last modified: 01-15-2021, 12:03 AM by macman.)
@ redbull2k
Thank you for your help,
The dialog box could not be closed
Has been successful, add the following code
ret 1
or
ret DT_Ret(hDlg 1)
Posts: 125
Threads: 20
Joined: Jan 2021
01-15-2021, 12:49 AM
(This post was last modified: 01-15-2021, 01:32 AM by macman.)
I added the same code for the CB control double-click event, But The dialog box cannot be closed by double click
Why?
case CBN_DBLCLK<<16|5
Click the OK button, I can successfully check the input and close the dialog box
Macro Macro3
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"
o11mal=1
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 IDOK
,_s.getwintext(id(3 hDlg)); _s.trim
,
,if(_s.len =0)
,,act id(3 hDlg) ;;e3 text
,,ret
,_s.getwintext(id(4 hDlg)) _s.trim
,
,if(_s.len =0)
,,act id(4 hDlg) ;;e4 text
,,ret
,_s.getwintext(id(6 hDlg)); _s.trim
,
,if(_s.len =0)
,,act id(6 hDlg) ;;e6 text
,,ret
,
,if(!IsDlgButtonChecked(hDlg 11))
,,if(!IsDlgButtonChecked(hDlg 12))
,,,out "check gender"
,,,ret
,
,case IDCANCEL
,
,case CBN_DBLCLK<<16|5
,_s.getwintext(id(3 hDlg)); _s.trim
,
,if(_s.len =0)
,,act id(3 hDlg) ;;e3 text
,,ret
,_s.getwintext(id(4 hDlg)) _s.trim
,
,if(_s.len =0)
,,act id(4 hDlg) ;;e4 text
,,ret
,_s.getwintext(id(6 hDlg)); _s.trim
,
,if(_s.len =0)
,,act id(6 hDlg) ;;e6 text
,,ret
,
,if(!IsDlgButtonChecked(hDlg 11))
,,if(!IsDlgButtonChecked(hDlg 12))
,,,out "check gender"
,,,ret
,
ret 1
Add the following code, can succeed
DT_Ok hDlg
Qm2 programming is really fun
Posts: 1,338
Threads: 61
Joined: Jul 2006
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.
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)
Posts: 125
Threads: 20
Joined: Jan 2021
@ Kevin
Thank you for your help,
It works perfectly
Posts: 125
Threads: 20
Joined: Jan 2021
@ Kevin
out cb5
______
0 one
How to output text only?
Posts: 1,338
Threads: 61
Joined: Jul 2006
cb5.replacerx("\d+ " "")
out cb5
Posts: 125
Threads: 20
Joined: Jan 2021
01-16-2021, 06:27 AM
(This post was last modified: 01-16-2021, 06:27 AM by macman.)
thanks! be realized like this?
I find that regular expressions are needed in many places
Posts: 1,338
Threads: 61
Joined: Jul 2006
sorry i forgot to add
You can also use this qm function to get just the text
TO_CBGetItem(cb5)
out cb5
Posts: 125
Threads: 20
Joined: Jan 2021
Thanks, this function is better understood.
|