views:

389

answers:

2

In a .Net application that flashes the title bar and the corresponding taskbar button for a window, to attract the users' attention, P/Invoke code something like this is used:

[DllImport("user32.dll")]
private static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

public static void FlashWindow(System.Windows.Forms.Form window)
{
  FlashWindow(window.Handle, false);
}

How can the same effect be triggered without using P/Invokes? Specifically, the .Net application is being updated to run fully on Linux/Mac OS X with Mono. Is there any way to construct a managed equivalent to FlashWindow or FlashWindowEx?

+1  A: 

You should note that MicroSoft's own UI guidelines suggest that you should not do this unless the event really does require immediate attention.

Don't flash the taskbar button if the only thing the user has to do is activate the program, read a message, or see a change in status.

It is strongly advisable, even within a cross platform app, that the current system's UI guidelines are followed.
In this case it depends what you are trying to do but taking a guess:

If you really do want to do the equivalent of the Flashing window icon the equivalent on OS X would be a bouncing dock icon (Again, people don't like this). I don't know if that is wrapped by cocoa#.

In Linux the behaviour is again fragmented since many frameworks simply don't have the taskbar concept and you would be expected to play nicely with whatever framework you were in.

ShuggyCoUk
Thanks. Your answer is absolutely correct, but following usability testing we *really* do want to use "FlashWindow" (or an equivalent). We aren't using this as a notification that something happened, but as an indicator of *where* it happened.To be honest, we haven't really thought much about MacOS X yet. However, we don't expect to know whether our customer is using .Net or Mono so, initially at least, we want to ship a single application that works equally with both.If the answer to my question is "it can't be done," then that is fine - but if it can be done, that's what I want to do!
Stewart
I would imagine that using a combination of cocoa# and some spelunking you can achieve a dock bounce. here's a pointer to how you might do it in java http://lists.apple.com/archives/Java-dev/2003/Dec/msg00783.html I would imagine doinging it in coco# is similar.My GUI experience on linux is minimal so I wouldn't know where to start but the HIG for Gnome: http://library.gnome.org/devel/hig-book/stable/ and KDE: http://developer.kde.org/documentation/design/ui/
ShuggyCoUk
wrong link for KDE sorry should be: http://developer.kde.org/documentation/standards/kde/style/basics/index.html
ShuggyCoUk
anyone going to indicate why the -1?
ShuggyCoUk
+1  A: 

There is no managed equivalent for what you wish to do. Without getting into the debate of whether or not this is a good idea, a couple ideas come to mind, none of which are as elegant and simple as the FlashWindow call.

  1. Use a timer to toggle the visibility of the form. This will have to effect of completely adding/removing the form from the task bar, but it will be noticed.

  2. Use a timer to toggle the window state (minimized/normal) of the form. This will also get you noticed, but perhaps not in a good way.

  3. Create a separate, blank form with ShowInTaskbar set to false and an opacity of 0. Then use a timer to alternately activate the blank form and the main form. This will have the effect of flashing the title bar of the main form, but will not effect the taskbar representation since another application is not gaining input focus.

DISCLAIMER: I have no idea how these will work on non-Windows OS'es, but am merely offering them up in the interest of managed alternatives.

Michael McCloskey
We had thought about ideas like your (1) and (2), but neither is ideal! (3) doesn't do precisely what I want, but it has inspired a possible solution I will test. I know the currently active form in our application (if our application is not focused at all, then the user doesn't care - and therefore we don't need to do anything) so we can probably alternately activate the "Flashing" form and the user's active form. I hope that there are no side-effects...
Stewart