Microsoft & .NETVisual BasicTIP: A Better PrevInstance

TIP: A Better PrevInstance

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Moving to 32bit Windows solved a mass of problems but also added some of it’s own. With Win16 everyone had a tip of how to get a minimized app to pop up and take focus.

With 32bit VB we got one built-in choice, the App object’s PrevInstance property. On starting your app, you check this property and if it’s true you could decide to not start a second one. To make the user aware you could pop up a Msgbox. But that’s it out of the VB box… and users think that that does not look professional.

Here’s how to get a real professional startup for your apps. By using one tricky line and making a few API calls you get:

  • Your app’s previous instance to jump to the top of the desktop
  • Your minimized app to restore itself to it’s original dimensions
  • Your app to retake focus

Just download the zip and take a look at the single function frmMDI1_Load(), it has all the notes you need to make it easy to follow along with and easier to use in your own apps.

The tricky caption switch idea came from AliasAce’s September 98 submission to PlanetSourceCode.com on how to completely restrict all added instances and alias instances from loading, we tweaked it to give the umph it really needed, but without AliasAce it would have been back to the normal API horrors to get the same result.

Warning: When working with API calls, even minor ones, there is potential for crashes. Do like the Gamers do "Save Often".

Click here to download the project!

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories