You need to capture all such events, because I think, Windows Hook API does not give you other options. But, in handling of this event, you need to discriminate the further action by the coordinates of the click. Just do nothing if the click goes out of the clipping area of your notification icon application. A little problem will be only passing right rectangle extents to the code handling the hooks. As the hook needs to be in the native DLL, to be global, and because the hook event is handled in some different thread, this would be a matter of IPC.
However, I suspect things are much easier in fact. I do understand it you need to setup a global Windows Hook to activate your application on some keyboard sequence, because at this moment you don't know what application window is activated and what control is in focus. I don't understand why would you need a Hook (any one, global or not) to handle this mouse click. If you click in the notification area, the click even will already be dispatched in your application, you only need to handle in a usual way, and it's simper than you wrote. It could be something like this:
public class MyNotifyIconControl : System.Windows.Forms.NotifyIcon {
public MyNotifyIconControl() {
this.MouseDown += (sender, eventArgs) => { ActivateColorPicker(); };
}
void ActivateColorPicker() {
if (alredyActivated) return;
}
bool alreadyActivated
}
Getting the idea?
[EDIT]
Even if you are using C# prior to v.3.0 when lambda syntax was not yet introduced, using anonymous method is still the simplest:
public MyNotifyIconControl() {
this.MouseDown += delegate(object sender, MouseEventArgs eventArgs) {
ActivateColorPicker();
};
}
[END EDIT]
—SA