Jump to content
Tuts 4 You
Sign in to follow this  
LCF-AT

How to drag links from browser to app?

Recommended Posts

LCF-AT

Hi guys,

I have a new question I am trying to find a solution.I would like to drag a link from browser directly into my app to get the full link address without using any copy / paste functions manually via mouse.Now I see its not working and I can only just drag files from Windows / Explorer etc into my app window.So how can I enable the drag operations also from any browser to outside like into my app window etc?

greetz

Share this post


Link to post
LCF-AT

Hi kao,

thanks for this infos so far.I tried to test the example app "droptarget.exe" to check whether it gets something if I drag something into but it dosent get something if I drag anything into this window of this example app.Or how should this example app work?I dont chekc this yet how to make it work etc.Could you maybe tell some more about it?

greetz

Share this post


Link to post
kao

Sample app does work for me in 64bit Win7 on both Chrome and IE, otherwise I wouldn't suggest it. :) 

From Chrome you can drag/drop both address from address bar and hyperlinks from any webpage. From IE8 you can drag/drop address from address bar.
I don't use Firefox or Brave or Vivaldi or whatever other weird browsers, so I can't test those.

 

Edited by kao (see edit history)
  • Like 1

Share this post


Link to post
LCF-AT

Hi kao,

thanks for this another info.Ok,I did some test with diffrent browsers and see also some diffrents.I am using x86 system.

1.) Using Chrome / Brave browser = Does work to drag links into this example app :)

