Is there a way to get my application to click the icon on other applications?

I have a WPF application that launches another application, I would like my application to change the icon of this second application. I can use GetWindowText and SetWindowText to change the name. Is it possible to do this for the icon?

Update

I have no control over the second application.

+4
source share
2 answers

To change the window title of another application:

Win32 API Function and Constant Definitions:

 [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; 

Using:

 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); 
+7
source

On Windows Forms you should use

 Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe"); this.Icon = ico; 

So, I assume it will be similar for WPF.

-1
source

Source: https://habr.com/ru/post/1312044/


All Articles