gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:55:51 26 4
gpt4 key购买 nike

我有一个启动另一个应用程序的 WPF 应用程序,我想让我的应用程序更改第二个应用程序的图标。我可以使用 GetWindowTextSetWindowText 来更改标题。 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com