Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
countdown code comes from function InputBox
#1
Hi,
The countdown code in the macro below comes from function InputBox

I have two problems:
1.I added color and font to the countdown text, Text overlaps as it is displayed

2. Types(___INPBOX) are defined in the code , However, it might be more convenient to use the v tag (#sub DlgProc v)
Is there any advantage to using types(___INPBOX) in this function?
Code:
Copy      Help
type ___INPBOX flags timeoutS dlgProc
___INPBOX z.flags=flags; z.timeoutS=timeoutS

Thanks in advance for any advice and help
david

Macro M1
Code:
Copy      Help
int timeoutS=10
int flags=128

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 128 88 "Dialog" "4"
;3 Static 0x44000002 0x0 40 16 12 12 ""
;4 Edit 0x54030080 0x200 16 32 96 14 ""
;1 Button 0x54030001 0x4 8 64 48 14 "OK"
;2 Button 0x54030000 0x4 72 64 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4"
str e4

type ___INPBOX flags timeoutS dlgProc
___INPBOX z.flags=flags; z.timeoutS=timeoutS

if(!ShowDialog(dd &sub.DlgProc &controls 0 flags&64 0 0 &z)) ret


#sub DlgProc
function# hDlg message wParam lParam

___INPBOX& z=+DT_GetParam(hDlg); if(!&z) ret
sel message
,case WM_INITDIALOG
,__Font-- f.Create("Microsoft YaHei Mono" 12 0); f.SetDialogFont(hDlg "3 4")
,f.SetDialogFontColor(hDlg 0xFF0000 "3 4")
,
,if z.timeoutS>0
,,hid- id(3 hDlg)
,,SetTimer hDlg 1 1000 0
,case WM_TIMER
,sel wParam
,,case 1
,,z.timeoutS-1
,,if(z.timeoutS>0) _s=z.timeoutS; _s.setwintext(id(3 hDlg))
,,else KillTimer hDlg 1; if(z.flags&128) DT_Ok hDlg 2; else DT_Cancel hDlg
,,ret 1
,case WM_SETCURSOR
,if lParam>>16!WM_MOUSEMOVE
,,;g1
,,if(z.timeoutS>0) KillTimer hDlg 1; z.timeoutS=0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,
,case EN_CHANGE<<16|4 goto g1
,case EN_KILLFOCUS<<16|4 if(GetFocus) goto g1
ret 1
#2
replace 
f.SetDialogFontColor(hDlg 0xFF0000 "3 4")

with
Code:
Copy      Help
DT_SetTextColor(hDlg 0xFF0000 "3 4")
#3
kevin, Thanks for your help!
Is there an easy way to achieve Press key(ctrl|enter or any key) to cancel the countdown?
#4
use DT_SetAccelerators

Code:
Copy      Help
int timeoutS=10
int flags=128

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 128 88 "Dialog" "4"
;3 Static 0x44000002 0x0 40 16 12 12 ""
;4 Edit 0x54030080 0x200 16 32 96 14 ""
;1 Button 0x54030001 0x4 8 64 48 14 "OK"
;2 Button 0x54030000 0x4 72 64 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "4"
str e4

type ___INPBOX flags timeoutS dlgProc
___INPBOX z.flags=flags; z.timeoutS=timeoutS

if(!ShowDialog(dd &sub.DlgProc &controls 0 flags&64 0 0 &z)) ret


#sub DlgProc
function# hDlg message wParam lParam

___INPBOX& z=+DT_GetParam(hDlg); if(!&z) ret
sel message
,case WM_INITDIALOG
,__Font-- f.Create("Microsoft YaHei Mono" 12 0); f.SetDialogFont(hDlg "3 4")
,DT_SetTextColor(hDlg 0xFF0000 "3 4")
,DT_SetAccelerators hDlg "400 CY";;Ctrl+enter
,if z.timeoutS>0
,,hid- id(3 hDlg)
,,SetTimer hDlg 1 1000 0
,case WM_TIMER
,sel wParam
,,case 1
,,z.timeoutS-1
,,if(z.timeoutS>0) _s=z.timeoutS; _s.setwintext(id(3 hDlg))
,,else KillTimer hDlg 1; if(z.flags&128) DT_Ok hDlg 2; else DT_Cancel hDlg
,,ret 1
,case WM_SETCURSOR
,if lParam>>16!WM_MOUSEMOVE
,,;g1
,,if(z.timeoutS>0) KillTimer hDlg 1; z.timeoutS=0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 400 goto g1
,case EN_CHANGE<<16|4 goto g1
,case EN_KILLFOCUS<<16|4 if(GetFocus) goto g1
ret 1
#5
Sorry, my description is wrong
I mean, just press one key, such as CTRL key or the Enter key or any other key  to cancel the countdown


Forum Jump:


Users browsing this thread: 1 Guest(s)