Windows 7-style Notification Area Applications in WPF: Part 3 (Taskbar Position)

View source on GitHub.

In the previous post in this series, I showed how to find the location of a notify icon by implementing the new Windows 7 Shell32.dll function Shell_NotifyIconGetRect in managed code for use with the System.Windows.Forms.NotifyIcon class.

In this post, I will look at how to accurately position a window above (or adjacent to) a notify icon, no matter the location of the taskbar (barring a certain issue that I note at the end of this post :)). As I noted in Part 2, the current version of Keiki is hardcoded to appear in the bottom right-hand corner of the user’s screen, making it very out of place when the taskbar is moved to the top/right/left of the screen. We’ll need to delve into the Win32 API once again, but as in Part 2 the amount of code required is not daunting, even for a Win32 beginner like me.

Continue reading “Windows 7-style Notification Area Applications in WPF: Part 3 (Taskbar Position)”

Windows 7-style Notification Area Applications in WPF: Part 2 (Notify Icon Position)

View source on GitHub.

You may have noticed that the notification area applications in Windows 7 (Volume/Power/Network/Action Centre) appear centred above their icon. I wanted Keiki to do the same; the current version is hardcoded to sit in the bottom right of the screen, which causes a few problems:

  1. The taskbar position is not taken into account; the window will be in the bottom right even if the taskbar is at the top of the screen.
  2. The window appears on top of the new Windows 7 fly-out interface for hiding notify icons if the Keiki icon is kept there.

In this post, I will demonstrate how to retrieve the location of a System.Windows.Forms.NotifyIcon with a function new to shell32.dll in Windows 7: Shell_NotifyIconGetRect. Windows Vista unfortunately lacks this function: I will cover the approach I use in Vista in a later post.

Thanks to Frédéric Hamidi for pointing me in the right direction.

Continue reading “Windows 7-style Notification Area Applications in WPF: Part 2 (Notify Icon Position)”

Windows 7-style Notification Area Applications in WPF: Part 1 (Removing Resize)

View source on GitHub.

Keiki, my OptusNet Usage Meter, is designed to sit in the notification area (or system tray, if you prefer) and behave similarly to the default system ‘applets’ (Volume/Network/Action Centre/Power). That is, the application becomes visible with a single left click on the notify (tray) icon, and is hidden again when focus is lost.Notification Area

I have recently started to refactor Keiki’s code, as I have learnt a lot about WPF since I first wrote the application. While refactoring I’ve also tried to polish a few rough edges: one of these is the main window’s resize behaviour. The Windows 7 (and Vista before it) tray applications (excuse the ever-changing terminology) have no title bar and are not resizable. It turns out that this window style isn’t trivial to implement with WPF.

Updated: improved code to focus application when border is clicked.

Continue reading “Windows 7-style Notification Area Applications in WPF: Part 1 (Removing Resize)”