Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect drop on toolbar
#1
I'm trying to detect when a file is dropped on the toolbar but the following hook doesn't work. Why?
Function tbhooker
Code:
Copy      Help
function# hWnd message wParam lParam

sel message
,case WM_QM_DRAGDROP
,out "dragdropped"
#2
i think this should help you

QM toolbars: how to drag and drop a button


QMDRAGDROPINFO& di=+lParam

under the case WM_QM_DRAGDROP
#3
That doesn't work either. As far as I can tell those posts refer to dragging a button off of the toolbar, I'm interested in detecting when a file is dragged onto the toolbar.
#4
not only off of the toolbar
#5
That thread is hard to follow, lots of different functions. None of them allow you to drag and drop a file onto toolbar AND make a new button AND allow you to detect the drop.

The following functions have these properties:
D&D file onto toolbar: allows but does not notify
D&D button off of the toolbar: allows and notifies
Function TB_DetectDragDropButton
Code:
Copy      Help
;/
function! *phWnd str&buttonText

;Call this function in a toolbar hook function, before sel message.
;It detects when you drag and drop a button somewhere outside the toolbar.
;If you drag and drop a button, it returns 1 and stores button text into buttonText.
;Else it returns 0.

;EXAMPLE
;function# hWnd message wParam lParam
;if(TB_DetectDragDropButton(&hWnd _s))
,;out "dropped %s" _s
;sel message
,;...


int hWnd message wParam lParam i htb
memcpy &hWnd phWnd 16

sel message
,case WM_SETCURSOR
,if(lParam>>16=WM_LBUTTONDOWN and lParam&0xffff=HTCLIENT and !GetMod and GetWinId(wParam)=9999)
,,htb=id(9999 hWnd)
,,POINT p; xm p htb 1
,,i=SendMessage(htb TB_HITTEST 0 &p) ;;1-based button index
,,if(i>0)
,,,SetProp hWnd "tb_db_button" i
,,,SetTimer hWnd 28561 10 0
,
,case WM_TIMER
,sel wParam
,,case 28561
,,htb=id(9999 hWnd)
,,if(htb=GetCapture)
,,,ifk(Z) ReleaseCapture; ret
,,,SetCursor iif(win(mouse)=hWnd LoadCursor(0 +IDC_ARROW) LoadCursor(GetModuleHandle("ole32") +4))
,,,ret
,,KillTimer hWnd wParam
,,if(win(mouse)=hWnd) ret
,,ifk((1)) ret
,,
,,i=GetProp(hWnd "tb_db_button")
,,Acc a=acc("" "TOOLBAR" htb "" "" 0x1000)
,,a.elem=i+1; buttonText=a.Name; err ret
,,ret 1

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

if(TB_DetectDragDropButton(&hWnd _s))
,out "dropped %s" _s

sel message
,case WM_INITDIALOG
,
,case WM_DESTROY
,

Toolbar
Code:
Copy      Help
;/hook tb_hook_drag_button
a :out "a"
b :out "b"
-
;h :out "h"

c :out "c"
d :out "d"
The following functions have these properties:
D&D file onto toolbar: does not make new button, only notifies if file is dropped on a button
D&D button off of the toolbar: does not allow or notify
Function TB_GetDragDropButton
Code:
Copy      Help
;/
function# hWnd [str&tbLabel] [str&tbLine]

;Call this function on WM_QM_DRAGDROP in toolbar hook function.
;Gets some info about the button on which dropped.
;Returns toolbar line index. Returns 0 if dropped not on a button.

;hWnd - hWnd.
;tbLabel - receives button text. Can be 0.
;tbLine - receives button line text. Can be 0.


;button index
int htb=id(9999 hWnd)
POINT p; xm p htb 1
int b=SendMessage(htb TB_HITTEST 0 &p)
if(b<1) ret

;label
if(&tbLabel)
,tbLabel.all
,Acc a=acc("" "TOOLBAR" htb "" "" 0x1000)
,a.elem=b+1; tbLabel=a.Name; err

;line
if(&tbLine)
,tbLine.all
,str s.getwintext(hWnd)
,s.getmacro(s); err goto gr
,tbLine.getl(s b)

;gr
ret b

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

sel message
,case WM_INITDIALOG
,int htb=wParam
,QmRegisterDropTarget(htb hWnd 16)
,
,case WM_DESTROY
,case WM_QM_DRAGDROP
,;get button
,str buttonText
,if(!TB_GetDragDropButton(hWnd buttonText)) ret
,out "dropped on '%s':" buttonText
,
,;get files
,QMDRAGDROPINFO& di=+lParam
,str s
,foreach(s di.files) out s

Toolbar
Code:
Copy      Help
;/hook tb_drag_drop_hook
qm.exe :run "$qm$\qm.exe"
My QM :run "$my qm$"
Winamp :run "$program files$\Winamp\winamp.exe"

So what allows you to add a new button by dragging and dropping a file (like normal toolbars) AND also allows you to detect when this happens.
#6
QmRegisterDropTarget disables normal drop behaviour for the toolbar. If you use it, on WM_QM_DRAGDROP you can insert buttons using str.setmacro.

Function TB_DropInsertButton
Code:
Copy      Help
;/tb_drag_drop3
function hWnd lParam

;Call this function on WM_QM_DRAGDROP in toolbar hook function.
;Inserts button(s).

;hWnd, lParam - hWnd, lParam.

;EXAMPLE
;sel message
, case WM_INITDIALOG
, int htb=wParam
, QmRegisterDropTarget(htb hWnd 16)
,
, case WM_DESTROY
, case WM_QM_DRAGDROP
, TB_DropInsertButton hWnd lParam


QMDRAGDROPINFO& di=+lParam
str s1 s2 sn st si; int i b

b=TB_GetDragDropButton(hWnd)

foreach(s1 di.files)
,if(!s1.beg("::")) s2.getfilename(s1 1)
,if(!inp(s2 "Button label." "" s2)) ret
,s1.expandpath(s1 2)
,s1.escape(1); s2.escape(1)
,si.formata("%s :run ''%s''[]" s2 s1)

sn.getwintext(hWnd)
st.getmacro(sn)
if(b) i=findl(st b); else i=-1
if(i<0) i=st.len
st.insert(si i)
st.setmacro(sn)

err+ out _error.description

Or don't use QmRegisterDropTarget, and detect when toolbar text changed, for example get its text every 1 s...


Forum Jump:


Users browsing this thread: 2 Guest(s)