09-10-2015, 02:07 AM
To expand on my questions from prior post, let me give a couple examples for comments:
hook method:
Macro Startup
Function NotePadDlg
Function exe_window_trigger
Timer (rep) loop method:
Function NotePadDlg2
The SetWinEventHook seems much quicker - no wobble compared to Timer Loop even with short period. I imagine it is less of drain on CPU usage.
I kind of cobbled the hook method from other posts. Is there a better way of doing this?
Stuart
hook method:
Macro Startup
run "$system$\notepad.exe" "" "" "" 0x800 win("Notepad" "Notepad")
ifi-( win("ToolbarDlg" "#32770"))
,mac "NotePadDlg"
mac "exe_window_trigger"
Function NotePadDlg
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
int- NotePadHwnd=win("Notepad" "Notepad")
str controls = "3"
str e3
if(!ShowDialog("NotePadDlg" &NotePadDlg &controls NotePadHwnd)) ret
;BEGIN DIALOG
;0 "" 0x90000A48 0x0 0 0 357 15 "ToolbarDlg"
;4 Button 0x54032000 0x0 260 0 48 14 "Button"
;5 Button 0x54032000 0x0 308 0 48 14 "Button"
;3 Edit 0x54030080 0x200 0 0 260 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
;messages
DT_AutoSizeControls hDlg message "3sh 4mh 5mh "
sel message
,case WM_INITDIALOG
,int x y cx cy
,GetWinXY(NotePadHwnd x y cx cy)
,mov+ x+50 y+5 cx-225 0 hDlg 0x200
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
Function exe_window_trigger
function hHook event hwnd idObject idChild dwEventThread dwmsEventTime
def EVENT_OBJECT_LOCATIONCHANGE 0x800B
if getopt(nargs)!=7
,int hh=SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE EVENT_OBJECT_LOCATIONCHANGE 0 &exe_window_trigger 0 0 WINEVENT_OUTOFCONTEXT)
,if(!hh) end F"{ERR_FAILED}. {_s.dllerror}"
,opt waitmsg 1
,wait -1
,UnhookWinEvent hh
,ret
;This code runs whenever a window has locationchange.
int NotePadHwnd=win("Notepad" "Notepad")
int ToolbarDlgHwnd = win("ToolbarDlg" "#32770")
if (hwnd == NotePadHwnd)
,out "App Window has moved"
,;outw hwnd
,ifi(NotePadHwnd)
,,int x y cx cy
,,GetWinXY(NotePadHwnd x y cx cy)
,,mov+ x+50 y+5 cx-225 0 ToolbarDlgHwnd 0x200
,else
,,ifi(ToolbarDlgHwnd)
,,,clo ToolbarDlgHwnd
Timer (rep) loop method:
Function NotePadDlg2
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
run "$system$\notepad.exe" "" "" "" 0x800 win("Notepad" "Notepad")
int- NotePadHwnd=win("Notepad" "Notepad")
str controls = "3"
str e3
if(!ShowDialog("NotePadDlg2" &NotePadDlg2 &controls NotePadHwnd)) ret
;BEGIN DIALOG
;0 "" 0x90000A48 0x0 0 0 357 15 "ToolbarDlg"
;4 Button 0x54032000 0x0 260 0 48 14 "Button"
;5 Button 0x54032000 0x0 308 0 48 14 "Button"
;3 Edit 0x54030080 0x200 0 0 260 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""
ret
;messages
DT_AutoSizeControls hDlg message "3sh 4mh 5mh "
sel message
,case WM_INITDIALOG
,RECT- r r_prev
,SetTimer hDlg 1 10 0
,case WM_TIMER
,,int x y cx cy
,,ifi(NotePadHwnd)
,,,GetWindowRect NotePadHwnd &r
,,,if(memcmp(&r &r_prev sizeof(RECT)))
,,,,;MoveWindow hDlg r.left+50 r.top+5 r.right-r.left-100 0 1
,,,,mov+ r.left+50 r.top+5 r.right-r.left-225 0 hDlg 0x200
,,,
,,,;GetWinXY(NotePadHwnd x y cx cy)
,,,;mov+ x+50 y+5 cx-225 0 hDlg 0x200
,,else
,,,clo hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
The SetWinEventHook seems much quicker - no wobble compared to Timer Loop even with short period. I imagine it is less of drain on CPU usage.
I kind of cobbled the hook method from other posts. Is there a better way of doing this?
Stuart