[Last Call] Learn how to a build a cloud-first strategyRegister Now


VB6 and Tray Icon

Posted on 2005-04-13
Medium Priority
Last Modified: 2008-02-01

I used to use Me.Hide and call the notification icon function to create a minimize to tray effect.

The problem with that is the app still shows up on the "Task" list, which sometimes interferes with system's shutdown. I know that this is because the form is not properly unloaded, but only hidden.

Is there any better way that is better than Me.Hide that will actually "unload the form" but the "app remains open"?

Question by:HM_CodeMaster
  • 2
  • 2
  • 2
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 13777897
I cant see why you couldnt use Unload frm1 from with a module level code but I think you would lose the ability to show the form again and certainly the use of right-click menus would not be available as they are part of the form.

Expert Comment

ID: 13778775
I  had the same thing happen to me. here's what i did.

1. use Sub Main in a module as the startup routine.
2. in Sub Main, load a form(frmTrayIcon) that contains the trayicon code in form_load.
3. in (frmTayIcon's) Form_Unload and Form_QueryUnload, put your shutdown routine. this form will only shutdown if you shutdown the computer.
4. Create menu commands For Program Exit and Shutdown that are accessed from the rightclick of the trayicon and on the frmTrayIcon Form. You can then unload the other form or do a hide (its not the form keeping the application alive any more.)

In a nut shell, you have a form that loads once at startup and all it knows is to stay loaded, until proper application shutdown, and holds your Icon Menu. If your computer goes to unload that form because it is shutting down, that form know how to shut the Application down properly. you wont get anymore crashes on shutdown. Your other forms are just loaded and unloaded when you need them. And if you want you could call your shutdown from any of the other forms as well.

Author Comment

ID: 13778953
Ok, I really appreciated your response.

However, I'm not very familiar with the apps startup routine thingy, and I don't really understand because the tray icon is now tied to the frmTrayIcon, which cannot be unloaded because frmTrayIcon is the object that keep the app alive, then it will comes to the same problems isn't it, you can only call frmTrayIcon.Hide but not Unload frmTrayIcon.

Sorry if I misunderstood anything but can you give me the pseudo-code for Sub Main and frmTrayIcon?

Another thing, where should I put the Sub Main routine? In the BAS module?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 13778980
In case you don't fully understand my question.

Say it simply, is there any way to make the "Process" running while not displaying on the "Task" part in the Windows Task Manager. Normally tray-icon-based program like Outlook, MSN Messenger, etc. tend to unload the application but remains running in the system memory (so the app is still shown in "Processes" but not "Tasks") Is there a way to do the same thing in VB6?
LVL 32

Accepted Solution

Robberbaron (robr) earned 400 total points
ID: 13779021
To your last post, no I dont think so. Applications are usually in the Tasks & Processes set, while Services are in the Processes set.

I think wraiths description of the startup / shutdown is earier to read. As to your quey re startup seq, you can either nominate a Sub Main() or a Form (which invokes the Form_Load) to be the initial point of your application.  This selection is on the Properties Dialog of your project, Startup object.

I think what Wraith is saying is that when you app is asked to shutdown by the os, it calls the Query_Unload. Therefore you should put code that closes all other forms, objects , files etc within the application in either location. Or call your own CleanQuit routine, that way the quit routine can be called from elsewhere within the app as well.

From VB5 help on Query_Unload... {This event is typically used to make sure there are no unfinished tasks in the forms included in an application before that application closes. For example, if a user has not yet saved some new data in any form, your application can prompt the user to save the data.
When an application closes, you can use either the QueryUnload or Unload event procedure to set the Cancel property to True, stopping the closing process. However, the QueryUnload event occurs in all forms before any are unloaded, and the Unload event occurs as each form is unloaded.}

Expert Comment

ID: 13780563
dang, thats makes about 3 questions i have answered and got no points for. My l luck sucks, or i can't explain anything in simple terms hehehh :)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question