天天看點

讓FX1.1的NotifyIcon支援BalloonTip(2)

讓FX1.1的NotifyIcon支援BalloonTip(2)

。于是幹脆一不做二不休,就用NotifyIcon Reflect出來的代碼做基類來實作支援Balloon Tip得了。

于是實作一個NotifyIconEx類繼承至重新編譯的NotifyIcon類,新的NotifyIcon隻做了利于被繼承的非常少量的修改。目前除了事件處理外,隻添加了一個ShowBalloonTip方法,并重載了一下WndProc方法,至于BalloonTipTitle、BalloonTipMessage和BalloonTipIcon以及Timeout的屬性支援都沒有加,因為要加上也非常的容易了。

    派生類NotifyIconEx的代碼如下:

讓FX1.1的NotifyIcon支援BalloonTip(2)

using System;

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

namespace Birdshome

讓FX1.1的NotifyIcon支援BalloonTip(2)

{

讓FX1.1的NotifyIcon支援BalloonTip(2)

    /// <summary>

讓FX1.1的NotifyIcon支援BalloonTip(2)

    /// Summary description for NotifyIconEx.

讓FX1.1的NotifyIcon支援BalloonTip(2)

    /// </summary>

讓FX1.1的NotifyIcon支援BalloonTip(2)

    public class NotifyIconEx : NotifyIcon

讓FX1.1的NotifyIcon支援BalloonTip(2)

    {

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private const int WM_BALLOONTIPSHOWN = 0x0402;

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private const int WM_BALLOONTIPCLOSING = 0x0403;

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private const int WM_BALLOONTIPCLOSED = 0x0404;

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private const int WM_BALLOONTIPCLICKED = 0x0405;

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        private static readonly object EVENT_BALLOONTIPSHOWN;

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private static readonly object EVENT_BALLOONTIPCLOSED;

讓FX1.1的NotifyIcon支援BalloonTip(2)

        private static readonly object EVENT_BALLOONTIPCLICKED;

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        static NotifyIconEx()

讓FX1.1的NotifyIcon支援BalloonTip(2)

        {

讓FX1.1的NotifyIcon支援BalloonTip(2)

            NotifyIconEx.EVENT_BALLOONTIPSHOWN = new object();

讓FX1.1的NotifyIcon支援BalloonTip(2)

            NotifyIconEx.EVENT_BALLOONTIPCLOSED = new object();

讓FX1.1的NotifyIcon支援BalloonTip(2)

            NotifyIconEx.EVENT_BALLOONTIPCLICKED = new object();

讓FX1.1的NotifyIcon支援BalloonTip(2)

        }

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        public NotifyIconEx()

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

            //

讓FX1.1的NotifyIcon支援BalloonTip(2)

            // TODO: Add constructor logic here

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        public event EventHandler BalloonTipShown

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        public event EventHandler BalloonTipClosed

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        public event EventHandler BalloonTipClicked

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        public void ShowBalloonTip(InfoIcon infoIcon, string title, string message, uint timeout)

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

            nid.uFlags = 0x0010;

讓FX1.1的NotifyIcon支援BalloonTip(2)

            nid.dwInfoFlags = (int)infoIcon;

讓FX1.1的NotifyIcon支援BalloonTip(2)

            nid.szInfo = message;

讓FX1.1的NotifyIcon支援BalloonTip(2)

            nid.szInfoTitle = title;

讓FX1.1的NotifyIcon支援BalloonTip(2)

            nid.uTimeoutOrVersion = timeout;

讓FX1.1的NotifyIcon支援BalloonTip(2)

            base.UpdateIcon(true);

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        private void OnBalloonTipShown()

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        private void OnBalloonTipClosed()

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        private void OnBalloonTipClicked()

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

        protected override void WndProc(ref System.Windows.Forms.Message msg)

讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)
讓FX1.1的NotifyIcon支援BalloonTip(2)

    }

讓FX1.1的NotifyIcon支援BalloonTip(2)

}

為了盡可能的利用原來的NotifyIcon中的代碼,不做太大的改動。新的NotifyIcon中修改了UpdateIcon方法中uFlags的管理。原來的代碼是在調用UpdateIcon時給uFlags指派為0x0001(即:NIF_MESSAGE),然後再通過一些判斷通過|操作加入新的flag。現在把第一次指派改為了:uFlags|=0x0001,目的是為了把ShowBalloonTip中對uFlags的指派傳遞進取。但是如果在顯示了Balloon

Tip後,uFlags中仍然保持了0x0010(即:NIF_INFO)标志位,那麼隻要NotifyIcon中移執行UpdateIcon就會再次顯示Balloon

Tip

讓FX1.1的NotifyIcon支援BalloonTip(2)

。是以在UpdateIcon方法的最後,我們清除uFlags中的0x0010辨別位,讓uFlag ^= 0x0010;,就這樣簡單NotifyIcon即改造完畢。

    新鮮出爐的NotifyIcon控件,使用友善,價格公道,童叟無欺

讓FX1.1的NotifyIcon支援BalloonTip(2)

本文轉自部落格園鳥食軒的部落格,原文連結:http://www.cnblogs.com/birdshome/,如需轉載請自行聯系原部落客。