I am using SetWindowText Function to rename Window Title it seems to work with Windows program like "notepad" but when trying with other 3rd party program its not working.I am grabbing window handle via Process..MainWindowHandle . I want to spawn firefox and rename its window title this is my requirement.Process is getting launched but Window Title rename is not happening i am getting "Send Error Report" Dialog window.Please Help me out.Below is the code.
using System;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Threading;
using System.Diagnostics;
namespace SampleNamespace
{
public class SampleClass
{
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
public static void Main()
{
Process p = Process.Start("C:\\Sham\\pg\\Firefox\\firefox.exe");
Thread.Sleep(1000);
SetWindowText(p.MainWindowHandle, "FireFox via Process-Start");
} // End of Main function (program statup)
}
}
Many programs set their main window titles repeatedly during their execution.
A good example is Firefox which changes its main window title whenever you browse to a new page. Likewise Notepad will change its main window title whenever you open or save a file to include the name of the latest file.
The only way you can realistically expect to exert control like this is to poll.