2.) Using Chrome / Brave browser running in Sandboxie = Dosent work :(

3.) Using Firefox running in Sandboxie or also not = Dosent work :(

Good thing is that Chrome / Brave does work so far (just too see whether the example app also works) but bad thing is that its not working running it in Sandboxie.I always use SB to browse.Do you have maybe any clue how to get this working too to drag hyperlinks from Chrome running in SB into the app window which runs not in SB?Maybe some kind of workaround or maybe there is any setting in SB to allow this anyhow etc?

greetz

EDIT: One  more thing about this RegisterDragDrop function pDropTarget paramter.What to use there?In the example app I see its using one pointer address where are stored 7 addresses to routines.What is what and what have I to build by myself etc?Has anyone any understandable example how to create / setup pDropTarget stuff?

Edited by LCF-AT (see edit history)

Share this post


Link to post
kao
7 hours ago, LCF-AT said:

Sandboxie

..and there's your problem. :) Sandboxie blocks such communication by design - because that's the only  way it can ensure that the sandboxed process doesn't break out of it. 

I'm not using Sandboxie, so I can't tell you if/how you can work around it. Google for possible configuration options. Maybe (just maybe!) this configuration option could work: https://www.sandboxie.com/OpenWinClass

 

7 hours ago, LCF-AT said:

function pDropTarget paramter

See IDropTarget link from my first answer. It's a COM interface. It's ugly. But that's how things in Windows sometimes work - no way around it.

 

Here's another sample program - http://web.archive.org/web/20050402152142/http://home.inreach.com/mdunn/code/ClipSpy/clipspy.html - there you can actually drag/drop any link from IE, not only from address bar. So, it might be even better example than the first one I gave. Or you can look at RAEdit sources, they have most of the structures defined (no comments, though): https://github.com/m417z/SimEd/blob/master/RAEdit/DragDrop.asm

  • Like 1

Share this post


Link to post
LCF-AT

Hi kao,

thanks for the new links.I did check & copied the DragDrop.asm and adjust them.Now I tried using it in my source but the functions of IDropTarget (IDropTarget_QueryInterface,IDropTarget_AddRef,IDropTarget_Release etc) I used calling RegisterDragDrop will never accessed but the function does retun S_OK = 0.Hhmm.

.code
start:

	invoke  OleInitialize,NULL
	invoke	GetModuleHandle, NULL
	mov	hInstance, eax
	invoke  GetCommandLine
	mov CommandLine, eax
	invoke	InitCommonControls
	mov icc.dwSize, sizeof INITCOMMONCONTROLSEX
	mov icc.dwICC, ICC_COOL_CLASSES or ICC_STANDARD_CLASSES or ICC_WIN95_CLASSES
	invoke  InitCommonControlsEx, offset icc
	invoke  CreateFont,18,6,0,0,0,0,0,0,0,0,0,0,0,ADDR FontName
	mov hFont,eax
	invoke  WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
	invoke	ExitProcess, NULL


WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
	LOCAL	wc:WNDCLASSEX
	LOCAL	msg:MSG

	mov		wc.cbSize, sizeof WNDCLASSEX
	mov		wc.style, CS_HREDRAW or CS_VREDRAW
	mov		wc.lpfnWndProc, offset WndProc
	mov		wc.cbClsExtra, NULL
	mov		wc.cbWndExtra, DLGWINDOWEXTRA
	push	hInst
	pop		wc.hInstance
	mov		wc.hbrBackground, COLOR_BTNFACE+1 ; COLOR_WINDOW+1
	mov		wc.lpszMenuName, NULL;IDM_MENU
	mov		wc.lpszClassName, offset ClassName
	Invoke LoadIcon, hInstance, ICO_MAIN ; resource icon for main application icon
	mov hIcoMain, eax ; main application icon
	Invoke LoadIcon, hInstance, IDI_APPLICATION
	mov		wc.hIcon, eax
	mov		wc.hIconSm, eax
	Invoke LoadCursor, NULL, IDC_ARROW
	mov		wc.hCursor,eax
	Invoke RegisterClassEx, addr wc
	Invoke CreateDialogParam, hInstance, IDD_MAIN, NULL, addr WndProc, NULL
    mov hWnd, eax
    Invoke ShowWindow, hWnd, SW_SHOWNORMAL
    Invoke UpdateWindow, hWnd
    .WHILE TRUE
        Invoke GetMessage, addr msg, NULL, 0, 0
        .BREAK .if !eax
        Invoke IsDialogMessage, hWnd,addr msg
        .IF eax == 0
            Invoke TranslateMessage, addr msg
            Invoke DispatchMessage,  addr msg
        .ENDIF
    .ENDW
	mov eax, msg.wParam
	ret
WinMain endp


WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
	
	mov eax, uMsg
	.IF eax == WM_INITDIALOG

		invoke CoLockObjectExternal,offset pIDropTarget,1,0
		invoke RegisterDragDrop,hWin,offset pIDropTarget

Not sure whats wrong in this case yet.

greetz

Share this post


Link to post
kao

I took dragdrop.asm from raedit, commented out things that didn't immediately compile, added a simple window + initialization code and it sort of works. When something is dragged over window, you can see calls to IDropTarget_AddRef and IDropTarget_DragEnter. After that it messes up because most of the code in IDropTarget_DragEnter was commented out. But that was enough for my dumb test. :)

So, probably you did something wrong with pIDropTarget declaration or implementation.

Edited by kao (see edit history)
  • Like 1

Share this post


Link to post
LCF-AT

Hi again kao,

ok thanks,so I tried it again and now the routines get called.Problem now is how to find out the important parts and remove the RaEdit extra stuff in this asm file to get at the end somewhere the draged data (link text) in my edit control.It dosent look easy. :( I need some kind of clean template.

greetz

Share this post


Link to post
LCF-AT

Hi kao,

so could manage something to get it work at the moment = I made a tiny app with edit and can drag something into to get the text now. :) Only issue in my app is that I can only drag something into when I come from below or right side = !?When I come from above or left side then its not working and mouse cursor dosent change too.No clue what that means.Are there any rule to allow comming from all 4 sides?

Now the Sandboxie issue.I tried to add this in my Sanboxie.ini for Sandbox Brave I am using here.If I read the link correctly then I should only add this into....

OpenWinClass=$:SomeDropTarget.exe

...just my small target name.I have test it but dosent work. :(

So I have this situation.I am using now 2 of my apps.First app 1 = main app and second app = this new drop app only to get links via drag.Now when I run Brave browser in my SB then I also run my drop app in same SB = working so far.When I drag a link into drop app then it should send this link text into my main app what not runs in SB = dosent work.Only working when I run all apps in same SB or without SB so thats the bad thing.My main app must run outside of SB but drop app cant send commands now to main app from SB.

Do you have some more ideas how to get this work?

greetz

Share this post


Link to post
LCF-AT

Hi again,

I still dont get it work to send something from Sandboxie to my app outside if Sandboxie.I tried to add this into Sandboxie.ini file under the Sandbox I am using.

OpenWinClass=*
OpenWinClass=$:SomeDropTarget.exe

My SomeDropTarget dosent have a class I could use.Also I see that the function FindWindow (I do use in my SomeDropTarget.exe to find the window title of my main app) does fail to find my main app (which runs outside).

    invoke FindWindow,NULL,chr$("My Main App 1.0")
    .if eax != FALSE
        mov edi, eax
        xor esi, esi
        .while eax != FALSE
               invoke FindWindowEx,edi,esi,chr$("Edit"),NULL
               .if eax != FALSE
                   mov esi, eax
                   invoke GetDlgCtrlID,esi
                   .if eax != FALSE
                       .if eax == 1003 ; IDC_EDITSEARCH ID of main app
                            invoke SendMessage,esi,WM_SETTEXT,0,_buffer
                           .break
                       .endif
                   .endif
               .endif
        .endw
    .endif
	Ret

Thats really bad not finding a way to make it doable anyhow.Just wonder how the app IDM does it.This does also send infos from browser I run in Sandboxie to the IDM main app which runs outside!?

greetz

Share this post


Link to post
kao

As I said earlier - I don't use Sandboxie and can't help you with that. From the quick search, you could try to enable Trace mode and check the log for hints what needs to be enabled: https://www.sandboxie.com/SandboxieTrace

 

  • Like 1

Share this post


Link to post
LCF-AT

Hi kao,

thanks again.Not sure about this trace mode yet.I tried to enable the class with CMD.exe example like describled here..

https://www.sandboxie.com/OpenWinClass

...but dont know how I could test it.

I tried to think about this Sandboxie issue and found out that its possible to use the Clipboard which is same in Sandboxie and outside if I copy something into Clipboard.In this case I could also use a other method (not so nice of course) using SetClipboardViewer function and WM_DRAWCLIPBOARD msg to catch the Clipboard on fly and checking for content like CF_TEXT.So this seems to work.Only disadvantage is that it will check everything what gets copied into Clipboard.

So my first goal was it to build another app showing it in HWND_TOPMOST style where I can drag links into and sending the link text into my main app via FindWindow (fails in SB) and SendMessage to send command to my main app.Question is whether it is possible to do this anyhow else or whether its just NOT possible to send commands from a app running in SB to my main app which runs outside.Lets say its really not possible then the only choice I have is using that Clipboard hook / monitoring but then it will send everything I do copy from any source and not only from my drag app when I do drag a link into you know.

I also still have some little problem with the dragging itself as I told before.I created a main window & a edit control with same paramters like the example droptarget.exe has but in my case it has some strange behavior to drag something into.When I do move the mouse fast into my drag app then I get the mouse pointer to see in the edit field = I can drop it now into but if I move it slowly then it dosent work.Not sure what the reason for this is so it works diffrent and not for 100 % like the droptarget.exe does.Below I did attach my SomeDropTarget.exe so maybe you can test it.Only issue it that it dosent get triggered for 100 % each time and I need to move mostly few times over my main window app etc.So this I would like to fix to get it work for 100 %.

SomeDropTarget.rar

greetz

EDIT: Short info,I did removed GetWindowLong from IDropTarget_DragEnter and now it works to move / drag for 100 %.Seems there was still some RaEdit handling.Need to remove all soon. :)

Edited by LCF-AT (see edit history)

Share this post


Link to post
LCF-AT

Hi again,

ok,now I made this...in both of my apps (main app & drag app).

		invoke SetClipboardViewer,hWin
		mov nextClipboardViewer, eax


	.elseif eax == WM_DRAWCLIPBOARD
	       invoke IsClipboardFormatAvailable,CF_TEXT
	       .if eax != 0h ; text there
	           invoke OpenClipboard, NULL
	           .if eax != 0h
	               invoke GetClipboardData, CF_TEXT
	               .if eax != 0h
	                   mov edi,eax ; data pointer
	                   invoke SetDlgItemText,hWin,IDC_EDIT,NULL
	                   invoke SetDlgItemText,hWin,IDC_EDIT,edi
	                   invoke CloseClipboard
	               .else
	                   invoke CloseClipboard
	               .endif
	           .endif
	       .endif
	       invoke SendMessage,nextClipboardViewer,uMsg,wParam,lParam

	.elseif eax == WM_CHANGECBCHAIN
		mov eax,wParam
		.if eax == nextClipboardViewer
		.else
		    invoke SendMessage,nextClipboardViewer,uMsg,wParam,lParam
		.endif	

	.ELSEIF eax == WM_DESTROY
		invoke ChangeClipboardChain,hWin,nextClipboardViewer

Now I can run only my main app (outside) and get everything I do copy to clipboard from any source.Also I can run optional my drag app in Sandboxie which also get everything I do copy + using dragging mode I do prefer what does then the same = I get both clipboard content into both apps.Just had to disable it in my main app when it does use clipboard functions for itself etc.Found no way to check from which handle (any outside app and not my own app) used the copy / clipboard.Now its working so far with this method (not so nice but working if I work with SB and using dragging with mouse).

greetz

Share this post


Link to post
LCF-AT

Hi again,

found another problem using 2 apps with SetClipboardViewer & handle codes.When I first run my main app and copy something then it gets send also to my main app.When I now also run another app (using same code SetClipboardViewer & handle codes) in SB then only this will work to get something if I copy anything and my main app gets nothing anymore,also not when I do exit the app which runs in SB.Hhmm.Anyhow bad.

greetz

Share this post


Link to post
LCF-AT

Hi,

thanks for this link so I found this one too already.The Drag&Drop asm file found by kao did helped already for me.Also working for Firefox browser now (not sure why it wasnt working before / I think my fault again).Now when I do drag any link or selected text into my tiny app then it copy the content of text in clipboard and this I can then catch in my main app without to do any manually handlings anymore (copy / paste etc).

greetz

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...