Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
resize dialog with mouse; autosize controls
#2
To make dialog resizable, in dialog editor add WS_THICKFRAME style. Also optionally WS_MINIMIZEBOX and WS_MAXIMIZEBOX.

Use this function to autosize dialog controls.

Function DT_AutoSizeControls
Code:
Copy      Help
;/
function hDlg message $controls

;Moves or resizes dialog controls when you resize the dialog.
;Call this function from dialog function, before sel message.

;hDlg, message - hDlg, message.
;controls - space-separated list of controls.
;;;Syntax for a control: IdActionDirection
;;;;;Id - control id.
;;;;;Action - m (move) or s (resize).
;;;;;Direction - h (horizontally) or v (vertically) or none (horizontally and vertically).

;EXAMPLE
;;...
;;messages
;DT_AutoSizeControls hDlg message "1m 2m 3sh 4mv 5s"
;sel message
,;case WM_INITDIALOG
,;;...


type ASC_CONTROL hwnd !action !direction horz vert
ASC_CONTROL* p
int i j k x y
RECT r rc

sel message
,case WM_INITDIALOG
,GetClientRect hDlg &rc
,
,ARRAY(lpstr) a
,tok controls a
,p._new(a.len)
,SetProp hDlg "asc_controls" p
,
,for i 0 a.len
,,ASC_CONTROL& c=p[i]
,,lpstr s=a[i] ;;out s
,,j=val(s 0 k); s+k
,,c.hwnd=id(j hDlg); if(!c.hwnd) out "Warning: control %i not found." j; continue
,,c.action=s[0]; c.direction=s[1]
,,
,,GetWindowRect c.hwnd &r; MapWindowPoints 0 hDlg +&r 2
,,sel c.action
,,,case 'm' c.horz=rc.right-r.left; c.vert=rc.bottom-r.top
,,,case 's' c.horz=rc.right-r.right; c.vert=rc.bottom-r.bottom
,
,case WM_SIZE
,GetClientRect hDlg &rc
,
,p=+GetProp(hDlg "asc_controls")
,
,for i 0 p._len
,,&c=p[i]
,,j=0; sel(c.direction) case 'h' j|2; case 'v' j|1
,,sel c.action
,,,case 'm'
,,,x=rc.right-c.horz; y=rc.bottom-c.vert
,,,mov x y c.hwnd j; err
,,,
,,,case 's'
,,,GetWindowRect c.hwnd &r; MapWindowPoints 0 hDlg +&r 2
,,,x=rc.right-r.left-c.horz; y=rc.bottom-r.top-c.vert
,,,siz x y c.hwnd j; err
,
,case WM_DESTROY
,p=+RemoveProp(hDlg "asc_controls")
,p._delete

example

Function dlg_autosize_control
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3 4 5"
str e3 c4Che e5
if(!ShowDialog("dlg_autosize_control" &dlg_autosize_control &controls)) ret

;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 219 132 "Dialog"
;1 Button 0x54030001 0x4 118 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 46 6 170 14 ""
;4 Button 0x54012003 0x0 4 102 48 12 "Check"
;5 Edit 0x54231044 0x200 120 56 96 48 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030208 "*" "" ""

ret
;messages
DT_AutoSizeControls hDlg message "1m 2m 3sh 4mv 5s"
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)