Guidance
指路人
g.yi.org
Software / Reginald / Examples / drop.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*
GUIBEGIN
WINDOW , 76, 220, 331, 180, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, FILES, Drag and Drop some files on this window
	FONT 8, 400, MS Shell Dlg
	LIST 12, 9, 282, 86, NOTIFY|BORDER|VSCROLL|HSCROLL|TABSTOP, , MyList
DEND
GUIEND
*/

/*
 * An example of handling the DROPFILES event of a REXX GUI
 * window. Note: The window must have the "Accept files" (FILES)
 * extra style.
 */

LIBRARY rexxgui

DO
	/* Register some Windows OS functions that we'll need to call when
	 * we get the WM_DROPFILES message.
	 */
	FUNCDEF("DragAcceptFiles", ", void, 32u", "shell32")
	FUNCDEF("DragQueryCount", "32u, void, 32, void, void", "shell32", "DragQueryFile")
	FUNCDEF("DragQueryFile", "32u, void, 32u, str[260] stor, 32u", "shell32")
	/* If you want to also be able to determine the mouse pointer's
	 * position where the icons were dropped inside your window,
	 * then you can FUNCDEF and call DragQueryPoint.
	 */
	/*
	POINT = '32u, 32u'
	FUNCDEF("DragQueryPoint", "32u, void, struct POINT stor", "shell32")
	*/

	CATCH FAILURE
		CONDITION("M")
		RETURN
END

guierr = "SYNTAX"
guiheading = 1
guicreatewindow('NORMAL')

again:
DO FOREVER

	guigetmsg()

	CATCH SYNTAX
		CONDITION('M')
		SIGNAL again
	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN

/* ================== WM_DROPFILES ==================
 * This handles the DROPFILES message for my window.
 *
 * Reginald calls this when the user drops some
 * file icons on our window, or some control in our
 * window.
 *
 * ARG(1) is a handle that we'll need to pass to
 * some other OS functions in order to enumerate
 * the names of all files dropped on our window.
 *
 * If the files were dropped on some control, then
 * ARG(2) is a handle to that control. If they were
 * dropped on the window itself, then ARG(2) is GuiWindow.
 */

wm_dropfiles:

	/* Get the count of how many icons were simultaneously
	* dragged and dropped on our window. (There could be
	* more than one icon).
	*/
	count = dragquerycount(ARG(1), -1)

	IF ARG(2) == guiwindow THEN DO

		guisay("There were" count "icons dropped on this window.")
		variable = ""
	END
	ELSE DO
		/* Get the REXX variable associated with the control handle. NOTE:
		 * The returned variable name is upper-cased.
		 */
		variable = guiinfo("VARIABLE", ARG(2))
		guisay("There were" count "icons dropped on" variable || ".")

		/* Clear out the listbox. */
		guisendmsg("MyList", "RESETCONTENT")
	END

	/* Get the name of each one of those icons' files.
	* We loop around a call to DragQueryFile(), and the
	* second arg tells which file's name we want. The
	* first file is number 0, the second file is number
	* 1, the third is number 2, etc.
	*
	* DragQueryFile() will return the file's name in
	* whatever variable we pass as the third arg. Below,
	* we use a variable named "Filename".
	*/
	DO i = 1 TO count

		dragqueryfile(ARG(1), i - 1, filename, 260)

		/* If dropped on the listbox, add the filename. */
		IF variable \== "" THEN guisendmsg("MyList", "ADDSTRING", , filename)

	END

	/* If we handle WM_DROPFILES, we return an empty string */
	RETURN ""
© Sun 2024-5-12  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:46:06