NotificationIcon Sample

Demonstrates how to use the Shell_NotifyIcon and Shell_NotifyIconGetRect APIs to display a notification icon.

This topic contains the following sections.

Description

In addition to the use of Shell_NotifyIcon and Shell_NotifyIconGetRect to display a notification icon, this sample also demonstrates how to display a rich flyout window, context menu, and balloon notification.

Note

Shell_NotifyIconGetRect is only available on Windows 7 and later versions.

 

Requirements

Product Minimum Product Version
Windows Windows 7
Windows Software Development Kit (SDK) 7.0

 

Downloading the Sample

Location Path URL
GitHub NotificationIcon sample

Building the Sample

To build the sample from the command prompt:

  1. Open the command prompt window and navigate to the NotificationIcon project directory.
  2. Enter msbuild NotificationIcon.sln.

To build the sample using Microsoft Visual Studio (preferred):

  1. Open Windows Explorer and navigate to the NotificationIcon project directory.
  2. Double-click the icon for the NotificationIcon.sln file to open the project in Visual Studio.
  3. From the Build menu, select Build Solution.

Running the Sample

  1. Navigate to the directory that contains the new executable, using the command prompt or Windows Explorer.
  2. At the command line, enter NotificationIcon.exe. Alternatively, from Windows Explorer double-click the icon for NotificationIcon.exe.

Note

Notification icons specified with a GUID are protected against spoofing by validating that only a single application registers them. This registration is performed the first time you call Shell_NotifyIcon(NIM_ADD, ...) and the full path name of the calling application is stored. If you later move your binary file to a different location, the system will not allow the icon to be added again. Please see Shell_NotifyIcon for more information.