08-08-2008, 10:42 AM
Function Dialog69
Function MoveSizeControlLoop
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
str controls = "3"
str e3
if(!ShowDialog("Dialog69" &Dialog69 &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54231044 0x200 4 30 96 48 ""
;4 Static 0x54000000 0x0 4 4 76 22 "Move with Shift[]Resize with Ctrl"
;END DIALOG
;DIALOG EDITOR: "" 0x2030001 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,
,case WM_SETCURSOR ;;use it to detect left button down. Don't use WM_LBUTTONDOWN because it is sent to the control, not to the dialog.
,sel lParam>>16 ;;mouse message
,,case WM_LBUTTONDOWN ;;left down
,,sel GetDlgCtrlID(wParam) ;;control id
,,,case 3 ;;edit control
,,,int m=GetMod
,,,sel m
,,,,case [1,2] ;;Shift or Ctrl
,,,,PostMessage hDlg WM_APP wParam m ;;don't use loop on WM_SETCURSOR. Do it async.
,,,,ret DT_Ret(hDlg 1)
,
,case WM_APP
,MoveSizeControlLoop hDlg wParam lParam 1
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Function MoveSizeControlLoop
;/
function hDlg hctrl action mouseButton ;;action: 1 move, 2 resize. mouseButton: 1 left, 2 right
MSG m; int mb;
RECT r; GetWindowRect hctrl &r
sel action
,case 1
,POINT po; xm po; po.x-r.left; po.y-r.top ;;get mouse offset in control
,case 2
,mou r.right r.bottom ;;move mouse to right-bottom
int hcur=LoadCursor(0 +IDC_CROSS)
SetCapture(hDlg);
rep
,if(GetCapture()!=hDlg || GetMessage(&m, 0, 0, 0)<=0) break
,if(m.message==WM_KEYDOWN && m.wParam==VK_ESCAPE) ReleaseCapture(); break
,mb=0;
,sel(m.message)
,,case WM_MOUSEMOVE:
,,POINT p; xm p
,,sel action
,,,case 1
,,,ScreenToClient hDlg &p
,,,mov p.x-po.x p.y-po.y hctrl
,,,case 2
,,,siz p.x-r.left p.y-r.top hctrl
,,SetCursor(hcur);
,,continue;
,,case WM_LBUTTONUP: mb=MK_LBUTTON
,,case WM_RBUTTONUP: mb=MK_RBUTTON
,if(mb==mouseButton)
,,ReleaseCapture();
,DispatchMessage(&m);