日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

让FX1.1的NotifyIcon支持BalloonTip(2)

發(fā)布時(shí)間:2025/6/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 让FX1.1的NotifyIcon支持BalloonTip(2) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

??? 在這個(gè)文章的(1)中,我本來(lái)打算完全自己實(shí)現(xiàn)一個(gè)支持Balloon Tip的NotifyIcon控件。后來(lái)發(fā)現(xiàn)實(shí)現(xiàn)NotifyIcon控件的大量代碼都糾纏在事件的處理和包裝上面,太沒(méi)有寫(xiě)頭了,簡(jiǎn)直就像打劫一樣沒(méi)有技術(shù)含量了。于是干脆一不做二不休,就用NotifyIcon?Reflect出來(lái)的代碼做基類(lèi)來(lái)實(shí)現(xiàn)支持Balloon Tip得了。

??? 于是實(shí)現(xiàn)一個(gè)NotifyIconEx類(lèi)繼承至重新編譯的NotifyIcon類(lèi),新的NotifyIcon只做了利于被繼承的非常少量的修改。目前除了事件處理外,只添加了一個(gè)ShowBalloonTip方法,并重載了一下WndProc方法,至于BalloonTipTitle、BalloonTipMessage和BalloonTipIcon以及Timeout的屬性支持都沒(méi)有加,因?yàn)橐由弦卜浅5娜菀琢恕?br />
??? 派生類(lèi)NotifyIconEx的代碼如下:

using?System;

