|
-
Jan 4th, 2004, 12:33 AM
#1
App.PrevInstance [resolved]
OK, I have 2 forms, the main one I want it to show only once, and the other as many times as you run the program, but it always showing either one or the other (in the same instance).
The problem with the next code is that when I run the program with a command i.e. the frmRestore is showing, the next time I run the program without the command, the main form does not show up, and I want it to because there is no previous instance of the main form.
If I do it the other way around, then it works. If I close all instances of my program, run it without a command, then run it with a command, then it works.... get it ?
VB Code:
Private Sub Form_Load()
If Command <> "" Then
Load frmRestore
Unload Me
Exit Sub
End If
If App.PrevInstance Then End
End Sub
Reading what I wrote, it still seems a bit confuzing. I'll try another way...
So... I have 2 forms, main form and frmRestore, when I run the program more than once, I want the main form to show only once, but the frmRestore more than once, and it should not matter in witch order I run them, main form should always be once...
Last edited by CVMichael; Jan 4th, 2004 at 02:21 AM.
-
Jan 4th, 2004, 02:06 AM
#2
Addicted Member
Could you make two different apps? Then each app would of course have its own App.PrevInstance. If the main form wants to load up and it's already loaded it could just shut down, regardless if the frmRestore is loaded. If you pass it a command it could just shell the frmRestore program.
I hope I understood your question correctly.
-
Jan 4th, 2004, 02:10 AM
#3
The program is ~6000 lines, and both forms have a lot of common code, making 2 apps would create a lot of problems.
-
Jan 4th, 2004, 02:19 AM
#4
I fixed the problem using some APIs...
VB Code:
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Private Declare Function GlobalFindAtom Lib "kernel32" Alias "GlobalFindAtomA" (ByVal lpString As String) As Integer
Private Const MyAtomName As String = "MyApp12345"
Private CurrAtom As Integer
Private Sub Form_Load()
Dim Atom As Integer
If Command <> "" Then
Load frmRestore
Exit Sub
End If
If App.PrevInstance Then
Atom = GlobalFindAtom(MyAtomName)
If Atom = 0 Then
CurrAtom = GlobalAddAtom(MyAtomName)
Else
End
End If
Else
CurrAtom = GlobalAddAtom(MyAtomName)
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
GlobalDeleteAtom CurrAtom
End Sub
Last edited by CVMichael; Jan 4th, 2004 at 02:40 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|