Re: Drag ' n ' Drop

new topic     » goto parent     » topic index » view thread      » older message » newer message
bugmagnet said...

Arwen is listed on the openeuphoria site .. but you already knew that.

Bugmagnet

<Ahem> I really should update that but my development version has been converted to Orac-style which means that although it is more convenient to program it is not fully compatible with Euphoria. In any case, I think Al Getz would have used his own WinClass to demonstrate Drag 'n Drop rather than my Arwen.

To use Drag 'n Drop in Windows one must first register the control by passing its native handle to xDragAcceptFiles. Then when the event occurs the message WM_DROPFILES is sent to the control's handler. To retrieve the file/folder names one has to pass wParam to getDroppedFiles() (which wraps xDragQueryFile).

For anyone interested here are the relevant routines in Arwen (probably ripped from Edita and which also need some tweaking to work in Euphoria):

Spock

 
global procedure setDragAndDrop(int id, int onoff) 
 
-- To enable Drag 'N Drop the user must register the window with setDragAndDrop() 
-- to accept dragged files and then capture the WM_DROPFILES msg calling 
-- getDroppedFilenames(wParam) to get the file names 
-- The window can be unregistered via setDragAndDrop() as well to NOT accept dropped files 
	 
	atom hWnd = ObjectHwnd[id] 
	c_proc(xDragAcceptFiles, {hWnd, onoff}) 
	end procedure 
-- 
-- 
 
global function getDroppedFiles(atom handle) 
--The DragQueryFile function retrieves the filenames of dropped files.  
-- 
--UINT DragQueryFile( 
--    HDROP hDrop,	// handle to structure for dropped files 
--    UINT iFile,	// index of file to query, 0-based 
--    LPTSTR lpszFile,	// buffer for returned filename 
--    UINT cch 	// size of buffer for filename 
--  
--hDrop - Identifies the structure containing the filenames of the dropped files.  
--iFile - Specifies the index of the file to query. If the value of the iFile parameter is 0xFFFFFFFF, DragQueryFile returns a count of the files dropped. If the value of the iFile parameter is between zero and the total number of files dropped, DragQueryFile copies the filename with the corresponding value to the buffer pointed to by the lpszFile parameter.  
--lpszFile - Points to a buffer to receive the filename of a dropped file when the function returns. This filename is a null-terminated string. If this parameter is NULL, DragQueryFile returns the required size, in characters, of the buffer.  
--cch - Specifies the size, in characters, of the lpszFile buffer.  
-- 
--When the function copies a filename to the buffer, the return value is a count of the characters copied,	not including the terminating null character.  
--If the index value is 0xFFFFFFFF, the return value is a count of the dropped files.  
--If the index value is between zero and n-1 and the lpszFile buffer address is NULL, the return value is the required size, in characters, of the buffer, not including the terminating null character. 	 
 
	-- get number of files dropped 
	int count = c_func(xDragQueryFile, {handle, #FFFFFFFF, 0, 0}) 
 
	-- early out? 
	if not count then 
		return {} 
	end if 
 
	-- init 
	seq names = {} 
 
	for i = 1 to count do 
 
		-- get buffer size required 
		int size = 1 + c_func(xDragQueryFile, {handle, i-1, 0, 0}) 
 
		-- get some buffer space 
		atom pBuffer = fast_allocate(size) 
 
		-- call the API to fill the buffer with the name 
		size = c_func(xDragQueryFile, {handle, i-1, pBuffer, size}) 
 
		-- retrieve the null-terminated string 
		seq name = peek({pBuffer, size}) -- peek_string(pBuffer) 
		names = append(names, name) 
 
	end for 
 
	return names 
 
	end function 
-- 
-- 
 
global function getDroppedFile(atom wParam) 
 
	-- try to get some names 
	seq tmp = getDroppedFiles( wParam ) 
 
	-- early out? 
	if not ~tmp then 
		return "" 
	end if 
 
	-- success 
	if seq(tmp.1) then 
		return tmp.1 
	end if 
 
	-- exit, failed 
	return "" 
 
	end function 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu