Discussion:
Handling second instance works in IDE but not when compiled
(too old to reply)
-mhd
2012-10-14 01:30:34 UTC
Permalink
Normally when I detect a running instance of my prog by using a mutex value, I
just kill the second instance but now I also want to bring the first instance up
to normal state if its minimized.


MutexValue = CreateMutex(ByVal 0&, 1, "MyProgMutex")
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
CloseHandle MutexValue
'Search for Window / Get its Handle
lhwnd = FindWindow(vbNullString, "My Prog Caption")
'If Another Window Found
If lhwnd <> 0 Then
'Activate and Show Window
lRtrn = ShowWindow(lhwnd, SW_SHOWRESTORE)
End If
'this instance exits sub main and dies
Exit Sub
End If

Works just great in the IDE as the first instance pops up from minimized state
and the second one dies.

When compiled the second one dies immediately upon launching as intended but the
first one doesn't pop up.

Any ideas?

-mike
Deanna Earley
2012-10-15 09:09:31 UTC
Permalink
Post by -mhd
Normally when I detect a running instance of my prog by using a mutex value, I
just kill the second instance but now I also want to bring the first instance up
to normal state if its minimized.
MutexValue = CreateMutex(ByVal 0&, 1, "MyProgMutex")
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
CloseHandle MutexValue
'Search for Window / Get its Handle
lhwnd = FindWindow(vbNullString, "My Prog Caption")
'If Another Window Found
If lhwnd <> 0 Then
'Activate and Show Window
lRtrn = ShowWindow(lhwnd, SW_SHOWRESTORE)
End If
'this instance exits sub main and dies
Exit Sub
End If
Works just great in the IDE as the first instance pops up from minimized state
and the second one dies.
When compiled the second one dies immediately upon launching as intended but the
first one doesn't pop up.
Have you checked whether you actually get a valid window handle?
The code above doesn't and exists only on the mutex check, regardless of
whether it found a window or not.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
BeeJ
2012-10-17 19:24:52 UTC
Permalink
Post by -mhd
Normally when I detect a running instance of my prog by using a mutex value, I
just kill the second instance but now I also want to bring the first instance up
to normal state if its minimized.
MutexValue = CreateMutex(ByVal 0&, 1, "MyProgMutex")
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
CloseHandle MutexValue
'Search for Window / Get its Handle
lhwnd = FindWindow(vbNullString, "My Prog Caption")
'If Another Window Found
If lhwnd <> 0 Then
'Activate and Show Window
lRtrn = ShowWindow(lhwnd, SW_SHOWRESTORE)
End If
'this instance exits sub main and dies
Exit Sub
End If
Works just great in the IDE as the first instance pops up from minimized state
and the second one dies.
When compiled the second one dies immediately upon launching as intended but the
first one doesn't pop up.
Any ideas?
-mike
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
Loading...