• <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  評論-36  文章-0  trackbacks-0
            在學習實現托盤圖標的過程中,自己嘗試著寫了個托盤類。
            當然了,不用問也知道,這個類是很弱的。

            頭文件:
            //////////////////////////////////////////////////////////////////////////
            //    
            //    文件說明 : TrayIcon類聲明
            //    
            //    簡要說明 : 為方便自己使用,同時以達到練手為目的,于是簡單的封裝(姑且用"封裝")了一個托盤類.
            //            使用該類時,可以通過使用重載函數Create來進行內部的設置,隨后調用LoadTrayIcon或
            //            UnLoadTrayIcon函數來進行在系統托盤中的圖標顯示和隱藏.
            //
            //    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;
            };



            實現:
            //////////////////////////////////////////////////////////////////////////
            //    
            //    文件說明 : TrayIcon類實現
            //    
            //    簡要說明 : 托盤類
            //
            //    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)
            {
            }

            //////////////////////////////////////////////////////////////////////////
            //  函數 Create(LPVOID callerthis , const HWND &hwnd , UINT iconID , UINT CallBackMessage, CALLBACKTrayIconNotify pcallback, LPCTSTR ptips , HICON hicon , UINT flags);
            //
            //    功能 : NOTIFYICONDATA 
            //
            //    參數說明:
            //      callerthis        : 包含TrayIcon對象的類對象的this指針,該指針將傳入參數pcallback指向的回調函數中
            //    hwnd                : 包含TrayIcon對象的類的句柄
            //    iconID            : 托盤對象ID
            //      CallBackMessage    : 回調消息.系統將向hwnd所表示的窗口發送該消息.該消息與一個自定義的消息處理函數關聯
            //      pcallback            : 回調函數指針.指向的函數即為CallBackMessage消息的響應函數
            //      ptips                : 提示字符串.當鼠標放置于托盤上的圖標時顯示該字符串
            //      hicon                : 需要顯示的圖標句柄
            //      flags                : 設置托盤的相關屬性.詳見MSDN中的NOTIFYICONDATA結構體
            //////////////////////////////////////////////////////////////////////////
            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 閱讀(419) 評論(0)  編輯 收藏 引用 所屬分類: 小代碼MFC學習筆記
            亚洲愉拍99热成人精品热久久| 久久久久国产精品熟女影院| 久久国产精品波多野结衣AV| 久久丝袜精品中文字幕| 久久久久久国产精品美女| 久久av无码专区亚洲av桃花岛| 国产精品美女久久久久网| 久久夜色撩人精品国产| 人妻精品久久久久中文字幕一冢本| 久久综合欧美成人| 久久久久国产精品人妻| 国内精品久久久久久久久| 久久狠狠高潮亚洲精品| 手机看片久久高清国产日韩 | 国产精品狼人久久久久影院 | 国产成人久久精品二区三区| 久久人人爽人人爽人人片AV不| 亚洲国产精品久久| 久久久久99精品成人片欧美| 热久久最新网站获取| 久久se精品一区精品二区国产 | 久久久国产精华液| 99久久成人国产精品免费| 一本色道久久综合狠狠躁| 无码乱码观看精品久久| 久久久久97国产精华液好用吗| 久久噜噜电影你懂的| 久久99国产综合精品免费| 午夜精品久久久久久毛片| 中文字幕精品无码久久久久久3D日动漫 | 香蕉久久影院| 一97日本道伊人久久综合影院| 大美女久久久久久j久久| 国产精品欧美亚洲韩国日本久久 | 青春久久| 伊人久久精品无码二区麻豆| 精产国品久久一二三产区区别| 狠狠久久综合| 久久亚洲sm情趣捆绑调教| 一本久久a久久精品亚洲| 精品无码久久久久久尤物|