473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Bring To Front of a Process/Other application

Hi,

I want my application to bring another application to the Front.

I thought best way to do this was by the Process-model:
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = "Appl" Then
'Here I should be able to Bring the Process to the Front!!!
Exit Function
End If
Next p

Does anybody nows how to do this? Or another solution?

Thanks!

Pieter
Nov 20 '05 #1
9 21553
Windows Forms Tips and Tricks explains how to maintain a single instance of
an application and bring it to the front when it's activated.

http://www.bobpowell.net/tipstricks.htm
--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Hi,

I want my application to bring another application to the Front.

I thought best way to do this was by the Process-model:
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = "Appl" Then
'Here I should be able to Bring the Process to the Front!!! Exit Function
End If
Next p

Does anybody nows how to do this? Or another solution?

Thanks!

Pieter

Nov 20 '05 #2
Thanks!

I just found it myself like this:

Dim handle As IntPtr = prcSiclid.MainWindowHandle
Dim Win32Help As New Win32Helper
If Not IntPtr.Zero.Equals(handle) Then
Win32Helper.ShowWindow(handle, 1)
Win32Helper.SetForegroundWindow(handle)
End If

Public NotInheritable Class Win32Helper
<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function _
SetForegroundWindow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function ShowWindow(ByVal handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
' Leave function empty
End Function

End Class ' End Win32Helper
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uo*************@TK2MSFTNGP10.phx.gbl...
Windows Forms Tips and Tricks explains how to maintain a single instance of an application and bring it to the front when it's activated.

http://www.bobpowell.net/tipstricks.htm
--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
Hi,

I want my application to bring another application to the Front.

I thought best way to do this was by the Process-model:
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = "Appl" Then
'Here I should be able to Bring the Process to the

Front!!!
Exit Function
End If
Next p

Does anybody nows how to do this? Or another solution?

Thanks!

Pieter


Nov 20 '05 #3
Hi Pieter,

I don't know, I did not really check everything you wrote, however did you
look already to the forms TopMost property?

Cor
Nov 20 '05 #4
TopMost works in the application itself, but I don't think you can use it to
put another appliation on Top.
Even in the application itself TopMost doesn't always work fine. But the
"SetForegroundWindow" works always :-)

Thansk anyways :-)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uW**************@TK2MSFTNGP12.phx.gbl...
Hi Pieter,

I don't know, I did not really check everything you wrote, however did you
look already to the forms TopMost property?

Cor

Nov 20 '05 #5
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I don't know, I did not really check everything you wrote, however did you
look already to the forms TopMost property?


This will make the window stay "always on top".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
* "DraguVaso" <pi**********@hotmail.com> scripsit:
I want my application to bring another application to the Front.

I thought best way to do this was by the Process-model:
Dim c As Process = Process.GetCurrentProcess()
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = "Appl" Then
'Here I should be able to Bring the Process to the Front!!!
Exit Function
End If
Next p

Does anybody nows how to do this? Or another solution?


'AppActivate'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
I tried Bob's C# code in his "Only one instance of an application"
article.
It didn't work for me in Windows 2000.

I then tried to email you about it Bob, but you are running FrontPage
extensions on your site, which didn't work for me. Presumably my
company firewall doesn't like them. Why you need FrontPage extensions
to handle a simple form is beyond me.

I am still looking for a solution to this problem. All I have found
on the net so far are solutions which don't work reliably, or guesses
from people (even Microsofties) who haven't tried what they are
suggesting.

Don't know if the barrier is .net, or Win2K/XP. I suspect the latter.

Ken.
Nov 20 '05 #8
I tried Bob's C# code in his "Only one instance of an application"
article.
It didn't work for me in Windows 2000.

I then tried to email you about it Bob, but you are running FrontPage
extensions on your site, which didn't work for me. Presumably my
company firewall doesn't like them. Why you need FrontPage extensions
to handle a simple form is beyond me.

I am still looking for a solution to this problem. All I have found
on the net so far are solutions which don't work reliably, or guesses
from people (even Microsofties) who haven't tried what they are
suggesting.

Don't know if the barrier is .net, or Win2K/XP. I suspect the latter.

Ken.
Nov 20 '05 #9
Hi,

