Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM toolbars: how to drag and drop a button
#1
i want to build a global toolbar with all my credentials.
i want to drop my password button onto firefox password field in order to prevent a lot of manual actions.

what is the status on that functionality?
pi
#2
drag and drop from a qm toolbar to another window?
#3
YES!!!
pi
#4
Maybe easier would be to click button, then let the macro wait for another click... I often do it. For example, this macro deletes a music file in winamp library and scrolls to the next item.

Macro
Code:
Copy      Help
OnScreenDisplay "click the item in 10 seconds"
wait 10 ML; err ret
OsdHide
int hlv=child(mouse)
Acc a=acc("" "LIST" hlv "" "" 0x1000); err ret
ARRAY(Acc) aa
a.Selection(aa)
if(!aa.len) ret
a=aa[0]
a.Mouse(2)
wait 5 WV "+#32768"
key rrrRp
0.5
a.Select(2) ;;now a is first element after deleted element
SendMessage hlv LVM_ENSUREVISIBLE a.elem 0

Toolbar
Code:
Copy      Help
Delete... :mac "winamp delete" * close.ico
#5
no, i really need the moment where i drop my related button.

it would be cool to know how to react when left mouse has been released.
pi
#6
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"
#7
woohoo!

and how do i perform my own drop on qm button script?
pi
#8
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"

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

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
#9
wow!
now it needs some fine tuning.
thank you very much!


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

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

sel message
,case WM_INITDIALOG
,int htb=wParam
,QmRegisterDropTarget(htb hWnd 16)
,
,case WM_DESTROY
,case WM_QM_DRAGDROP
,,;get button
,,htb=id(9999 hWnd)
,,POINT p; xm p htb 1
,,int b=SendMessage(htb TB_HITTEST 0 &p) ;;toolbar line
,,if(b<1) ret
,,Acc a=acc("" "TOOLBAR" htb "" "" 0x1000)
,,a.elem=b+1; str buttonText=a.Name; err ret
,,out "dropped on '%s':" buttonText
,,
,,;get files
,,QMDRAGDROPINFO& di=+lParam
,,str s
,,foreach(s di.files) out s
pi
#10
how do i include my standard code for toolbars?
currently i have to paste my 'move toolbar' code into each hook function.
pi
#11
Moved something to TB_GetDragDropButton.
#12
Function tb_drag_drop_hook
Code:
Copy      Help
;/Toolbar qm
function# hWnd message wParam lParam
int+ g_tb_move_htb g_tb_move_hfore
POINT+ g_tb_move_pos
POINT p

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

sel message
,case WM_INITDIALOG
,int htb=wParam
,QmRegisterDropTarget(htb hWnd 16)
,    case WM_SETCURSOR
,,if(lParam=WM_LBUTTONDOWN<<16|HTCLIENT)
,,,if(wParam=hWnd)
,,,else if(GetDlgCtrlID(wParam)=9999)
,,,,GetCursorPos &p; ScreenToClient wParam &p
,,,,if(SendMessage(wParam TB_HITTEST 0 &p)>=0) ret ;;button
,,,else ret
,,,
,,,GetCursorPos &g_tb_move_pos
,,,g_tb_move_htb=hWnd
,,,g_tb_move_hfore=win
,,,act hWnd ;;for SetCapture
,,,SetCapture hWnd
,,
,,case [WM_LBUTTONUP,WM_CANCELMODE]
,,g_tb_move_htb=0
,,SetCapture 0
,,act g_tb_move_hfore; err
,,
,,case WM_MOUSEMOVE
,,if(g_tb_move_htb=hWnd)
,,,RECT r; GetWindowRect hWnd &r
,,,GetCursorPos &p
,,,mov r.left+p.x-g_tb_move_pos.x r.top+p.y-g_tb_move_pos.y hWnd
,,,g_tb_move_pos=p
,
,case WM_DESTROY
,case WM_QM_DRAGDROP
,,;get button
,,htb=id(9999 hWnd)
,,;;POINT p;
,,xm p htb 1
,,int b=SendMessage(htb TB_HITTEST 0 &p) ;;toolbar line
,,if(b<1) ret
,,Acc a=acc("" "TOOLBAR" htb "" "" 0x1000)
,,a.elem=b+1; str buttonText=a.Name; err ret
,,out "dropped on '%s':" buttonText
,,
,,;get files
,,QMDRAGDROPINFO& di=+lParam
,,str s
,,foreach(s di.files) out s
pi
#13
another wow!


