Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reset
#2
To reset controls to default values, can be used DT_SetControls, but it must be slightly modified. If you don't want to wait for next QM version, use its copy DT_SetControls2:

Code:
Copy      Help
;/
function# hDlg [lParam]

;This function must be called from dialog procedure.
;Sets controls data.
;Called by DT_Init when initializing dialog.


;You can also call this function from dialog procedure, when you
;need to set controls again. Then lParam must be omitted or 0.



opt end 1
__DIALOG* d
if(lParam) SetProp(hDlg "dialogdata" lParam); d=+lParam
else d=+GetProp(hDlg "dialogdata"); if(!d) ret

str* p=d.pdata; if(!p) ret
str cls li
int i j k h n stl lh handle

for i 0 1000000
,j=findt(p[0] i " "); if(j<0) break
,if(!isdigit(p[0][j])) end "invalid first string" 5
,j=val((p[0]+j))
,if(j) h=id(j hDlg); if(!h) end "dialog doesn't have control with id %i" 5 j
,k+1
,str& s=p[k]
,if(s.len>s.nc or s.len<0 or (s.lpstr and IsBadWritePtr(s.lpstr 1)) or s.len!=len(s)) end "invalid str array" 5
,if(!s.lpstr and lParam) continue
,
,if(j=0)
,,if(lParam) s.setwintext(hDlg)
,,continue
,
,sel(cls.getwinclass(h) 1)
,,case "Button"
,,stl=GetWinStyle(h)&15
,,if(stl>1 and stl<7 or stl=9)
,,,if(val(s)) CheckDlgButton(hDlg j 1)
,,,else if(!lParam) CheckDlgButton(hDlg j 0)
,,,continue
,,,
,,case "ListBox"
,,stl=GetWinStyle(h)&LBS_MULTIPLESEL
,,TO_CBFill h s iif(stl 2 1)
,,continue
,,
,,case "ComboBox"
,,TO_CBFill h s
,,continue
,,
,,case "Static"
,,if(!lParam) continue
,,sel(GetWinStyle(h)&31)
,,,case SS_ICON
,,,int large=s[0]='&'
,,,handle=GetIcon(s+large large); if(handle=0) continue
,,,SendMessage(h STM_SETICON handle 0)
,,,lh=d.handles._len; d.handles._resize
,,,d.handles[lh].handle=handle; d.handles[lh].flags=1
,,,continue
,,,case SS_BITMAP
,,,handle=LoadImage(0 s.expandpath IMAGE_BITMAP 0 0 LR_LOADFROMFILE); if(handle=0) continue
,,,SendMessage(h STM_SETIMAGE IMAGE_BITMAP handle)
,,,lh=d.handles._len; d.handles._resize
,,,d.handles[lh].handle=handle; d.handles[lh].flags=2
,,,continue
,,,
,,case "RichEdit20A"
,,SendMessage h EM_LIMITTEXT 0x7FFFFFFE 0
,,if(s.beg("&") and RichEditLoad(h s+1)) continue
,,
,s.setwintext(h)

ret 1

After upgrading QM you should stop using DT_SetControls2, and use DT_SetControls, because it may be extended in the future.

Other way - temporarily remove read-only property from System folder (not file), replace DT_SetControls text with this new text, and export/overwrite System folder.
_______________________

Sample dialog dialog_reset:
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4"
str e3 e4
e3="abc"
if(!ShowDialog("dialog_reset" &dialog_reset &controls)) ret

;BEGIN DIALOG
;0 "" 0x10C80A44 0x100 0 0 223 135 "Form"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 12 10 96 14 ""
;4 Edit 0x54030080 0x200 12 32 96 14 ""
;5 Button 0x54032000 0x0 12 52 48 14 "Reset"
;END DIALOG
;DIALOG EDITOR: "" 0x2010800 "*" ""


ret
;messages
sel message
,case WM_INITDIALOG DT_Init(hDlg lParam); ret 1
,case WM_DESTROY DT_DeleteData(hDlg)
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 5
,DT_SetControls2 hDlg
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1

_____________________

I also have to say that dialog variables are not updated whenever something is changed in the dialog. To populate variables without closing the dialog, call DT_GetControls. It is called by DT_Ok, which also closes the dialog.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)