"Minimize to Tray Icon" on the control box

Hey all,
I'm workin on an application that has some fun features in it including an option to run at startup. When it runs at startup, it is loaded into the system tray instead of maximized. Once the user restores the window to the screen and all, there is an option to return the app to the system tray so that it can still process and receive data through its network connection. All of that is runnin pretty darn well but I want to add one more bit of convenience- right now the only way to return the app to the system tray is through a menu item... how to I load up a button on the window's control box (next to minimize, maximize, and close) that will do this task? An example of such is found in the API-Guide 3.6 which i'm sure many of you are familiar with. Isn't that little system tray button handy? well, i like it anyway. Thanks in advance for any help!!

Jeff
[917 byte] By [Ghost308] at [2007-11-15 16:16:27]
# 1 Re: "Minimize to Tray Icon" on the control box
You will need to subclass your form and add the button in the WM_NCPAINT message processing I'd imagine.

Why not make the form's VisibleInTaskBar member = false so that it is only shown in the system tray?

HTH,
Duncan

---------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
Clearcode at 2007-11-10 0:59:11 >
# 2 Re: "Minimize to Tray Icon" on the control box
if you want to capture events on the system tray icon of your app (like mouse click...) write that:

private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
' get messages received from NotifyIcon
' Messages are passed in the x parameter

Dim Msg as Long

Msg = (X And &HFF) * &H100
Select Case Msg

Case 0 ' mouse move
' your code here

Case &HF00 ' left button down
' your code here

Case &H1E00 ' left button up
' your code here

Case &H2D00 ' left button doubleclick
' your code here
ChangeIcon

Case &H3C00 ' right button down
' your code here

Case &H4B00 ' right button up
' your code here

Case &H5A00 ' right button doubleclick
' your code here

End Select
End Sub

when picture1 is the pic you connect with the tray
I DID NOT write this, i copied it from somewhere and lost the source so the rights are still reserved to that person (that one is for learning purposes...:-})

----
The @host is everywhere!
----
deghost at 2007-11-10 1:00:17 >
# 3 Re: "Minimize to Tray Icon" on the control box
If all you want to do is add a Button to the titleBar, GO to http://www.planetsourcecode.com/vb/scripts/BrowseCategoryOrSearchResults.asp?txtCriteria=custom+button+in+titlebar&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUE&lngWId=1&B1=Quick+Search&optSort=Alphabetical
From there add the code you want to its click event. ethe example shows 4 buttons in the Title Bar, CLose,max,min and the new button

John G
John G Duffy at 2007-11-10 1:01:13 >
# 4 Re: "Minimize to Tray Icon" on the control box
Hey- thanks for replying...

This is exactly what i'm trying to accomplish:
simply adding the button to the title bar. This example does that, but it keeps going into an infinite loop or something because after i press the button it locks up and i have to end task the IDE. Any thoughts?
Ghost308 at 2007-11-10 1:02:18 >
# 5 Re: "Minimize to Tray Icon" on the control box
I tested the sample app out and could not find any problems with it as such. I am using Windows ME V 6.0 professional edition.
I do know there are somethings you can't do when using Callbacks and that is tracing or trapping in the callback function. It causes all sorts of problems if you axe the callback function.
Try putting some Debug.print statements at various points to see where you are looping or hanging.
I tried putting a Debug.Print in the HookProc sub and it blew VBs mind with errors in Kernel32.dll.
Don't see anyplace it can be looping.

John G
John G Duffy at 2007-11-10 1:03:11 >
# 6 Re: "Minimize to Tray Icon" on the control box
Hmm, I'm using NT 4.0 but I wouldn't think that would make this big a difference. Oh well, I know i'm close to having this finished anyway, thank you very much for your help!!
Ghost308 at 2007-11-10 1:04:19 >
# 7 Re: "Minimize to Tray Icon" on the control box
I would suspect Callback routines are finicky. I would look for one that is specific to NT and go from there. Windows 95 98 98Se and ME are pretty similar but NT is another animal as is 2000.

John G
John G Duffy at 2007-11-10 1:05:23 >