Attached Files Image(s)
   
pi
#14
how do i make a button accept a text selection being dropped from another application?
pi
#15
Function dlg_ole_drop_text
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dlg_ole_drop_text" &dlg_ole_drop_text 0 _hwndqm 0 0 0 0 1 -1)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;END DIALOG
;DIALOG EDITOR: "" 0x2020006 "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,QmRegisterDropTarget(hDlg hDlg 0)
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s)) ret
,,out s
,,ret DT_Ret(hDlg 1)
,
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Member function QMDRAGDROPINFO.GetText
Code:
Copy      Help
function! str&s [flags] ;;flags: 1 drag source must not delete text

;Extracts dropped text.
;Returns 1 if successful, 0 if failed.


s.fix(0)

int k=GetMod
sel(k) case [0,2] case else this.effect=DROPEFFECT_NONE; ret
if(flags&1) k=2

int i
for(i 0 this.formats.len) if(this.formats[i].cfFormat=CF_UNICODETEXT) break
if(i=this.formats.len) ret

STGMEDIUM sm
this.dataObj.GetData(&this.formats[i] &sm); err ret

int gs=GlobalSize(sm.hGlobal)-2; if(gs<=0) ret
s.all(gs 2)
byte* m=GlobalLock(sm.hGlobal); if(!m) ret
memcpy s m s.len
GlobalUnlock sm.hGlobal
ReleaseStgMedium(&sm)
s.ansi

sel k
,case 0 this.effect&DROPEFFECT_MOVE
,case 2 this.effect&DROPEFFECT_COPY

ret 1
#16
hello gintaras, it has been a while since i last edited the related code for that.
i now want to use a toolbar like this for overlaying a text field, which does not allow drag text.
that all is working, but since i am so rusty with qm code, can you please give me a hint or a topic about how to extract urls from dropped text?

thank you!
pi
#17
Macro Macro1519
Code:
Copy      Help
str text="..."
str url
if(findrx(text "regular expression for url" 0 0 url)<0) ret
out url
#18
ok. i think my regex is working, but it only returns the first found url.
sorry again, but i am really rusty :oops:

i know i need to use foreach or for to parse all lines. please help.

,QMDRAGDROPINFO& di=+lParam
,,sel wParam
,,,case 3 ;;drop
,,,,str s url
,,,,if(!di.GetText(s)) ret
,,,,if(findrx(s "http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?" 0 0 url)<0) ret
,,,,out url
pi
#19
Macro Macro1519
Code:
Copy      Help
str s="http://a.b.c/x?y=z&b=5 http://e.f.g"
ARRAY(str) a
if(!findrx(s "http(s)?://([\w\-]+\.)?[\w\-]+\.\w+/?\S*" 0 4 a)) ret
int i
for i 0 a.len
,out a[0 i]

the regular expression is not perfect
#20
thanks, it works like it is supposed to do. i don't know if it makes sense to post my code, since the purpose is relatively special.

but i have a further question, can qm toolbars and related trigger functions be used in exe?

and what do you mean by 'the regular expression is not perfect''?
pi
#21
Toolbars no. Drag/drop functions yes, for example with dialogs.

not perfect is not perfect
#22
when i remember correctly, then its possible to mimic toolbars with dialogs, or?
pi
#23
No, would need to create windows. Difficult.
#24
what i need it to have a transparent borderless dialog over a text field, where i can use drop code to pass the dropped result to.
pi
#25
test
Code:
Copy      Help
;----
int w=win("Untitled - Notepad" "Notepad")
int c=id(15 w)

