12-03-2007, 10:19 PM
Function ShowDialog2
Function outb
Create the above functions and this macro:
Run the macro. What is in the QM output?
;/
function# [$macro] [dlgproc] [!*controls] [hwndowner] [flags] [style] [notstyle] [param] [x] [y] [$icon] [$menu] ;;flags: 1 nonmodal, 2 macro is DD, 4 set style (default is to add).
;Shows <help "::/user/IDH_DIALOG_EDITOR.html">dialog</help>.
;macro - name of macro containing dialog definition. If flag 2 is set or it is multiline string - dialog definition itself. Default: "" (caller).
;dlgproc - for smart dialogs - address of dialog procedure. Default: 0 (simple dialog).
;controls - address of dialog variables. Default: 0 (don't set/get control values).
;hwndowner - owner window handle. Default: 0.
;flags - see above. Default: 0.
;style - dialog window styles to add or set. Default: 0.
;notstyle - dialog window styles to remove. Default: 0.
;param - some value that dialog procedure can access using DT_GetParam. Default: 0.
;icon - title bar icon. Can be icon file, or icon resource id preceded by : (eg ":133"). Default: "".
;menu - menu. Can be name of item that contains menu definition, or menu definition itself, or menu resource id preceded by : (eg ":1"). Default: "".
#opt nowarnings 1
str txt s
int iid i r de_cb=iif(flags&0x80000000 param 0)
lpstr es=".[][9]First argument of ShowDialog must be name of macro or function that contains dialog definition (text that begins with BEGIN DIALOG)"
;get dialog definition
if(flags&2 or findc(macro 10)>=0) txt=macro
else
,if(len(macro)) iid=qmitem(macro 5); else iid=getopt(itemid 1)
,if(!iid) end "cannot create dialog. Macro not found or is encrypted%s" 0 es
,txt.getmacro(iid)
;convert
i=CompileDialog(txt s de_cb)
if(!i) end "cannot create dialog. Dialog definition not found or is invalid%s" 0 es
;style
int& dst=+(s+12)
if(flags&4) dst=style
;else if(flags&8) dst|style ;;fbc
else if(flags&16) dst~style ;;fbc
else if(flags&32) dst^style ;;fbc
else dst|style
dst~notstyle
if(!hwndowner) dst~WS_CHILD
if(dst&WS_CHILD) flags|1
else
,if(hwndowner) hwndowner=GetAncestor(hwndowner 2)
,if(dst&DS_SETFOREGROUND) AllowActivateWindows
;dialog data
__DIALOG* d._new
d.flags=flags
d.hwndowner=hwndowner
d.pdata=controls
d.param=param
d.x=x
d.y=y
if(dlgproc) d.dlgproc=dlgproc; if(IsBadCodePtr(dlgproc)) end ES_BADARG
if(dst&(WS_VISIBLE|DS_SETFOREGROUND)=0) d.flags2|256
;extra
if(len(icon))
,d.hicon=GetFileIcon(icon 0 0)
,if(!d.hicon) out "Warning: cannot load icon %s" icon
if(len(menu))
,d.hmenu=DT_CreateMenu(menu d.haccel)
,if(!d.hmenu) out "Warning: cannot create or load menu %s" menu
;needs memory allocated by GlobalAlloc
DLGTEMPLATEEX* dt=+GlobalAlloc(0 i)
memcpy(dt s i); s.all
out i
outb dt i 1
out _hinst
out &DefDialogProc
out d
;create dialog window
if(flags&1) ;;nonmodal
,r=CreateDialogIndirectParam(_hinst dt hwndowner &DefDialogProc d)
,if(!r) r=-1
else
,r=DialogBoxIndirectParam(_hinst dt hwndowner &DefDialogProc d)
GlobalFree(dt)
0 ;;process messages, or later something will not work, eg GetKeyState
if(r!=-1) ret r
;ge
end "cannot show dialog"
err+
,if(dt) GlobalFree(dt)
,out "Error (RT) in dialog: %s,[][9]line: %s" _error.description _error.line
Function outb
;/
function !*ptr nBytes [flags] ;;flags: 1 show characters too
out _s.encrypt(8 _s.fromn(ptr nBytes) "" 1)
if(flags&1)
,str s.all(nBytes*3 2 32)
,int i c
,for(i 0 nBytes)
,,c=ptr[i]
,,if(c<32) continue
,,s[i*3+1]=c
,out s
Create the above functions and this macro:
\Dialog_Editor
if(!ShowDialog2("" 0)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2020103 "" "" ""
Run the macro. What is in the QM output?