有没有办法让我的应用程序将其图标推送到其他应用程序?

Nat*_*ate 4 c# wpf winapi

我有一个启动另一个应用程序的WPF应用程序,我希望我的应用程序更改第二个应用程序的图标.我可以使用GetWindowTextSetWindowText更改标题.是否可以为Icon执行此操作?

更新

我无法控制第二个应用程序.

Ser*_*nov 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;
Run Code Online (Sandbox Code Playgroud)

用法:

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);
Run Code Online (Sandbox Code Playgroud)