Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #1607 > unrolled thread
| Started by | -mhd <not_real@invalid.com> |
|---|---|
| First post | 2012-10-13 21:30 -0400 |
| Last post | 2012-10-17 12:24 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.basic.visual.misc
Handling second instance works in IDE but not when compiled -mhd <not_real@invalid.com> - 2012-10-13 21:30 -0400
Re: Handling second instance works in IDE but not when compiled Deanna Earley <dee.earley@icode.co.uk> - 2012-10-15 10:09 +0100
Re: Handling second instance works in IDE but not when compiled BeeJ <nospam@spamnot.com> - 2012-10-17 12:24 -0700
| From | -mhd <not_real@invalid.com> |
|---|---|
| Date | 2012-10-13 21:30 -0400 |
| Subject | Handling second instance works in IDE but not when compiled |
| Message-ID | <ct4k78lk04bsi7elbill37af55flj55it4@4ax.com> |
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
[toc] | [next] | [standalone]
| From | Deanna Earley <dee.earley@icode.co.uk> |
|---|---|
| Date | 2012-10-15 10:09 +0100 |
| Message-ID | <k5gjs9$fig$1@speranza.aioe.org> |
| In reply to | #1607 |
On 14/10/2012 02:30, -mhd wrote: > 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 (dee.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.)
[toc] | [prev] | [next] | [standalone]
| From | BeeJ <nospam@spamnot.com> |
|---|---|
| Date | 2012-10-17 12:24 -0700 |
| Message-ID | <op.wmb77q2pek1mal@lapkat7> |
| In reply to | #1607 |
On Sat, 13 Oct 2012 18:30:34 -0700, -mhd <not_real@invalid.com> wrote: > 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/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.basic.visual.misc
csiph-web