Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Captionless, movable smart dialog?
#7
FUNCTIONS

Function DialogDrag
Code:
Copy      Help
;/
function# hDlg message [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win

;Moves the dialog when the user presses left mouse button on the client area and drags.
;Returns 1 if suscessful, 0 if not (then the message should be passed to the default window procedure).
;The dialog must be a smart dialog, ie with dialog procedure.
;Call this function from the dialog procedure as shown below:


,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message

;To enable moving the dialog by dragging a control, call DialogDragSubclassControl on WM_INITDIALOG.
;If the control has scroll bars, use Ctrl or other modifier key to scroll.



dll user32 #DragDetect hwnd POINT'pt

POINT-- pp_drag
POINT p
RECT r
int-- t_indrag

sel message
,case WM_LBUTTONDOWN
,t_indrag=0
,if(GetMod!=modifiers) ret
,if(GetWinStyle(hDlg)&WS_CHILD) ;;need to detect drag, or the control will not respond to clicks
,,xm p
,,if(!DragDetect(hDlg p))
,,,ScreenToClient hDlg &p
,,,PostMessage hDlg WM_LBUTTONUP 0 p.y<<16|p.x
,,,ret
,xm pp_drag
,SetCapture hDlg
,t_indrag=1
,
,case [WM_LBUTTONUP,WM_CANCELMODE]
,if(!t_indrag or GetCapture!=hDlg) ret
,ReleaseCapture
,t_indrag=0
,
,case WM_MOUSEMOVE
,if(!t_indrag or GetCapture!=hDlg) ret
,hDlg=GetAncestor(hDlg 2) ;;in case hDlg is a subclassed control
,GetWindowRect hDlg &r
,xm p
,mov r.left+p.x-pp_drag.x r.top+p.y-pp_drag.y hDlg
,pp_drag=p

ret 1

Function DialogDragSubclassControl
Code:
Copy      Help
;/
function hwndctrl [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win

;Use this function to subclass a control to enable dialog moving.
;Call it eg under WM_INITDIALOG.



SetProp hwndctrl "qm_wndproc" SetWindowLong(hwndctrl GWL_WNDPROC &DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers

Function DialogDragSubclassProc
Code:
Copy      Help
;/
function# hWnd message wParam lParam

;Used internally in case a control is subclassed. Don't call explicitly.


sel message
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE]
,if(DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret

int wndproc=GetProp(hWnd "qm_wndproc"); if(!wndproc) end
ret CallWindowProc(wndproc hWnd message wParam lParam)

EXAMPLES

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

if(!ShowDialog("DialogDragExample" &DialogDragExample)) 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 0x54030080 0x200 6 6 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message
ret
;messages2
sel wParam
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9

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

if(!ShowDialog("DialogDragExample2" &DialogDragExample2)) 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 Button 0x54032000 0x0 8 10 54 42 "Drag Me"
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,DialogDragSubclassControl id(3 hDlg) ;;subclass button 3
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message ;;this also can be used
ret
;messages2
sel wParam
,case 3 out "clicked"
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9

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

str controls = "3"
str ax3SHD
ax3SHD="http://www.google.com"
if(!ShowDialog("DialogDragExample3" &DialogDragExample3 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90400A44 0x180 0 0 223 147 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 224 148 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,;subclass web browser
,int hctrl=child("" "Internet Explorer_Server" id(3 hDlg)); if(!hctrl) out "Warning: Web browser control not initialized. Assign an url or ''about:blank'' to the control variable before ShowDialog."; ret
,DialogDragSubclassControl hctrl
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message ;;this also can be used
ret
;messages2
sel wParam
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)