Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Minimizing a window to the system tray

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

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Minimizing a window to the system tray
#13385
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)
Message2.
#13386
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
#13390
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 ?

trayicon_1.png

trayicon_2.png

trayicon_3.png
Message4. After playing a bit, I came up with this solution
#13394
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')  
again:
DO FOREVER
.......
				/* Did he double-click on the icon? */
				WHEN 515 /* WM_LBUTTONDBLCLK */ THEN 
					DO
						/* Make the window visible again */
						guisetctlplacement(guiwindow,,,,,,'NORMAL')
						guiaddctltext("TrayResult", "User double-clicked the icon")
					END
......
/* and finally */
wm_size:
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 */ 
	guisetctlplacement(,,,,,,'HIDE')  
RETURN	
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
#13395
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
	DO
		tray = 'No' 
		rc = wdwsay.rex("Failure setting the icon", "STOP")
	END	
ELSE 
	/* 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 */ 
guisetctlplacement(,,,,,,'HIDE')  
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 tray = 'Yes' /* EXISTS(Tray) */ THEN 
			DO
 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 ?

trayicon_4.png
Message6. In the end
#13413
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
Message7.
#13414
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:

#define WM_QUERYENDSESSION

For example, the above will reveal the text:

#define WM_QUERYENDSESSION 0x0011


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.
#13415
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
#13423
Posted by: Michael S 2010-11-20 01:09:49

/*********************************************************
 Let's resize
*********************************************************/
wm_size:
temp = ARG(1) + ARG(2) + ARG(3) + ARG(4)

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

RETURN
  


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
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0