/* 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. */ OPTIONS "C_CALL LABELCHECK WINFUNC NOSOURCE" 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 msg /* 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 ""