• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-59  評(píng)論-36  文章-0  trackbacks-0
            在學(xué)習(xí)實(shí)現(xiàn)托盤圖標(biāo)的過(guò)程中,自己嘗試著寫了個(gè)托盤類。
            當(dāng)然了,不用問(wèn)也知道,這個(gè)類是很弱的。

            頭文件:
            //////////////////////////////////////////////////////////////////////////
            //    
            //    文件說(shuō)明 : TrayIcon類聲明
            //    
            //    簡(jiǎn)要說(shuō)明 : 為方便自己使用,同時(shí)以達(dá)到練手為目的,于是簡(jiǎn)單的封裝(姑且用"封裝")了一個(gè)托盤類.
            //            使用該類時(shí),可以通過(guò)使用重載函數(shù)Create來(lái)進(jìn)行內(nèi)部的設(shè)置,隨后調(diào)用LoadTrayIcon或
            //            UnLoadTrayIcon函數(shù)來(lái)進(jìn)行在系統(tǒng)托盤中的圖標(biāo)顯示和隱藏.
            //
            //    zhaoyg : 2010.1.23
            //
            //////////////////////////////////////////////////////////////////////////


            #pragma once

            class TrayIcon
            {
            public:
                TrayIcon(
            void);
                
            ~TrayIcon(void);
                typedef 
            void (*CALLBACKTrayIconNotify)(LPVOID thisclass ,WPARAM wparam ,LPARAM lparam);
                
            void        Create(LPVOID callerthis , const HWND &hwnd , UINT iconID , UINT CallBackMessage, 
                                    CALLBACKTrayIconNotify pcallback, LPCTSTR ptips , HICON hicon , 
                                    UINT flags 
            = NIF_MESSAGE|NIF_ICON|NIF_TIP);
                
            void        Create(LPVOID callerthis , const HWND &hwnd , UINT iconID);
                
            void        OnTrayNotification(WPARAM wparam ,LPARAM lparam);

                
            bool        LoadTrayIcon();
                
            bool        UnLoadTrayIcon();

                
            void        SetIcon(const HICON &hicon);
                
            void        SetTip(const LPCTSTR tipstr);
                
            void        SetBalloonTip(UINT timeout , DWORD infoflags , const LPCTSTR infotitle , const LPCTSTR info);
                
            void        SetCallBackMessage(UINT CallBackMessage , CALLBACKTrayIconNotify pcallback);

                
            // change the existing icon status
                bool        ChangeIcon(const HICON &hicon);
                
            bool        ChangeTip(const LPCTSTR tipstr);
                
            bool        ChangeBalloonTip(UINT timeout , DWORD infoflags , const LPCTSTR infotitle , const LPCTSTR info);

                
            bool        visible();
                
            bool        enable();

            protected:
                NOTIFYICONDATA            m_iconinfo;
                CALLBACKTrayIconNotify    m_pcallback;
                LPVOID                    m_thisclass;
                
            bool                    m_enable;
                
            bool                    m_ishide;
            };



            實(shí)現(xiàn):
            //////////////////////////////////////////////////////////////////////////
            //    
            //    文件說(shuō)明 : TrayIcon類實(shí)現(xiàn)
            //    
            //    簡(jiǎn)要說(shuō)明 : 托盤類
            //
            //    zhaoyg : 2010.1.23
            //
            //////////////////////////////////////////////////////////////////////////


            #include 
            "StdAfx.h"
            #include 
            "TrayIcon.h"

            TrayIcon::TrayIcon(
            void)
            {
                memset(
            &m_iconinfo,0,sizeof(NOTIFYICONDATA)) ;
                m_thisclass 
            = NULL;
                m_pcallback 
            = NULL;
                m_enable 
            = false;
                m_ishide 
            = false;
            }

            TrayIcon::
            ~TrayIcon(void)
            {
            }

            //////////////////////////////////////////////////////////////////////////
            //  函數(shù) Create(LPVOID callerthis , const HWND &hwnd , UINT iconID , UINT CallBackMessage, CALLBACKTrayIconNotify pcallback, LPCTSTR ptips , HICON hicon , UINT flags);
            //
            //    功能 : NOTIFYICONDATA 
            //
            //    參數(shù)說(shuō)明:
            //      callerthis        : 包含TrayIcon對(duì)象的類對(duì)象的this指針,該指針將傳入?yún)?shù)pcallback指向的回調(diào)函數(shù)中
            //    hwnd                : 包含TrayIcon對(duì)象的類的句柄
            //    iconID            : 托盤對(duì)象ID
            //      CallBackMessage    : 回調(diào)消息.系統(tǒng)將向hwnd所表示的窗口發(fā)送該消息.該消息與一個(gè)自定義的消息處理函數(shù)關(guān)聯(lián)
            //      pcallback            : 回調(diào)函數(shù)指針.指向的函數(shù)即為CallBackMessage消息的響應(yīng)函數(shù)
            //      ptips                : 提示字符串.當(dāng)鼠標(biāo)放置于托盤上的圖標(biāo)時(shí)顯示該字符串
            //      hicon                : 需要顯示的圖標(biāo)句柄
            //      flags                : 設(shè)置托盤的相關(guān)屬性.詳見(jiàn)MSDN中的NOTIFYICONDATA結(jié)構(gòu)體
            //////////////////////////////////////////////////////////////////////////
            void TrayIcon::Create( LPVOID callerthis , const HWND &hwnd , UINT iconID , UINT CallBackMessage, 
                                  CALLBACKTrayIconNotify pcallback, LPCTSTR ptips , HICON hicon ,
                                  UINT flags)
            {
                m_iconinfo.cbSize 
            = sizeof(NOTIFYICONDATA);
                m_iconinfo.hWnd 
            = hwnd;
                m_iconinfo.uID 
            = iconID;
                m_iconinfo.hIcon 
            = hicon;
                m_iconinfo.uFlags 
            = flags;
                wcscpy_s (m_iconinfo.szTip,ptips);
                m_iconinfo.uCallbackMessage 
            = CallBackMessage;
                m_pcallback 
            =pcallback;
                m_thisclass 
            = callerthis;
                m_enable
            = true;
            }

            void TrayIcon::Create( LPVOID callerthis , const HWND &hwnd ,UINT iconID)
            {
                m_iconinfo.cbSize 
            = sizeof(NOTIFYICONDATA);
                m_iconinfo.hWnd 
            = hwnd;
                m_thisclass 
            = callerthis;
                m_iconinfo.uID 
            = iconID;
                m_enable
            = true;
            }

            void TrayIcon::OnTrayNotification( WPARAM wparam ,LPARAM lparam )
            {
                ASSERT(m_pcallback 
            != NULL && m_thisclass != NULL);
                
            return m_pcallback(m_thisclass,wparam , lparam);
            }

            bool TrayIcon::LoadTrayIcon()
            {
                
            if (m_enable && !m_ishide)
                {
                    m_ishide 
            = Shell_NotifyIcon(NIM_ADD , &m_iconinfo);
                    
            return m_ishide;
                }

                
            return false;
            }

            bool TrayIcon::UnLoadTrayIcon()
            {
                
            if (m_enable && m_ishide)
                {
                    
            bool tmp = Shell_NotifyIcon(NIM_DELETE , &m_iconinfo);
                    m_ishide 
            = !tmp;
                    m_iconinfo;
                    
            return tmp;
                }

                
            return false;
            }

            void TrayIcon::SetIcon( const HICON &hicon )
            {
                
            if (m_enable)
                {
                    m_iconinfo.uFlags 
            |= NIF_ICON;
                    m_iconinfo.hIcon 
            = hicon;
                }
            }

            void TrayIcon::SetTip( const LPCTSTR tipstr )
            {
                ASSERT(wcslen(tipstr) 
            < 64);

                m_iconinfo.uFlags 
            |= NIF_TIP;
                wcscpy_s (m_iconinfo.szTip , tipstr);
            }

            void TrayIcon::SetBalloonTip( UINT timeout , DWORD infoflags , const LPCTSTR infotitle , const LPCTSTR info )
            {
                m_iconinfo.uFlags 
            |= NIF_INFO;
                m_iconinfo.uTimeout 
            = timeout;
                m_iconinfo.dwInfoFlags 
            = infoflags;
                wcscpy_s (m_iconinfo.szInfo,info);
                wcscpy_s (m_iconinfo.szInfoTitle,infotitle);
            }

            void TrayIcon::SetCallBackMessage( UINT CallBackMessage , CALLBACKTrayIconNotify pcallback )
            {
                m_iconinfo.uFlags 
            |= NIF_MESSAGE;
                m_iconinfo.uCallbackMessage 
            = CallBackMessage;
                m_pcallback 
            = pcallback;
            }


            bool TrayIcon::ChangeIcon( const HICON &hicon )
            {
                m_iconinfo.uFlags 
            |= NIF_ICON;
                m_iconinfo.hIcon 
            = hicon;

                
            return Shell_NotifyIcon(NIM_MODIFY , &m_iconinfo);
            }

            bool TrayIcon::ChangeTip( const LPCTSTR tipstr )
            {
                ASSERT(wcslen(tipstr) 
            < 64);
                m_iconinfo.uFlags 
            |= NIF_TIP;
                wcscpy_s(m_iconinfo.szTip , tipstr);

                
            return Shell_NotifyIcon(NIM_MODIFY , &m_iconinfo);
            }
            bool TrayIcon::ChangeBalloonTip( UINT timeout , DWORD infoflags , const LPCTSTR infotitle , const LPCTSTR info )
            {
                ASSERT(wcslen(infotitle)
            < 63 && wcslen(info)< 255);

                m_iconinfo.uFlags 
            |= NIF_INFO;
                m_iconinfo.uTimeout 
            = timeout;
                m_iconinfo.dwInfoFlags 
            = infoflags;
                wcscpy_s(m_iconinfo.szInfoTitle , infotitle);
                wcscpy_s(m_iconinfo.szInfo , info);
                
            int i =Shell_NotifyIcon(NIM_MODIFY , &m_iconinfo);
                
            return i;
            }

            bool TrayIcon::visible()
            {
                
            return !m_ishide;
            }
            bool TrayIcon::enable()
            {
                
            return m_enable;
            }
            posted on 2010-02-01 18:10 zhaoyg 閱讀(410) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 小代碼MFC學(xué)習(xí)筆記
            yellow中文字幕久久网| 国内精品久久久久影院薰衣草| 久久青青草原精品影院| 久久精品国产一区二区三区不卡| 亚洲人成网站999久久久综合 | 久久久久九九精品影院| 久久综合亚洲色一区二区三区| 狠狠狠色丁香婷婷综合久久五月| 久久精品夜色噜噜亚洲A∨| 亚洲va久久久噜噜噜久久男同| 国产福利电影一区二区三区久久久久成人精品综合 | 色综合久久久久综合99| 精品久久久久久亚洲精品 | 99精品伊人久久久大香线蕉| 久久精品国产精品亚洲艾草网美妙 | 久久久久久毛片免费播放| 久久99精品久久久久久9蜜桃| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 午夜精品久久久久久久久| 久久久久国产一级毛片高清板| 精品久久久久久综合日本| 亚洲伊人久久大香线蕉综合图片| 日韩亚洲国产综合久久久| 亚洲欧美日韩精品久久| 99久久中文字幕| 亚洲精品国产美女久久久| 狠狠色丁香久久婷婷综合蜜芽五月| 狠狠久久综合伊人不卡| 久久综合久久综合九色| 久久福利青草精品资源站免费| 久久亚洲精品中文字幕| 99久久精品免费看国产一区二区三区 | 麻豆AV一区二区三区久久| 欧美日韩精品久久免费| 国内精品久久久久影院老司| 性做久久久久久久久老女人| 久久一区二区三区99| 香蕉aa三级久久毛片| 久久人妻无码中文字幕| 久久精品国产免费观看| 久久综合88熟人妻|