11-20-2000, 10:32 AM
Is there any way to limit how many instances of a program (multiple windows) that are opened at any given time. For example, say the user has one Internet Explorer window opened, and then tries to open a second one......how can I prevent the user from opening another one, yet leave the first one alone?
I'm using VB5.
12-03-2000, 10:43 PM
I would search the API for a similar function as VB's "PrevInstance" property of the "APP" funtion. If you're unfamiliar with this open a program and type the following code:
If App.PrevInstance Then
MsgBox "This program is already open"
Keep in mind though that this would only work if your VB was creating an instance of IE from within the application itself, not if you simply open IE two separate times...in which case I think there is a similar API function to PrevInstance...
12-31-2000, 01:05 AM
how screensavers do it is put this in the form load event of your startup form
If App.PrevInstance=true then end
that way it will shut down if one is already running.<P ID="edit"><FONT SIZE=-1><EM>Edited by Ryan231 on 12/31/00 02:18 AM (server time).</EM></FONT></P>
01-01-2001, 01:39 AM
By the way, it is preferrable to put the above mentioned
code not into Form1_Load(), but into
Form1_Initialize() Event, because it will be performed faster.
01-01-2001, 05:49 PM
Guys, what rcody is asking is how to prevent multiple instances of other apps, not the one he is making...
previnstance would NOT work when trying to control other programs instances... what you would probably have to do is use a timer and use API to check how many windows are open... if more than one...then close one... this won't let the user do anything on the second Internet explorer or whatever because it'll close it right away.
This is probrely COMPLETELY wrong but I'll give it a wrill. Try:
Private sub cmdOpenBrowser_Click()
If frmBrowser >=1 Then
Msgbox "Sorry browser already opened",VbExclamation,"Browser1"
It's a guess but, I hope it works.