473,545 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetCurr entProcess()
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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 21600
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**********@h otmail.com> wrote in message
news:O3******** ******@TK2MSFTN GP09.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.GetCurr entProcess()
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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.MainW indowHandle
Dim Win32Help As New Win32Helper
If Not IntPtr.Zero.Equ als(handle) Then
Win32Helper.Sho wWindow(handle, 1)
Win32Helper.Set ForegroundWindo w(handle)
End If

Public NotInheritable Class Win32Helper
<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Se tForegroundWind ow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function _
SetForegroundWi ndow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Sh owWindow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function ShowWindow(ByVa l handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
' Leave function empty
End Function

End Class ' End Win32Helper
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:uo******** *****@TK2MSFTNG P10.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**********@h otmail.com> wrote in message
news:O3******** ******@TK2MSFTN GP09.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.GetCurr entProcess()
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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
"SetForegroundW indow" works always :-)

Thansk anyways :-)

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uW******** ******@TK2MSFTN GP12.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**********@p lanet.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**********@h otmail.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.GetCurr entProcess()
Dim p As Process
For Each p In Process.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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 BringExtraToFro nt()
Dim prc As Process
Dim clsProc As New clsProcesses
prc = clsProc.Process Extra 'gets me the
process based on the name
Dim handle As IntPtr = prc.MainWindowH andle
Dim Win32Help As New Win32Helper
If Not IntPtr.Zero.Equ als(handle) Then
Win32Helper.Sho wWindow(handle, 1)
Win32Helper.Set ForegroundWindo w(handle)
End If
End Sub
Option Explicit On

Public Class clsProcesses

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

' Durchlaufen aller Prozesse mit gleichem Namen.
Dim p As Process
For Each p In Process.GetProc essesByName(c.P rocessName)

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

' Es kann mehrere Prozesse gleichen Namens geben, die von
' unterschiedlich en Programmen stammen.
If p.MainModule.Fi leName = c.MainModule.Fi leName 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.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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.GetProc essesByName("EX TRA")
If Left(p.MainWind owTitle, 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.Applicati on.ThreadExcept ion,
AddressOf GlobalErrorHand ler
End Sub
End Class

Public NotInheritable Class Win32Helper
<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Se tForegroundWind ow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function _
SetForegroundWi ndow(ByVal handle As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime .InteropService s.DllImport("us er32.dll", _
EntryPoint:="Sh owWindow", _
CallingConventi on:=Runtime.Int eropServices.Ca llingConvention .StdCall, _
CharSet:=Runtim e.InteropServic es.CharSet.Unic ode, SetLastError:=T rue)> _
Public Shared Function ShowWindow(ByVa l handle As IntPtr, _
ByVal nCmd As Int32) As Boolean
' Leave function empty
End Function

End Class ' End Win32Helper

"Ken Wagnitz" <kw******@bigfo ot.com> wrote in message
news:21******** *************** **@posting.goog le.com...
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
2480
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 AProcess.StartInfo.WindowStyle <> ProcessWindowStyle.Maximized Then AProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
7
11082
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? Thanks in advance.
3
7814
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 every case. I tryed two ways: one way it disn't maximazi the Windowd when it was Minimized, in the other way it resized the application when it was...
2
4928
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. How do you do this? I've tried using the API functions BringWindowToTop, SetForegroundWindow, and SetWindowPos and can't get any of them to work...
0
1747
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 state not maximised. To accomplish this, in the activated event of my MainForm I first activated the other window and then activated my window. I've...
5
3598
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 every user face, we should be able to use the same FE in as before as now on Sharepoint? ANSWER:
3
4768
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 fine. My problem is now that the form I want to show, does not come to the front. I've tried to set Topmost to true, but then the form doesn't...
1
7282
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 can't get it done. In the Click event I've used all sorts of methods: this.SetTopLevel(true); this.Show(); this.Focus();
2
4061
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 my application to front), my problem was that after i press the hotkey, the window stays in minimize state instead of being in the front. i fount an...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.