Unable to Rename Window Title Text Via SetWindowText Function
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.
The problem may occur because Firefox, google, IE work in few processes to isolate different pages from each other, so if one tab crashes, the other will still alive. Open Windows Task Manager to ensure. (Opera is still dont but thes feature is already planned for future releases). Possible solution for you is to enumerate all processes with name 'firefox.exe' for instance and change window titles of windows that match some of your criteria.
精彩评论