Guidance Forums / Reginald Rexx / Minimizing a window to the system tray

Search 搜索
Home Home

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Minimizing a window to the system tray
Posted by: Michael S 2010-11-03 15:50:49
Is there some simple way of doing this (and if there is, it goes without saying that I need to be able to detect if the user clicks on the icon and (re)opens the window)
Posted by: Jeff Glatt 2010-11-05 11:30:07
Look at the trayicon.rex example script on my web page.
Message3. Thanks for the pointer Jeff, but there's one thing I don't understand
Posted by: Michael S 2010-11-06 16:46:01
The window text control says to click on the icon bar and hold. I include 3 screen captures to show what I'm doing (in case I'm misunderstanding you).

As you can see (?) from the 3rd capture, it seems that when I minimize the window via the icon in the top left-hand corner, it's minimized to both the system tray AND the taskbar which isn't what I'm after. I only what it minimized (and visible) in the tray

Am I doing something wrong ?



Message4. After playing a bit, I came up with this solution
Posted by: Michael S 2010-11-06 18:26:13 Last edited by: Michael S 2010-11-06 18:31:19 (Total edited 1 time)
Would you go this way, Jeff, or is there a better way ? I changed the trayicon example to the following

/* Hide this window so it'll ONLY be visible in the system tray */ 
err = guisetctlplacement(,,,,,,'HIDE')  
				/* Did he double-click on the icon? */
						/* Make the window visible again */
						guiaddctltext("TrayResult", "User double-clicked the icon")
/* and finally */
temp = ARG(1) + ARG(2) + ARG(3) + ARG(4)
IF temp = 0 THEN
	/* They're minimizing the window - hide it so it's only
	   visible in the system tray */ 
One final question. I notice that when I close the window it disappears (of course), BUT how do I programmatically close/remove the icon from the system tray. It hangs around until I move the mouse over it (whereupon it disappears automatically)
Message5. I'll answer that last question myself
Posted by: Michael S 2010-11-06 20:46:44
There seems to be a slight bug in the example you posted. I changed the code to the following:-

IF shell_notifyicon(0, notifyicondata) == 0 THEN
		tray = 'No' 
		rc = wdwsay.rex("Failure setting the icon", "STOP")
	/* Indicate that we have an icon installed */
	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.
/* Hide this window */ 


		SIGNAL again

		/* If we added an icon to the tray, we need to delete it now */
		IF tray = 'Yes' /* EXISTS(Tray) */ THEN 
 etc etc
However, I do have another problem, and that is I can only seem to get the left double-click on the icon in the system tray to "kick in" every other time. Here's an example of some says based on your code example. Any suggestions as to what/why this is happening ?

Message6. In the end
Posted by: Michael S 2010-11-10 05:46:06
I changed the code so that it would reopen the window if the right button was pressed.

One other question Jeff - is it correct to test for ARG(1) = 13 in WM_EXTRA to know that Windows is shutting down/restarting ? (I need to know so that I can save various settings before closing the application)

Based on the example in trayicon example, I could find in the MS documentation that WM_RBUTTONDOWN = 0x0204 = 516 (dec), but I couldn't find any equivalent value for WM_QUERYENDSESSION or WM_ENDSESSION
Posted by: Jeff Glatt 2010-11-10 08:44:35
When doing a google search for the numeric value of a WM_ constant, add #define to your search request:


For example, the above will reveal the text:


Note that 0x before a number is the C language's hexadecimal. (Same as appending 'X in REXX). So this is decimal 17. I haven't experimented with a QUERYENDSESSION event handler (which is how you handle that. Not from a WM_EXTRA event handler. WM_EXTRA is only needed for some rare WM_ values that REXX GUI doesn't know about and list in the "Event handlers" listbox, such as the tray messages, or your own custom messages). Kare once did and reported that Windows doesn't always report it. (Maybe it's sent only to the active window). Note that you have only a few seconds before your script is terminated.
Message8. I tested a bit at work.
Posted by: Michael S 2010-11-10 23:38:32
The results I got seemed a bit strange, but I'll include them here, nonetheless.

Using (as we do) XP Pro resulted in the following values being passed to arg(1) arg(2) and arg(3) in WM_EXTRA.

Logoff     -2147483637    0 59    (Strange first value ??)
Restart                      11    0 59
Shutdown                  11    0 59

so my code simply tests for 0/59 in args 1 & 2. If it finds it, I write my outstanding data to my files and "pretend" to do a WM_CLOSE to close everything tidily.

Note that the 13 mentioned in the earlier append seems to be the restart/shutdown values when running ordinary XP
Message9. I thought I'd append this last "finesse" I added
Posted by: Michael S 2010-11-20 01:09:49

 Let's resize
temp = ARG(1) + ARG(2) + ARG(3) + ARG(4)

IF temp = 0 THEN
		/* They're minimizing the window - hide it so it's only
	     visible in the system tray */ 
		notifyicondata.7 = active_tupp_code
		/* Change the tip shown for the tray icon to the current TUPP code */
		rc = shell_notifyicon(1, notifyicondata)	


What this does is to change the tip shown when the mouse passes over the icon in the system try yo whatever is currently in active_tupp_code (TUPP is a system at work that is used to register time spent on various projects). I've written an application that allows a user to automatically keep track of which project (tupp code) they're working on. All they have to do is check on the code they're working on at the moment and a time starts for that code. The "finesse" above allows them to pass the mouse over the system tray icon to see which code is currently being debited. rather than opening the window to see
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
© Sat 2018-5-26  Guidance Laboratory Inc. Hits:0