N
NewbieMahi
Guest
Hi there,
I am trying to bring IE child processes to front using C#. The below code executes, but the action is not completed. Could anyone assist?
//Please mind the coding, conversions and standards. This is edited for public usage.
using System;
using System.Data;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
namespace Porcesses
{
class Program
{
private const int SW_MAXIMIZE = 3;
[DllImport("user32")]
private static extern bool ShowWindow(IntPtr hwnd, int SW_MAXIMIZE);
[DllImport("user32")]
private static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public static void Main(string[] args)
{
IntPtr hWnd;
decimal processId = 21088; //child process ID
DataTable processIds = new DataTable(); //Test purpose
processIds.Columns.Add("Process Name", typeof(string));
processIds.Columns.Add("ID", typeof(decimal));
processIds.Rows.Add("ID", 21088);
foreach (DataRow row in processIds.Rows)
{
if (Convert.ToDecimal(row[1]) == processId)
{
var p = Process.GetProcessById(21088);
hWnd = p.MainWindowHandle;
ShowWindow(hWnd, SW_MAXIMIZE);
SwitchToThisWindow(hWnd, true);
}
}
}
}
}
The following source was helpful, however the issue persists for IE child process cases.
How to Bring an application to front with C#
Please shout if you need more details.
Thanks in advance.
Continue reading...
I am trying to bring IE child processes to front using C#. The below code executes, but the action is not completed. Could anyone assist?
//Please mind the coding, conversions and standards. This is edited for public usage.
using System;
using System.Data;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
namespace Porcesses
{
class Program
{
private const int SW_MAXIMIZE = 3;
[DllImport("user32")]
private static extern bool ShowWindow(IntPtr hwnd, int SW_MAXIMIZE);
[DllImport("user32")]
private static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
public static void Main(string[] args)
{
IntPtr hWnd;
decimal processId = 21088; //child process ID
DataTable processIds = new DataTable(); //Test purpose
processIds.Columns.Add("Process Name", typeof(string));
processIds.Columns.Add("ID", typeof(decimal));
processIds.Rows.Add("ID", 21088);
foreach (DataRow row in processIds.Rows)
{
if (Convert.ToDecimal(row[1]) == processId)
{
var p = Process.GetProcessById(21088);
hWnd = p.MainWindowHandle;
ShowWindow(hWnd, SW_MAXIMIZE);
SwitchToThisWindow(hWnd, true);
}
}
}
}
}
The following source was helpful, however the issue persists for IE child process cases.
How to Bring an application to front with C#
Please shout if you need more details.
Thanks in advance.
Continue reading...