Send Text from One App to Another - December 2000
Activating a Previous Instance of an Application

Thanks to Francesco Balena's article, Synchronize Your Apps, page 58, in the September 2000 issue of the Visual Basic Programmers Journal, I was able to develop a simple routine to allow communication between running applications. You may need to be a 'premier' member to view the article online. I added a few wrinkles and made this the tip-of-the-month.

The Concept

The concept behind the inner-application communication is simple:

  1. Create a form containing a text box.
  2. Get the handle to the form.
  3. Send text to the form's text box.
  4. Use the text box's change event to perform the desired actions.

Sample Inner-Application Communication

The sender.

The receiver.

My 'Wrinkle'

I created an 'invisible' GUID form. The advantage is that the form's caption will always be unique. To learn more about GUID's and how to create them click here. If you use this concept then be sure to unload the invisible form when you end your application. You should create a different GUID form for each application in which you use this concept. By using a unique form name you insure that you are always talking to the correct application. My sample shows communication one way - from sender to receiver - Francisco's shows how to implement two way communication.

Possible Uses

One Instance A common problem - the user start's a second instance of the application. VB provides a 'previous instance' facility to determine if it is already running but not a very good way to active the current instance. Use this feature to send a message to the current instance to cause it to become active and if minimized be restored. See the sample below.
Preview I created an application that changes information in a database and then sends information to a receiving application. The receiver reads the new information from the database and updates it's main form.

Only One Instance

I wrote a very small application that shows how to use inner-application communication to make sure only one instance of an application is running. The VB source code is included under project name 'projAppOneInstance'. I compiled the application - run 'projAppOneInstance.exe' to see how it works. The application is restored to its last displayed stated, 'normal' or 'maximized'. Sample screens shots:

App 'Started'

App 'Restored'

Download VB 6 Source Code

Click here to download the VB 6 source code [26k]

Previous Tip   Tip Index    Next Tip


Updated 2009/05/03