Announcement

Collapse
No announcement yet.

DragDrop Library

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • jassing
    replied
    is there a way to get it to work with both file & text?

    Leave a comment:


  • Samio
    replied
    Thanks Sooooooo Much!

    Leave a comment:


  • qwerty
    replied
    ok, i managed to get my project to become focused and on top of other windows when you drag a file into it's area

    the problem was not exactly with my code, but the flakey and unreliable AMS/Windows ontop function/implementation. What i used was the app ontop function of the SendKeys DLL

    I placed this in the onstartup and on mouse move sections
    Code:
    OnTop = false;
    and then in the trigger code for the drag and drop, i added the code below, as i did before i utilised the GetEventType function that is checked in the timer section, using it to reset the OnTop variable to true and to call the DLL function, returning the value to false if the item is dragged off the project. Because the on mouse move event does not trigger if you have the mouse button depressed when you enter the project, the code in on mouse move doesnt take affect until you release the mouse button

    Code:
    	-- Switch Focus to File Splitter as user drags item to it --
    if DragDrop.GetEventType() == "DragOver" and OnTop == false then
    	OnTop = true;  -- set ontop flag to true to stop repeat DLL calls
    	SendKeys("{AppActivate File Splitter}")
    elseif DragDrop.GetEventType() == "DragLeave" then
    	OnTop = false;  -- reset ontop flag to false incase user drags item off File Splitter
    end

    Leave a comment:


  • qwerty
    replied
    i spoke too soon :( ....it works, right up to the point you move the mouse into the area with the button pressed down, then it fails to trigger (i was testing with a message box in the 2 sections of the code)... but when the mouse button is depressed, the movement into the target area is not detected..... bugger, back to the drawing board

    Leave a comment:


  • qwerty
    replied
    correction to above, i still had the Input box set in the stop line, it shoud read

    elseif not IsInRect(e_X, e_Y, Hotspot.GetPos("Drag and Drop Area1"), Hotspot.GetSize("Drag and Drop Area1")) and DnD_on == true then

    Leave a comment:


  • qwerty
    replied



    i figured it out

    apart from the superfluous tbl enumeration and loop, it was the application window handle it was stumbling on .... i've now declared that elsewhere and it works

    here's what i have now....

    Code:
    -- Function to tell whether a point is in a given objects rectangle --
    
    function IsInRect(m_nX, m_nY, m_tblPos, m_tblSize)
    	local bReturn = false;
    	if (m_nX >= m_tblPos.X) and (m_nX <= m_tblPos.X + m_tblSize.Width) then
    		if (m_nY >= m_tblPos.Y) and (m_nY <= m_tblPos.Y + m_tblSize.Height) then
    			bReturn = true;
    		end
    	end
    	return bReturn;
    end
    
    
    -- Function to Start and Stop Drag nDrop Dependant on cursor location --
    
    function Compare_Cursor_Location(e_X, e_Y)
    		if IsInRect(e_X, e_Y,  Hotspot.GetPos("Drag and Drop Area1"), Hotspot.GetSize("Drag and Drop Area1")) and DnD_on == false then
    			-- Cursor is inside drag n drop area, start Drag N Drop Function + Timer --
    			DragDrop.SetDataFormat(DataFormat.FileDrop);  -- set it to file drop mode
    			DragDrop.Start(handle);  -- Start Drag n Drop monitoring
    			error = DragDrop.GetError();
    			if (error == "") then
    				Timer2 = Timer.StartTimer("MultiTimer", 2, 100);
    			else
    				Dialog.Message("Error", error, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    			end
    			DnD_on = true;  -- set Drag n Drop running flag to on
    		elseif not IsInRect(e_X, e_Y,  Input.GetPos("file select"), Input.GetSize("file select")) and DnD_on == true then
    			-- Cursor is NOT inside drag n drop area, stop Drag N Drop Function + Timer --
    			DragDrop.Stop(handle);  -- Stop Drag n Drop monitoring
    			Timer.StopTimer( "MultiTimer", Timer2);-- Kill timer
    			DnD_on = false;  -- set Drag n Drop running flag to off
    		end
    end
    so i was wrong, it wasnt the on mouse event not triggering :o

    now to get this dam ontop thing sorted lol, also a way to move the cursor to the end of the input box after i've dropped the file would be handy for long file paths, so i can see the file name, i know i can set focus to the input box after dropping the file to it, so how to go to the end ?
    Last edited by qwerty; 02-27-2009, 05:41 PM.

    Leave a comment:


  • qwerty
    replied
    well i couldn't get a stable result from trying to make it set the project to TOPMOST and bring it to the top of all other windows.

    So i decided to mess around with some other code, to see if i could make it drag and drop only when i was within a certain object on the page, having decided that my input box was a little narrow for this i opted to put a hotspot object of a slightly larger size around it (and also to cover the browse for file button) ... and target this object.

    So i cannibalised some of Worms code (sorry buddy ) and set about making it trigger initially only on mouse over (i was going to play with the mouse button event too, but bearing in mind i have covered the browse button with hotspot i'm not sure what would happen) .... anyway, here's what i came up with..


    Startup Code
    Code:
    DnD_on = false;

    Global Code
    Code:
    -- Function to tell whether a point is in a given objects rectangle --
    
    function IsInRect(m_nX, m_nY, m_tblPos, m_tblSize)
    	local bReturn = false;
    	if (m_nX >= m_tblPos.X) and (m_nX <= m_tblPos.X + m_tblSize.Width) then
    		if (m_nY >= m_tblPos.Y) and (m_nY <= m_tblPos.Y + m_tblSize.Height) then
    			bReturn = true;
    		end
    	end
    	return bReturn;
    end
    
    
    -- Function to Start and Stop Drag nDrop Dependant on cursor location --
    
    function Compare_Cursor_Location(e_X, e_Y)
    
    	tblObjects = Page.EnumerateObjects();  -- Get object names on page, put in a table
    
    	for index, sObject in tblObjects do
    		if sObject == "file select" then
    			if IsInRect(e_X, e_Y,  Hotspot.GetPos("Drag and Drop Area1"), Hotspot.GetSize("Drag and Drop Area1")) and DnD_on == false then
    				-- Cursor is inside drag n drop area, start Drag N Drop Function + Timer --
    				DragDrop.SetDataFormat(DataFormat.FileDrop);  -- set it to file drop mode
    				DragDrop.Start(Application.GetWndHandle());  -- Start Drag n Drop monitoring
    				error = DragDrop.GetError();
    				if (error == "") then
    					Timer2 = Timer.StartTimer("MultiTimer", 2, 100);
    				else
    					Dialog.Message("Error", error, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    				end
    				DnD_on = true;  -- set Drag n Drop running flag to on
    			elseif not IsInRect(e_X, e_Y,  Input.GetPos("file select"), Input.GetSize("file select")) and DnD_on == true then
    				-- Cursor is NOT inside drag n drop area, stop Drag N Drop Function + Timer --
    				DragDrop.Stop(Application.GetWndHandle());  -- Stop Drag n Drop monitoring
    				Timer.StopTimer( "MultiTimer", Timer2);-- Kill timer
    				DnD_on = false;  -- set Drag n Drop running flag to off
    			end
    			break;
    		end
    	end
    end

    and, it works like a charm...... until i realised that if the project isn't in focus it doesnt work


    anyone know a way around this ? the drag and drop dll obviously works when the project does not have focus, whereas the on mouse move event doesn't.... so i'm back to needing ti trigger an event when the mouse passes over into the project boundry !! ... i seem to have come full circle here

    Leave a comment:


  • qwerty
    replied
    vey useful.

    now, how do i make it bring the project on top of other windows when i drag something over it, been trying to insert the code in the ontimer section where it fills in the status text box, but cant get it to work.. i figured i could use an if statement to grab the eventType and set the apps ontop status using the "DragOver" result as a trigger, but cant get it to work

    Leave a comment:


  • Centauri Soldier
    replied
    Thanks much sside! Great DLL!:yes

    Leave a comment:


  • Proent
    replied
    Thanks for another awesome dll!!

    Leave a comment:


  • SiNisTer
    replied
    Beautiful...

    Thanks

    Leave a comment:


  • AudioSam
    replied
    Good Job sside,

    Thank you,
    This works very well.
    Now,,, It's drag and drop time!!!

    Thank You,
    AudioSamIam:yes

    Leave a comment:


  • amimanera
    replied
    thanks sside :yes you're good & god!! xDD

    Leave a comment:


  • RizlaUK
    replied
    This is fanstasic :yes

    i managed to get my drag n drop dll working but its very unstable and only single files accepted, this dll is just the ticket

    @ sside, do you have a donations page ?

    the whole community owes you for this little gem, i have been passing my droped file path from a PB window to a ams exe via commandline for my current project which is VERY messy, this will sort that out

    Thank you :yes

    Leave a comment:


  • sside
    replied
    Thanks for the feedback, i appreciate it.



    With Kind Regards
    sside

    Leave a comment:

Working...
X