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

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

  
/*
GUIBEGIN
WINDOW , 49, 110, 311, 120, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , My Window
	FONT 8, 400, MS Shell Dlg
DEND
GUIEND
*/

/* This script, in conjunction with the script SendMsg2.rex, demonstrates
 * how one script can send a custom event to another script's window.
 * Run this script first. Then run SendMsg2.rex and it will send a custom
 * event with an event number of 40000. This script will display that
 * info when it receives the event. The other script will also send another
 * custom event with an event number of 40001. For that second event, we
 * return a value to the other script.
 */

LIBRARY rexxgui, rxclip
guierr = "SYNTAX"
guiheading = 1
cliperr = "SYNTAX"
clipheading = 1
guicreatewindow('NORMAL')

/* Let's create our own custom clipboard format with a name
 * of "WindowHandle". Then we'll store our window's handle
 * on the clipboard so some other script can grab it.
 */
FORMAT = clipnewformat("WindowHandle")
clipset("GuiWindow", format)

again:
DO FOREVER
	guigetmsg()
	CATCH SYNTAX
			CONDITION()
			SIGNAL again
	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN

/* ==================== WM_EXTRA ====================
 * This handles all events for our window which REXX
 * GUI doesn't know about (ie, custom events). Another
 * script can send us a custom event by passing a
 * numeric arg for the second arg to GuiSendMsg (as
 * opposed to an event name such as "CLOSE", "CLICK",
 * etc).
 *
 * For example, here's how to send our window a
 * custom event with an event number of 40000, and
 * two additional numeric args of 1 and -1. NOTE:
 * The other script must somehow obtain our window
 * handle. We assume it did so, and saved the handle
 * in its variable "SomeWindowHandle".
 *
 * GuiSendMsg(SomeWindowHandle, 40000, 1, -1)
 *
 * When we call GuiGetMsg() in our loop above, and
 * GuiGetMsg() encounters this custom event, it
 * automatically calls our WM_EXTRA subroutine.
 *
 * ARG(3) is the event number that the other script
 * passed to GuiSendMsg().
 *
 * ARG(1) and ARG(2) are the two additional args
 * passed to GuiSendMsg(), if any.
 */
 
wm_extra:

	/* Figure out what to do based on the event number */
	SELECT ARG(3)

		/* Is it our custom event number 40000? */
		WHEN 40000 THEN DO

			/* It's the 40000 event someone GuiSendMsg()'ed to us */
			guisay("Received event 40000 with ARG(1) =" ARG(1) "and ARG(2) =" ARG(2))

		END

		/* Is it our custom event number 40001? */
		WHEN 40001 THEN DO

			guisay("Received event 40001. Returning the value 1000 to the other script.")

			/* The other script expects us to return a numeric value.
			 * We'll arbitrarily return 1000. Any return value from
			 * WM_EXTRA() MUST be numeric. (Ie, we can't return a
			 * string such as "Hello").
			 */
			RETURN 1000

		END

		OTHERWISE

	END

	/* Returning an empty string from WM_EXTRA really means "no return value" */
	RETURN ""
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-4-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:40