예제 #1
0
/* Implement these if needed.
 *              /// <summary>
 *              /// Mouse down delegate.
 *              /// </summary>
 *              public delegate void MouseDownDelegate(object sender, MouseEventArgs e);
 *              /// <summary>
 *              /// Occurs when the user presses the mouse button while the pointer is over the icon in the
 *              /// status notification area of the taskbar.
 *              /// </summary>
 *              new public event MouseDownDelegate MouseDown;
 *
 *              /// <summary>
 *              /// Mouse move delegate.
 *              /// </summary>
 *              public delegate void MouseMoveDelegate(object sender, MouseEventArgs e);
 *              /// <summary>
 *              /// Occurs when the user moves the mouse while the pointer is over the icon in the status
 *              /// notification area of the taskbar.
 *              /// </summary>
 *              new public event MouseMoveDelegate MouseMove;
 *
 *              /// <summary>
 *              /// Mouse up delegate.
 *              /// </summary>
 *              public delegate void MouseUpDelegate(object sender, MouseEventArgs e);
 *              /// <summary>
 *              /// Occurs when the user releases the mouse button while the pointer is over the icon in the
 *              /// status notification area of the taskbar.
 *              /// </summary>
 *              new public event MouseUpDelegate MouseUp;*/
        #endregion

        /// <summary>
        /// Wnd Proc method
        /// </summary>
        /// <param name="msg">message to the process</param>
        protected override void WndProc(ref Message msg)
        {
//			System.Diagnostics.Debug.WriteLine(msg.Msg);
            if (msg.Msg == shellNotifyIcon.WM_NOTIFY_TRAY)
            {
                if ((int)msg.WParam == shellNotifyIcon.uID)
                {
                    switch ((int)msg.LParam)
                    {
                    case NIN_BALLOONUSERCLICK:
                        balloonClicked = true;
                        if (BalloonClick != null)
                        {
                            // Fire the BalloonClick event.
                            BalloonClick(this, new EventArgs());
                            return;
                        }
                        break;

                    case WM_MOUSEMOVE:
                        if (!iconClicked)
                        {
                            balloonClicked = false;
                        }
                        break;

                    case WM_LBUTTONDOWN:
                        iconClicked = true;
                        break;

                    case WM_LBUTTONUP:
                        // Don't fire this event if the balloon-click event was just fired.
                        if (!balloonClicked)
                        {
                            if (Click != null)
                            {
                                // Fire the Click event.
                                Click(this, new EventArgs());
                                iconClicked = balloonClicked = false;
                                return;
                            }
                        }
                        iconClicked = balloonClicked = false;
                        break;

                    case WM_LBUTTONDBLCLK:
                        if (DoubleClick != null)
                        {
                            // Fire the DoubleClick event.
                            DoubleClick(this, new EventArgs());
                            return;
                        }
                        break;

                    case WM_RBUTTONDOWN:
                        break;

                    case WM_RBUTTONUP:
                        if ((shellNotifyIcon.ContextMenu != null) &&
                            (shellNotifyIcon.ContextMenu.Handle != IntPtr.Zero))
                        {
                            if (ContextMenuPopup != null)
                            {
                                // Fire the ContextMenuPopup event.
                                ContextMenuPopup(this, new EventArgs());
                            }

                            // This is a work-around for a known bug ...
                            // (call SetForegroundWindow before and after calling TrackPopupMenu).
                            ShellNotifyIcon.SetForegroundWindow(shellNotifyIcon.Handle);

                            // Display the shortcut menu.
                            TrackPopupMenu(
                                shellNotifyIcon.ContextMenu.Handle,
                                TPM_RIGHTBUTTON,
                                System.Windows.Forms.Cursor.Position.X,
                                System.Windows.Forms.Cursor.Position.Y,
                                0,
                                shellNotifyIcon.Handle,
                                IntPtr.Zero);

                            ShellNotifyIcon.SetForegroundWindow(shellNotifyIcon.Handle);
                            return;
                        }
                        break;
                    }
                }
            }
            else if (msg.Msg == shellNotifyIcon.shellRestart)
            {
                // The shell has been restarted, add the icon to the tray.
                if (shellNotifyIcon.Visible)
                {
                    shellNotifyIcon.Visible = false;
                    shellNotifyIcon.Visible = true;
                }
            }

            base.WndProc(ref msg);
        }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="shellNotifyIcon">Shell NotifyIcon object</param>
 internal NotifyMessageLoop(ShellNotifyIcon shellNotifyIcon)
 {
     this.shellNotifyIcon = shellNotifyIcon;
 }