AddTextDrop c

Function AddTextDrop
Code:
Copy      Help
;/
function# hwndControl [flags] ;;flags: 1 nonmodal

;Creates a partially transparent window over a control.
;When you drop text on it, it transfers the text to the control.
;Not fully working. Just an example of how you can do it. Need much more code in dlg_TextDrop.

;hwndControl - control handle.
;flags:
;;;0 - wait until the control is destroyed (its window closed). Returns 1.
;;;1 - return immediately. Returns handle of the transparent window. Then the thread must not exit; it must process messages.


if(!IsWindow(hwndControl)) ret
int hDlg=ShowDialog("dlg_TextDrop" &dlg_TextDrop 0 hwndControl 1 0 0 hwndControl)

if(flags&1) ret hDlg
opt waitmsg 1
wait 0 -WC hDlg
ret 1

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

;BEGIN DIALOG
;0 "" 0x80000848 0x8000080 0 0 227 150 "TextDrop"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "AddTextDrop" "" ""

ret
;messages
;OutWinMsg message wParam lParam
int hwndControl=DT_GetParam(hDlg)
sel message
,case WM_INITDIALOG
,RECT r; GetWindowRect hwndControl &r
,SetWindowPos hDlg 0 r.left r.top r.right-r.left r.bottom-r.top SWP_NOZORDER|SWP_NOACTIVATE
,Transparent hDlg 64
,SetWindowPos hDlg 0 0 0 0 0 SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE
,SetTimer hDlg 1 1000 0
,QmRegisterDropTarget(hDlg hDlg 0)
,
,case WM_QM_DRAGDROP
,QMDRAGDROPINFO& di=+lParam
,sel wParam
,,case 3 ;;drop
,,str s
,,if(!di.GetText(s)) ret
,,s.setwintext(hwndControl)
,,ret DT_Ret(hDlg 1)
,
,case WM_TIMER
,sel wParam
,,case 1
,,if(!IsWindow(hwndControl)) DestroyWindow hDlg; ret
,,;also should move dialog if hwndControl moved; hide if hidden or minimized, etc
ret

;Should also somehow relay mouse and some other messages to hwndControl,
;because now it is covered by this dialog and therefore is like disabled.
;Cannot make this dialog completely transparent, because dag/drop will not work.
;Easier would be to move this dialog beside the control, not to cover the control.
;Need much more code to make this work well in all cases.
#26
In "dlg_ole_drop_text" from March 27,2009, can you add a rich text control or a web browser control and still maintain the same drag / drop functionality for the main window? ie: you could display text in the control and drag portions of that text from that control and drop it on the main host window.

Thanks,

Brad
#27
Can add a rich text control and drag text from it to the host dialog.
Same with web browser control, but in latest IE versions drag/drop is disabled.
#28
Thank you,

I have limited programming knowledge.

Usually I add controls in the basic way:
str controls = "3"
str rea3 = "$documents$\testFolder\testFile.rtf"
if(!ShowDialog("Dialog19" &Dialog19 &controls)) ret
---------------
Could you please show how to add a rich text control to "dlg_ole_drop_text" ?
I don't understand how to work with [[ 0 _hwndqm 0 0 0 0 1 -1 ]] part:
if(!ShowDialog("dlg_ole_drop_text" &dlg_ole_drop_text 0 _hwndqm 0 0 0 0 1 -1)) ret

Thanks,

Brad
#29
Also, how can I set the size of the displayed window with ShowText?
ShowText "Document" "$desktop$\document.rtf" 0 4
#30
1. Open dlg_ole_drop_text.
2. Right click selection bar in first line. It will insert 1 space.
3. Click Run button. It will show dialog editor.
4. Click Options button, click Together... button, OK.
5. Add rich edit control.
6. Apply. It will update dialog definition, add/update dialog variables and ShowDialog line.


Forum Jump:


Users browsing this thread: 1 Guest(s)