Re: Application to Tray



Hello,

I think you can cheat a little by using the SetWindowPos API.

Your VB program can issue a window message to, say, notepad (or
whatever App you have in mind) to hide that window. This is done by
using the SWP_HIDEWINDOW flag in the SetWindowPos API. Once you have
hidden the window, your VB program can then place a small icon in the
sytem tray representing the "minimized to sytem tray" application, in
this case, notepad (I think you can extract notepad's icon from notepad
itself).

When the user double clicks the notepad icon on the system tray, the VB
program should remove the icon in the system tray then issue another
SetWindowPos message, only this time, use the SWP_SHOWWINDOW flag to
restore the window.

There are two catches here. One is that SetWindowsPos must know the
exact windows caption for it to send a message to that window. For
example, when you open notepad, its caption is "Untitled - Notepad".

The second is you can minimize it to the system tray through your VB
proram only. If you want to minimize to the system tray using the
minimize button of notepad itself, I think it is possible to subclass
the notepad window and replace the window default procedure with your
own so that it watches for the WM_SIZE message with the SIZE_MINIMIZED
wParam value. Once your VB program sees this messages, it should hide
notepad and insert an icon in system tray. Note that my knowledge in
subclassing is very limited so I am not sure if this will even work.
Also, I am told to be wary when subclassing windows so be sure to save
everything first before running the program. It might be a good idea to
compile and not run it the IDE.

For more info, check out
http://www.mentalis.org/apilist/SetWindowPos.shtml. They've got pelenty
of examples you can try out. For subclassing, take a peek at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windowprocedures/aboutwindowprocedures.asp

I know its a bit lengthy but I hope this helps.

Chad

.