Important alert: (current site time 7/16/2013 1:57:53 AM EDT)
 

winzip icon

[ !] Check for PrevInstance

Email
Submitted on: 4/16/2005 1:20:11 PM
By: Sergio del Rio 
Level: Intermediate
User Rating: By 7 Users
Compatibility: VB 6.0
Views: 18372
author picture
 
     This code checks for a previous instance of the program. This is not like the App.PrevInstance property. This checks the prevInstance no matter the location of the file, or the name of the app. You don't have to call DestroyWindow to destroy the created window, since when you quit the application, it is self destroyed. This may not work in the VB IDE, because the window is created by VB6.EXE. In this case you can call DestroyWindow in the Form_Unload().

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/16/2005 6:03:52 PMSergio del Rio

Please leave comments and vote! -:)

(If this comment was disrespectful, please report it.)

 
4/16/2005 8:06:31 PMCodE Solutions

Great Work! It helps me a lot.....Continue to help PSC and other coders...5 Globes for the nice and very short module.
(If this comment was disrespectful, please report it.)

 
4/17/2005 12:04:43 AMenmity

don't you need to close the created window?
(If this comment was disrespectful, please report it.)

 
4/17/2005 9:59:12 AMTom Pydeski

dim Instance as long
Instance =createwindow(etc....)
then declare destroywindow and
use
destroywindow(Instance)
in form unload
although i was not smart enough to do that BEFORE i ran the code, so now i have that instancecode window that i can't kill....
i need to reboot to test the destroy
(If this comment was disrespectful, please report it.)

 
4/17/2005 11:04:03 AMSergio del Rio

Tom: In fact... No, you don't have to
destroy the window, since it self
destroys when the application is
closed. That doesn't happen in the
Visual Basic IDE, since the window was
created by VB6.EXE, and not from your
application. You can put the DestroyWindow API while you work in the VB IDE.

It will be the same to
put it in Form_Unload() because if the
application is closed by the Task
Manager, Form_Unload wont be called.
(If this comment was disrespectful, please report it.)

 
4/17/2005 11:04:28 AMSergio del Rio

Don't forget to vote! -:)
(If this comment was disrespectful, please report it.)

 
4/17/2005 3:44:26 PMPaul Turcksin

Good thinking! Original and useful post. Thanks for sharing. My @@@@@
(If this comment was disrespectful, please report it.)

 
4/17/2005 4:23:40 PMSergio del Rio

Thanks!
(If this comment was disrespectful, please report it.)

 
4/19/2005 12:11:50 PMIsbat Sakib

Nice idea. 5 from me. Will you see my method? It's on Id: 56211 . But I think this one is simpler.
(If this comment was disrespectful, please report it.)

 
6/9/2005 8:21:27 AM

Nice concise code and very useful - well done and thanks
(If this comment was disrespectful, please report it.)

 
11/29/2006 4:24:51 AM

very usefull code, great job!
keep up good work!
(If this comment was disrespectful, please report it.)

 
6/22/2007 8:42:50 AMMega

Very Nice
(If this comment was disrespectful, please report it.)

 
9/12/2012 8:02:17 AMRon Pitts

This solves the Previous Instance problem, which quit working in modern windows systems. It just works.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.