I have the following code which draws a square on the main window of another process:
private void DrawOnWindow(string processname)
{
IntPtr winhandle = GetWindowHandle(processname);
Graphics grph = Graphics.FromHwnd(winhandle);
grph.DrawRectangle(Pens.Red, 10, 10, 100, 100);
}
private IntPtr GetWindowHandle(string windowName)
{
IntPtr windowHandle = IntPtr.Zero;
Process[] processes = Process.GetProcessesByName(windowName);
if (processes.Length > 0)
{
for (int i = 0; i < processes.Length; i++)
{
if (processes[i].MainWindowHandle.ToInt32() > 0)
{
windowHandle = processes[i].MainWindowHandle;
break;
}
}
}
return windowHandle;
}
This works when I pass "firefox" to the DrawOnWindow method, but it does not work when I pass "iexplore" and I don't understand why. What do I need to do to get this to work on internet explorer? (IE8)