0

I want something like this:

Tray popup
(source: cybernetnews.com)

This window is not resizable, and aligns itself above the system tray icon which it is related to.

I have this:

Tray popup

Which is resizeable, and it goes wherever it feels like. If you click the volume control in Win 7, it always pops up directly above the icon. This is ideal.

I've found this reference which I think is trying to solve the same problem (can't tell though as the images are dead),

but I'm using WPF and I'm not sure how to get these Form objects they refer to from my Window object. This is the XAML declaration of my window at the moment:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="WirelessControl.Window1"
x:Name="Window"
Title="Window1"
Width="260" Height="370" mc:Ignorable="d" WindowStyle="None"></Window>

I feel like based on how common this is in Windows that there must be a fairly easy way to do this.

ResizeMode="NoResize" causes my window border to disappear, so that's no help.

Thanks guys, I hope I was comprehensive enough.

Community
  • 1
  • 1
Mason Blier
  • 140
  • 2
  • 11

3 Answers3

5

You can use Shell_NotifyIconGetRect to retrieve the location of the notification icon. You can then reposition your window to match that location. That's what the volume control UI does. Unfortunately it only works on Win7.

If you need to work on older OS's, you can get the mouse cursor position at the time of the NIN_BALLOONSHOW message - that's what the volume control UI used to do.

Larry Osterman
  • 16,086
  • 32
  • 60
  • I can get the mouse cursor at the time of the icon being clicked also, and I can use modulus for every 24 pixels to approximate the level the icon is at. This seems like such a workaround to reimplement a dialog so common in Windows Vista and 7 however. – Mason Blier Jun 08 '10 at 15:14
  • 1
    That's exactly why the Shell_NotifyIconGetRect API was added in Windows 7 - because it's a common task, they automated it. – Larry Osterman Jun 09 '10 at 01:54
3

I've written a series of posts about doing this (and made a sample project) here: http://blog.quppa.net/2011/01/03/windows-7-style-notification-area-applications-in-wpf-recap-sample/

Topics covered include removing window resize without removing the glass border, finding the position of the notify icon (both with Windows 7 using Shell_NotifyIconGetRect and with earlier versions using a more hacky method), finding the taskbar docking alignment and finding the correct working area when there are multiple screens (monitors) present. Though I didn't really write about it, the sample code includes fallbacks for systems where the DWM (read: Aero) is not enabled (that is, drawing a custom 1 pixel border in the style of the Windows 7 notification area applications).

Quppa
  • 1,841
  • 20
  • 18
0

I have answered a question just like yours in this post

the only problem is that the resize cursers are still visible. I think you can hide them by manuplating the window's message loop.

Community
  • 1
  • 1