Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does a button implement two functions
#1
Hello everyone, I created a dialog box without a title bar. I want to use the button in the upper right corner of the dialog to implement two functions. Any comments and suggestions are welcome. Thanks in advance.  Smile

1. When I click the button, I can close the dialog

2. When I right-drag the button(or left-drag the button ), I can drag the entire dialog

Macro Macro6
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90080AC8 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
put together from this topic
http://www.quickmacros.com/forum/showthr...12#pid7112

left click button closes dialog and left click and drag  button moves dialog



Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90000A40 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,sub.DialogDragSubclassControl id(3 hDlg) ;;subclass button 3    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Close
,DT_Ok hDlg
ret 1

#sub DialogDragSubclassControl
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" SubclassWindow(hwndctrl &sub.DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers
#sub DragDialog
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
#sub DialogDragSubclassProc
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(sub.DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret

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

if(message=WM_NCDESTROY)
,RemoveProp(hWnd "qm_wndproc")
,RemoveProp(hWnd "qm_modifiers")

ret r
#3
thank you very much  Heart  There are many lines of code, how to achieve more simple? Can I save a function call?
#4
this is not a simple thing to do.Many many functions involved to do this its not really that many lines of code

Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90000A40 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close" "left click to close left click+drag to move"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,sub.DialogDragSubclassControl id(3 hDlg) ;;subclass button 3    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Close
,DT_Ok hDlg
ret 1

#sub DialogDragSubclassControl
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" SubclassWindow(hwndctrl &sub.DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers
#sub DragDialog
function# hDlg message [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win
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
#sub DialogDragSubclassProc
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(sub.DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret
int wndproc=GetProp(hWnd "qm_wndproc"); if(!wndproc) ret
int r=CallWindowProc(wndproc hWnd message wParam lParam)
if(message=WM_NCDESTROY)
,RemoveProp(hWnd "qm_wndproc")
,RemoveProp(hWnd "qm_modifiers")
ret r
its either this way using sub functions or can use user defined functions but code will not get smaller

example using external functions
only code which will be smaller is main dialog
Function DragDialogButton
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90000A40 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close" "left click to close left click+drag to move"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DialogDragSubclassControl id(3 hDlg) ;;subclass button 3    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Close
,DT_Ok hDlg
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" SubclassWindow(hwndctrl &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_renamed(hWnd message GetProp(hWnd "qm_modifiers"))) ret

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

if(message=WM_NCDESTROY)
,RemoveProp(hWnd "qm_wndproc")
,RemoveProp(hWnd "qm_modifiers")

ret r
Function DragDialog_renamed
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.


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

sel message
,case WM_LBUTTONDOWN
,t_indrag=0
,if(GetMod!=modifiers) ret
,if(IsChildWindow(hDlg)) ;;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
#5
I want to right-click on the button to maximize the window, how to add code?   A button for closing, dragging, and maximizing functions  Wink
#6
you have done this before only difference is using right click just need to add case statement in
#sub DialogDragSubclassProc since button control is subclassed

Function DialogButtonDrag 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90000A40 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close" "left click to close or left click+drag to move or right click to maximize/restore"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
int- Fullscreen dialoghandle
sel message
,case WM_INITDIALOG
,Fullscreen =0
,dialoghandle=hDlg
,sub.DialogDragSubclassControl id(3 hDlg) ;;subclass button 3    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Close
,DT_Ok hDlg
ret 1

#sub DialogDragSubclassControl
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" SubclassWindow(hwndctrl &sub.DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers
#sub DragDialog
function# hDlg message [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win
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
#sub DialogDragSubclassProc
function# hWnd message wParam lParam
;Used internally in case a control is subclassed. Don't call explicitly.
sel message
,case [WM_RBUTTONDOWN,WM_RBUTTONUP]
,int- Fullscreen dialoghandle
,if Fullscreen =0
,,max dialoghandle
,,Fullscreen=1
,else
,,res dialoghandle
,,Fullscreen=0
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE]
,if(sub.DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret
int wndproc=GetProp(hWnd "qm_wndproc"); if(!wndproc) ret
int r=CallWindowProc(wndproc hWnd message wParam lParam)
if(message=WM_NCDESTROY)
,RemoveProp(hWnd "qm_wndproc")
,RemoveProp(hWnd "qm_modifiers")
ret r
#7
Great, very much admired your programming skills, almost everything  Smile

I have encountered a problem in use, web pages can not be refreshed in time  Huh

Macro Macro2
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90000A40 0x0 0 0 398 210 "Dialog"
;3 Button 0x54032000 0x0 368 0 30 14 "Close" "left click to close or left click+drag to move or right click to maximize/restore"
;4 ActiveX 0x54030000 0x0 0 0 400 212 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040700 "*" "" "" ""
str controls = "4"
str ax4SHD
ax4SHD="http://www.quickmacros.com/forum/index.php"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
int- Fullscreen dialoghandle
sel message
,case WM_INITDIALOG
,DT_SetAutoSizeControls hDlg "4s 3mh"
,Fullscreen =0
,dialoghandle=hDlg
,sub.DialogDragSubclassControl id(3 hDlg) ;;subclass button 3
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 3 ;;Close
,DT_Ok hDlg
ret 1

#sub DialogDragSubclassControl
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" SubclassWindow(hwndctrl &sub.DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers
#sub DragDialog
function# hDlg message [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win
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
#sub DialogDragSubclassProc
function# hWnd message wParam lParam
;Used internally in case a control is subclassed. Don't call explicitly.
sel message
,case [WM_RBUTTONDOWN,WM_RBUTTONUP]
,int- Fullscreen dialoghandle
,if Fullscreen =0
,,max dialoghandle
,,Fullscreen=1
,else
,,res dialoghandle
,,Fullscreen=0
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE]
,if(sub.DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret
int wndproc=GetProp(hWnd "qm_wndproc"); if(!wndproc) ret
int r=CallWindowProc(wndproc hWnd message wParam lParam)
if(message=WM_NCDESTROY)
,RemoveProp(hWnd "qm_wndproc")
,RemoveProp(hWnd "qm_modifiers")
ret r


Attached Files Image(s)
   
#8
not having that issue add 
Code:
Copy      Help
WebBrowserControlDisableIE7Emulation
 and see if it corrects the issue
#9
http://www.quickmacros.com/forum/showthr...p?tid=6458

@kevin 
Can you help me solve this problem? This question is asked a lot of programming friends, can not solve, thank you very much Smile

Using the conventional method: (Hide the dialog title bar and then maximize) will cause many flash hot keys to expire  Huh

For example: press ctrl+K : autoplay

Using F11 All hot keys work fine, but every time I need to click the allow button, and when I accidentally move the mouse pointer over the desktop, an annoying hint appears, affecting reading. Angel


Forum Jump:


Users browsing this thread: 1 Guest(s)