How to force running VB app to the foreground? 
Author Message
 How to force running VB app to the foreground?

Using VB6 enterprise

In Sub Main() I check that a previous instance of the app is not running. If it is I display an
error message telling that only one instance can be run.

i.e

    If App.PrevInstance Then
        MsgBox "Only one instance of this application can be run at any time!"
        End
    End If

I would like to make this existing instance of the app the current application instead of displaying
this error!!

Any ideas?

Thanks

Adrian Harrison



Fri, 02 Nov 2001 03:00:00 GMT  
 How to force running VB app to the foreground?
How about using get WinAPI function FindWindow in concert with
GetWindowThreadProcessId to return the task ID of the other instance,
and then using AppActivate (a vb command)?  You might want to also use
GetCurrentProcessID and check against it to avoid just activating the
same window you are currently running.

-Jake Jaffe

Quote:

> Using VB6 enterprise

> In Sub Main() I check that a previous instance of the app is not running. If it is I display an
> error message telling that only one instance can be run.

> i.e

>     If App.PrevInstance Then
>         MsgBox "Only one instance of this application can be run at any time!"
>         End
>     End If

> I would like to make this existing instance of the app the current application instead of displaying
> this error!!

> Any ideas?

> Thanks

> Adrian Harrison

       The contents of this message express only the sender's opinion.
       This message does not necessarily reflect the policy or views of
       my employer, Merck & Co., Inc.  All responsibility for the statements
       made in this Usenet posting resides solely and completely with the
       sender.


Fri, 02 Nov 2001 03:00:00 GMT  
 How to force running VB app to the foreground?
Why bother with handles and API calls - AppActivate will work
with the window title instead. Do it in the form load event or
sub main and it can't activate the new instance - the form doesn't
exist yet.

Quote:

>How about using get WinAPI function FindWindow in concert with
>GetWindowThreadProcessId to return the task ID of the other instance,
>and then using AppActivate (a vb command)?  You might want to also use
>GetCurrentProcessID and check against it to avoid just activating the
>same window you are currently running.

>-Jake Jaffe


>> Using VB6 enterprise

>> In Sub Main() I check that a previous instance of the app is not running. If it is I
display an
>> error message telling that only one instance can be run.

>> i.e

>>     If App.PrevInstance Then
>>         MsgBox "Only one instance of this application can be run at any time!"
>>         End
>>     End If

>> I would like to make this existing instance of the app the current application instead
of displaying
>> this error!!

>> Any ideas?

--
Nigel Worsley

----------------------------------------------------
To reply, replace no.spam with nigle.globalnet.co.uk

The world is flat, and so are hedgehogs
----------------------------------------------------



Fri, 02 Nov 2001 03:00:00 GMT  
 How to force running VB app to the foreground?
There are several articles in the MSDN and the Microsoft Knowledge base that
demonstrate how to iterate or get a list of all running windows (forms).
You can then use the API function GetWindowText to retrieve the caption of
each window.
When you find the window you are looking for, pass the hWnd (window handle)
of that window to the SetFocus API function or the SetWindowPos API function
to bring it to the foreground.

-Rob

Quote:

>Using VB6 enterprise

>In Sub Main() I check that a previous instance of the app is not running.

If it is I display an
Quote:
>error message telling that only one instance can be run.

>i.e

>    If App.PrevInstance Then
>        MsgBox "Only one instance of this application can be run at any
time!"
>        End
>    End If

>I would like to make this existing instance of the app the current

application instead of displaying
Quote:
>this error!!

>Any ideas?

>Thanks

>Adrian Harrison



Fri, 02 Nov 2001 03:00:00 GMT  
 How to force running VB app to the foreground?
You can try this:
Dim hWnd as long
If App.PrevInstance then
     hWnd = FindWindow(0&, "MyWindow")
     if hWnd Then
             SetForegroundWindow(hWnd)
     End if
End if

or instead of calling FindWindow, the harder way would be to create a
callback function and call:
Call EnumWindows(addressof myProc, 0&0)
and provide a function such as
Sub myProc(hWnd as long, lParam as long)
      Dim buffer as string * 1024
      Dim sText as string
      Dim lSize as long
      lSize = GetWindowText(hWnd, buffer)
      sText = Left(buffer, lSize)
      if StrComp (sText, "MyWindow") = 0 then
             SetForegroundWindow(hWnd)
      End if
End Sub

Good Luck

Quote:

>Using VB6 enterprise

>In Sub Main() I check that a previous instance of the app is not running.

If it is I display an
Quote:
>error message telling that only one instance can be run.

>i.e

>    If App.PrevInstance Then
>        MsgBox "Only one instance of this application can be run at any
time!"
>        End
>    End If

>I would like to make this existing instance of the app the current

application instead of displaying
Quote:
>this error!!

>Any ideas?

>Thanks

>Adrian Harrison



Sun, 04 Nov 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to force running VB app to the foreground?

2. How to force running VB app to the foreground?

3. How to force running VB app to the foreground?

4. Force Web Browser to load Word document in foreground

5. Question about keeping VB apps in foreground

6. Forcing msgbox to foreground

7. Force foreground a runtime-added control

8. VB app foreground processing while in tray

9. VB app hangs - any way to force return??

10. running DOS PROgram from VB APP using variables in the app

11. Warning message when creating Excel object from Vb App when app is running as a service

12. Run VB app directly from CD without running setup

 

 
Powered by phpBB® Forum Software