|
-
October 29th, 2009, 08:52 AM
#1
Set another application focus
Hi,
I'm try to set another application, outside myapplication, as focused window.
Can someone gimmy some help? I've allready tryed something like this
System.Diagnostics.Process.GetProcessesByName("notepad");
I don't start the application in myapplication so I can't set a handle to it.
Greetz Otto
Give up your guns and face the law!!
-
October 29th, 2009, 01:22 PM
#2
Re: Set another application focus
Get the hWnd to the app's top level window and pinvoke to SetForegroundWindow.
-
October 30th, 2009, 03:17 AM
#3
Re: Set another application focus
Thanks, I worked it all out.
//Import the SetForeground API to activate it
[DllImport("User32.dll")]
private static extern IntPtr SetForegroundWindow(int hWnd);
public MyProjectFunctions()
{
}
public void SetWindowFocus(string processName)
{
Process[] pname = Process.GetProcessesByName(processName);
if (pname.Length > 0)
{
foreach (Process processes in pname)
{
if (processes.ProcessName.Equals(processName))
{
SetForegroundWindow((int)processes.MainWindowHandle);
}
}
}
}
Give up your guns and face the law!!
-
October 30th, 2009, 07:49 AM
#4
Re: Set another application focus
Just to add my 2 cents.
For some inexplicable reason I have had problems with using only SetForeGroundWindow. I also then made use of the BringWindowToTop API, which assisted in bringing the necessary window to the front.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|