作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个启动另一个应用程序的 WPF 应用程序,我想让我的应用程序更改第二个应用程序的图标。我可以使用 GetWindowText
和 SetWindowText
来更改标题。 Icon 也可以这样做吗?
更新
我无法控制第二个应用。
最佳答案
更改另一个应用程序的窗口标题:
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);
关于c# - 有没有办法让我的应用程序将其图标推送到其他应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9199523/
我是一名优秀的程序员,十分优秀!