Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21264

Open several files using Command

$
0
0
Goodmorning :)

I have built a program of which I wish only one instance opened at time. To do this, I used Mutex and related API calls:
Code:

Function Is2ndInstance() As Boolean
    Dim hMutex As Long

    hMutex = CreateMutex(ByVal 0&, 1, App.Title)
    If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
        Is2ndInstance = True
        ReleaseMutex hMutex
        CloseHandle hMutex
    End If
End Function

Private Sub Form_Load()
    If Is2ndInstance Then End
    If Command <> "" Then
      'Code to open file
    End If
End Sub

Now there's my problem...

I'm trying to give user the possibility to open files simply clicking on them and use the path stored into Command function to load them into my application. The first time user tries to open a file, it is successfully opened. But if he tries again, the Mutex doesn't allow and closes the second instance of the program without opening the file chosen.

What can I do to open all files into the same instance of my application (avoiding my program is opened twice or more) ? Moreover I succeeded to use Command only if I select what program I want to open the file with (using the Open As... option in the contex Menu). In fact, the double click on the file didn't make anything useful. Why?

Thank you all.
:wave:

Viewing all articles
Browse latest Browse all 21264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>