Hi
I'm trying to use the Windows 7 Taskbar API to set the overlay icon of the application icon on the taskbar.
I've downloaded the samples from Microsoft, but wanted to extract that particular piece of code that does that to avoid adding a reference to a huge brick of code that I won't use most of.
I have a simple WPF app in VS 2010 on Win 7 x64.
Code-behind for my Window1.xaml is like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Interop;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private static ITaskbarList3 _taskbarList;
internal static ITaskbarList3 TaskbarList
{
get
{
if (_taskbarList == null)
{
if (_taskbarList == null)
{
_taskbarList = (ITaskbarList3)new CTaskbarList();
_taskbarList.HrInit();
}
}
return _taskbarList;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TaskbarList.SetOverlayIcon(new WindowInteropHelper(Application.Current.MainWindow).Handle, SystemIcons.Question.Handle, "Test");
}
}
[ComImportAttribute()]
[GuidAttribute("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ITaskbarList3
{
// ITaskbarList
[PreserveSig]
void HrInit();
[PreserveSig]
void AddTab(IntPtr hwnd);
[PreserveSig]
void DeleteTab(IntPtr hwnd);
[PreserveSig]
void ActivateTab(IntPtr hwnd);
[PreserveSig]
void SetActiveAlt(IntPtr hwnd);
void SetOverlayIcon(
IntPtr hwnd,
IntPtr hIcon,
[MarshalAs(UnmanagedType.LPWStr)] string pszDescription);
}
[GuidAttribute("56FDF344-FD6D-11d0-958A-006097C9A090")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComImportAttribute()]
internal class CTaskbarList { }
}
When I click the button, nothing happens. No error. Icon doesn't change.
I wonder if I'm passing the correct handle to the SetOverlayIcon method.
Anyone know how to fix this?