namespace?Birdshome
{
????
/**////?<summary>
????
///?Summary?description?for?NotifyIconEx.
????
///?</summary>

????public?class?NotifyIconEx?:?NotifyIcon
????
{
????????
private?const?int?WM_BALLOONTIPSHOWN?=?0x0402;
????????
private?const?int?WM_BALLOONTIPCLOSING?=?0x0403;
????????
private?const?int?WM_BALLOONTIPCLOSED?=?0x0404;
????????
private?const?int?WM_BALLOONTIPCLICKED?=?0x0405;

????????
private?static?readonly?object?EVENT_BALLOONTIPSHOWN;
????????
private?static?readonly?object?EVENT_BALLOONTIPCLOSED;
????????
private?static?readonly?object?EVENT_BALLOONTIPCLICKED;

????????
static?NotifyIconEx()
????????
{
????????????NotifyIconEx.EVENT_BALLOONTIPSHOWN?
=?new?object();
????????????NotifyIconEx.EVENT_BALLOONTIPCLOSED?
=?new?object();
????????????NotifyIconEx.EVENT_BALLOONTIPCLICKED?
=?new?object();
????????}


????????
public?NotifyIconEx()
????????
{
????????????
//
????????????
//?TODO:?Add?constructor?logic?here
????????????
//
????????}


????????
public?event?EventHandler?BalloonTipShown
????????
{
????????????add
????????????
{
????????????????
this.Events.AddHandler(NotifyIconEx.EVENT_BALLOONTIPSHOWN,?value);
????????????}

????????????remove
????????????
{
????????????????
this.Events.RemoveHandler(NotifyIconEx.EVENT_BALLOONTIPSHOWN,?value);
????????????}

????????}


????????
public?event?EventHandler?BalloonTipClosed
????????
{
????????????add
????????????
{
????????????????
this.Events.AddHandler(NotifyIconEx.EVENT_BALLOONTIPCLOSED,?value);
????????????}

????????????remove
????????????
{
????????????????
this.Events.RemoveHandler(NotifyIconEx.EVENT_BALLOONTIPCLOSED,?value);
????????????}

????????}

????
????????
public?event?EventHandler?BalloonTipClicked
????????
{
????????????add
????????????
{
????????????????
this.Events.AddHandler(NotifyIconEx.EVENT_BALLOONTIPCLICKED,?value);
????????????}

????????????remove
????????????
{
????????????????
this.Events.RemoveHandler(NotifyIconEx.EVENT_BALLOONTIPCLICKED,?value);
????????????}

????????}


????????
public?void?ShowBalloonTip(InfoIcon?infoIcon,?string?title,?string?message,?uint?timeout)
????????
{
????????????nid.uFlags?
=?0x0010;
????????????nid.dwInfoFlags?
=?(int)infoIcon;
????????????nid.szInfo?
=?message;
????????????nid.szInfoTitle?
=?title;
????????????nid.uTimeoutOrVersion?
=?timeout;
????????????
base.UpdateIcon(true);
????????}


????????
private?void?OnBalloonTipShown()
????????
{
????????????EventHandler?handler?
=?(EventHandler)?base.Events[NotifyIconEx.EVENT_BALLOONTIPSHOWN];
????????????
if?(handler?!=?null)
????????????
{
????????????????handler(
this,?EventArgs.Empty);
????????????}

????????}


????????
private?void?OnBalloonTipClosed()
????????
{
????????????EventHandler?handler?
=?(EventHandler)?base.Events[NotifyIconEx.EVENT_BALLOONTIPCLOSED];
????????????
if?(handler?!=?null)
????????????
{
????????????????handler(
this,?EventArgs.Empty);
????????????}

????????}


????????
private?void?OnBalloonTipClicked()
????????
{
????????????EventHandler?handler?
=?(EventHandler)?base.Events[NotifyIconEx.EVENT_BALLOONTIPCLICKED];
????????????
if?(handler?!=?null)
????????????
{
????????????????handler(
this,?EventArgs.Empty);
????????????}

????????}


????????
protected?override?void?WndProc(ref?System.Windows.Forms.Message?msg)
????????
{
????????????
int?msgId?=?msg.Msg;
????????????
if?(?msgId?==?0x111?)
????????????
{
????????????????
switch((int)msg.LParam)
????????????????
{
????????????????????
case?WM_BALLOONTIPSHOWN:
????????????????????
{
????????????????????????
this.OnBalloonTipShown();
????????????????????????
break;
????????????????????}

????????????????????
case?WM_BALLOONTIPCLOSING:
????????????????????
{
????????????????????????
this.OnBalloonTipClosed();
????????????????????????
break;
????????????????????}

????????????????????
case?WM_BALLOONTIPCLOSED:
????????????????????
{
????????????????????????
this.OnBalloonTipClosed();
????????????????????????
break;
????????????????????}

????????????????????
case?WM_BALLOONTIPCLICKED:
????????????????????
{
????????????????????????
this.OnBalloonTipClicked();
????????????????????????
break;
????????????????????}

????????????????}

????????????}

????????????
base.WndProc?(ref?msg);
????????}

????}

}


??? 為了盡可能的利用原來(lái)的NotifyIcon中的代碼,不做太大的改動(dòng)。新的NotifyIcon中修改了UpdateIcon方法中uFlags的管理。原來(lái)的代碼是在調(diào)用UpdateIcon時(shí)給uFlags賦值為0x0001(即:NIF_MESSAGE),然后再通過(guò)一些判斷通過(guò)|操作加入新的flag?,F(xiàn)在把第一次賦值改為了:uFlags|=0x0001,目的是為了把ShowBalloonTip中對(duì)uFlags的賦值傳遞進(jìn)取。但是如果在顯示了Balloon Tip后,uFlags中仍然保持了0x0010(即:NIF_INFO)標(biāo)志位,那么只要NotifyIcon中移執(zhí)行UpdateIcon就會(huì)再次顯示Balloon Tip。所以在UpdateIcon方法的最后,我們清除uFlags中的0x0010標(biāo)識(shí)位,讓uFlag ^=?0x0010;,就這樣簡(jiǎn)單NotifyIcon即改造完畢。

??? 新鮮出爐的NotifyIcon控件,使用方便,價(jià)格公道,童叟無(wú)欺。

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的让FX1.1的NotifyIcon支持BalloonTip(2)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。