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

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

  
/*
GUIBEGIN
WINDOW , 149, 285, 193, 85, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , Tray icon example
	FONT 8, 400, MS Shell Dlg
	TEXT 5, 7, 134, 8, GROUP, , , , Click on the icon in the task bar and hold
	TEXT 4, 21, 132, 8, GROUP, , TrayResult
DEND
GUIEND

*/

/*
 * An example of handling the CTLCOLOREDIT event of a
 * REXX GUI window to set the color of ENTRY controls.
 *
 * In this example, we'll change the color of ENTRY controls in
 * window. This will be almost the same as colors.rex (which
 * handled the CTLCOLORSTATIC event) but here we're going to do
 * one other thing. Instead of changing the colors of all entry
 * boxes, we're going to change only one specific entry box. To
 * do this, you'll see how you can use the window handle arg to
 * our WM_CTLCOLOREDIT to determine the correct control.
 */

LIBRARY rexxgui

DO
	/* Register Shell_NotifyIcon once (and the NOTIFYICONDATA struct) */
	notifyicondata = "32u, 32u, 32u, 32u, 32u, 32u, str[64]"
	FUNCDEF("Shell_NotifyIcon", "32u, 32u, struct NOTIFYICONDATA", 'shell32')

	/* Register LoadImage once */
	FUNCDEF('LoadImage', '32u, 32u, str, 32u, 32u, 32u, 32u', 'user32')

	/* Register DestroyIcon once */
	FUNCDEF("DestroyIcon", "void, 32u", 'user32')

	CATCH FAILURE
		CONDITION("M")
		RETURN
END

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

/* ================= Load an icon (image) =================== */
hicon = loadimage(0, "MyIcon.ico", 1 /* IMAGE_ICON */, 16, 16, 16 /* LR_LOADFROMFILE */)
IF hicon == 0 THEN DO
	guisay("Error loading MyIcon.ico")
	SIGNAL skip
END




/* =============== Add an icon to the tray ================== */

/* Set the size */
notifyicondata.1 = 88

/* Set the window that receives a notification message when the user manipulates the icon */
notifyicondata.2 = guiwindow

/* Set the ID number we wish to use for the icon. We'll arbitrarily use 10 */
notifyicondata.3 = 10

/* Set the flags. We want NIF_MESSAGE, NIF_ICON, and NIF_TIP */
notifyicondata.4 = 1 /* NIF_MESSAGE */ + 2 /* NIF_ICON */ + 4 /* NIF_TIP */

/* Set the callback message (number) we wish our window to receive. So as
 * not to interfere with standard Windows messages, this value should be
 * at least WM_USER (ie, 32768) and less than 65536. Let's just use a
 * value of 50000.
 */
notifyicondata.5 = 50000

/* Set the handle to the icon we want displayed */
notifyicondata.6 = hicon

/* Set the tooltip text. It can be 63 characters max */
notifyicondata.7 = "This is my tooltip text."

/* Add an icon to the tray.
 *
 * The first arg to Shell_NotifyIcon is one of the following:
 *
 * 0 = Add an icon.
 * 1 = Modify an icon that we previously added.
 * 2 = Remove an icon that we previously added.
 *
 * Second arg is the name of the REXX variable where we have
 * initialized a NOTIFYICONDATA struct.
 *
 * RETURNS: 0 if failure, or non-zero otherwise.
 */

IF shell_notifyicon(0, notifyicondata) == 0 THEN guisay("Failure setting the icon")

/* Indicate that we have an icon installed */
ELSE tray = "Yes"

/* Now Windows will send a message number of 50000 whenever the user manipulates
 * our icon in the tray. And it will be sent to our REXX Dialog window we
 * subclassed.
 */

again:
DO FOREVER

	guigetmsg()

	CATCH SYNTAX
		CONDITION('M')
		SIGNAL again

	CATCH HALT
	FINALLY
		/* If we added an icon to the tray, we need to delete it now */
		IF EXISTS(tray) THEN DO

			/* Set the size */
			notifyicondata.1 = 88

			/* Set the window that received notification messages */
			notifyicondata.2 = rxhandle

			/* Set the ID number we used for the icon */
			notifyicondata.3 = 10

			/* Note: This above 3 fields should already be set from when we installed the
			 * icon. After all, we didn't alter them. But just for clarity, I initialized
			 * just the needed fields again.
			 */
			 
			/* Delete it */
			shell_notifyicon(2, notifyicondata)
		END

		/* Destroy the icon */
		IF EXISTS(hicon) THEN destroyicon(hicon)
	
		guidestroywindow()
END
RETURN

/* ===================== WM_EXTRA ========================
 * This handles all events for our window which REXX
 * GUI doesn't know about. REXX GUI doesn't know about
 * any of the tray events, so any tray event causes
 * Reginald to call this handler.
 */

wm_extra:

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

		/* It our custom event we used for the tray? If so, the
		 *  message number = 50000 because that's what we chose.
		 *
		 * The OS causes this even when some activity happens
		 * with our tray icon.
		 *
		 *
		 * ARG(1) is the ID number we used for the icon. In this
		 * example, it was 10.
		 * ARG(2) is the message number sent from the icon.
		 */
		WHEN 50000 THEN DO

			/* Let's see what sort of message was sent */
			SELECT ARG(2)

				/* Did he click the mouse on the icon? */
				WHEN 513 /* WM_LBUTTONDOWN */ THEN guiaddctltext("TrayResult", "User clicked upon the icon")

				/* Did he release the mouse button? */
				WHEN 514 /* WM_LBUTTONUP */ THEN guiaddctltext("TrayResult", "")

				/* Did he double-click on the icon? */
				WHEN 515 /* WM_LBUTTONUP */ THEN guiaddctltext("TrayResult", "User double-clicked the icon")

				/* For all other messages, we have no processing */
				OTHERWISE

			END /* SELECT ARG(2) */

		END /* Custom message */

		OTHERWISE

	END /* SELECT message number */

	/* Don't let Rexx Gui process this event. */
	RETURN ""
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:47