使用PInvoke更改任务栏图标

时间:2014-11-25 23:24:24

标签: c# pinvoke taskbar

我有一个启动窗口进程的应用程序。我已成功设法更新窗口图标以及使用Alt + Tab时显示的图标:

public class ProcessLauncher {

    ...

    [DllImport("user32.dll")]
    private 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;

    public void LaunchProcess() {

        var process = new Process();
        var startInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = "C:"
            };
        process.StartInfo = startInfo;
        process.Start();

        Thread.Sleep(50);

        var icon = Resources.MyIcon;

        SendMessage(process.MainWindowHandle, WM_SETICON, ICON_BIG, icon.Handle);
        SendMessage(process.MainWindowHandle, WM_SETICON, ICON_SMALL, icon.Handle);
    }

    ...
}

这很好用,但该进程的任务栏图标保持不变。如何更新任务栏图标以匹配我为窗口和Alt + Tab提供的图标?

0 个答案:

没有答案