我有一个启动另一个应用程序的WPF应用程序,我希望我的应用程序更改第二个应用程序的Icon。我可以使用GetWindowText
和SetWindowText
来更改标题。是否也可以为Icon执行此操作?
更新
我无法控制第二个应用。
答案 0 :(得分:7)
更改其他应用程序的窗口标题:
Win32 API函数和常量的定义:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int message, int wParam, IntPtr lParam);
private const int WM_SETICON = 0x80;
private const int ICON_SMALL = 0;
private const int ICON_BIG = 1;
用法:
Process process = Process.Start("notepad");
// If you have just started a process and want to use its main window handle,
// consider using the WaitForInputIdle method to allow the process to finish starting,
// ensuring that the main window handle has been created.
// Otherwise, an exception will be thrown.
process.WaitForInputIdle();
SetWindowText(process.MainWindowHandle, "Hello!");
Icon icon = new Icon(@"C:\Icon\File\Path.ico");
SendMessage(process.MainWindowHandle, WM_SETICON, ICON_BIG, icon.Handle);
答案 1 :(得分:-1)
在Windows窗体中,您将使用
Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
this.Icon = ico;
所以我猜测WPF会是类似的。