I used this to bring another application to the Front:

Hope this helps,

Pieter

Public Sub BringExtraToFront()
Dim prc As Process
Dim clsProc As New clsProcesses
prc = clsProc.ProcessExtra 'gets me the
process based on the name
Dim handle As IntPtr = prc.MainWindowHandle
Dim Win32Help As New Win32Helper
If Not IntPtr.Zero.Equals(handle) Then
Win32Helper.ShowWindow(handle, 1)
Win32Helper.SetForegroundWindow(handle)
End If
End Sub
Option Explicit On

Public Class clsProcesses

Public Shared Function PrevInstance() As Process
Dim c As Process = Process.GetCurrentProcess()

' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProcessesByName(c.ProcessName)

' Aktuellen Prozess nicht beachten.
If p.Id <> c.Id Then

' Es kann mehrere Prozesse gleichen Namens geben, die von
' unterschiedlichen Programmen stammen.
If p.MainModule.FileName = c.MainModule.FileName Then

' Prozess der ersten gefundenen anderen Instanz
' zurückgeben.
Return p
End If
End If
Next p

' Keine andere Instanz gefunden.
Return Nothing
End Function

Public Shared Function ExtraOpen() As Boolean
' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = SessionName Then
Return True
Exit Function
End If
Next p
Return False
End Function

Public Shared Function ProcessExtra() As Process
' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProcessesByName("EXTRA")
If Left(p.MainWindowTitle, 4) = SessionName Then
Return p
Exit Function
End If
Next p
Return Nothing
End Function

Public Sub New()
'error-handler die alle errors voor zn rekening neemt
AddHandler System.Windows.Forms.Application.ThreadException,
AddressOf GlobalErrorHandler
End Sub
End Class

Public NotInheritable Class Win32Helper
<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function _
SetForegroundWindow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function ShowWindow(ByVal handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
' Leave function empty
End Function

End Class ' End Win32Helper

"Ken Wagnitz" <kw******@bigfoot.com> wrote in message
news:21*************************@posting.google.co m...
I tried Bob's C# code in his "Only one instance of an application"
article.
It didn't work for me in Windows 2000.

I then tried to email you about it Bob, but you are running FrontPage
extensions on your site, which didn't work for me. Presumably my
company firewall doesn't like them. Why you need FrontPage extensions
to handle a simple form is beyond me.

I am still looking for a solution to this problem. All I have found
on the net so far are solutions which don't work reliably, or guesses
from people (even Microsofties) who haven't tried what they are
suggesting.

Don't know if the barrier is .net, or Win2K/XP. I suspect the latter.

Ken.

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Charles A. Lackman | last post by:
Hello, I have created an application that searches to see if a process is running and if it is it maximizes it's window. i.e. For Each AProcess In AProcesses If...
7
by: tom | last post by:
Hi, I want a listbox below a hidden calendar control. The problem is that the listbox will shadow the calendar when the calendar is visible. How can I bring the calendar from back to front? ...
3
by: DraguVaso | last post by:
Hi, My application has some interaction with an other application. I sometimes need to put the other application to the front. The problem is that I'm not able to get a nice solution to work in...
2
by: Don | last post by:
I have two programs. One is supposed to bring the other (which is already running either minimized or at the bottom of the window z-order) to the front so that it becomes the foremost application....
0
by: pavan377 | last post by:
Hi folks, I got a requirement in my project where in when my application is activated another window should get activated and upon it my application should be present. Both should be in restored...
5
by: Anns via AccessMonster.com | last post by:
My establishment has about 20 ms access db's that will be converted over (see subject). When we pull all the BE's over to SQL and the FE's on Sharepoint (.net) surely we don't have to change...
3
by: M O J O | last post by:
Hi, I have an application where I've implemented a global hotkey, so no matter what other application is in front (have focus), my app will react when the key combination is pressed. This works...
1
by: Marcel Brekelmans | last post by:
Hello, I have an application with a notifyIcon. When my application's main form is hidden by some other window I would like to bring it in front by single-clicking the NotifyIcon. However, I...
2
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I asked here yesterday about bringing a form to front with hotkey while using different application then mine (meaning, when i'm using outlook, and pressing ALT+T it will bring a form from...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.