• <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>

            我住包子山

            this->blog.MoveTo("blog.baozishan.in")

            [一篇VC小文章]VC++制作一個最小化最小托盤的8步驟(Minimize your app to systray in 8 easy steps)翻譯完

            Minimize your app to systray in 8 easy steps

            By Yasar Arslan. From codeproject




            這篇文章內容比較基礎,最近看到覺得有用,順便翻譯一下
            有空可以寫一個自己的TrayIcon類,化簡這些原始的操作。

            Introduction

            這篇文章解析了 Shell_NotifyIcon 這個函數用法--用來建立你自己的應用程序的系統托盤圖標.
            這篇文章給了基本的縮小到托盤的操作過程并讓你從中了解.
            這篇文章提供8個簡單的步驟讓你成功的實現在你的程序中建立系統托盤圖標.
            源代碼提供了一個基于對話框的演示程序.

            Tray Icons

            為了用托盤圖標你需要用一個shell函數 :)

            BOOL Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid );
            

            The dwMessage?可選的參數包括 the NIM_ADD,NIM_DELETE and NIM_MODIFY功能分別是添加刪除以及修改圖標于系統圖標.

            PNOTIFYICONDATA 結構包括這些系統需要處理的任務圖標狀態區域消息等信息.
            typedef??struct _NOTIFYICONDATA {
            ??? DWORD cbSize;
            ??? HWND hWnd;
            ??? UINT uID;
            ??? UINT uFlags;
            ??? UINT uCallbackMessage;
            ??? HICON hIcon;
            ??? #if (_WIN32_IE < 0x0500)
            ??????? TCHAR szTip[64];
            ??? #else
            ??????? TCHAR szTip[128];
            ??? #endif??? #if (_WIN32_IE >= 0x0500)
            ??????? DWORD dwState;
            ??????? DWORD dwStateMask;
            ??????? TCHAR szInfo[256];
            ??????? union {
            ??????????? UINT? uTimeout;
            ??????????? UINT? uVersion;
            ??????? } DUMMYUNIONNAME;
            ??????? TCHAR szInfoTitle[64];
            ??????? DWORD dwInfoFlags;
            ??? #endif??? #if (_WIN32_IE >= 0x600)
            ??????? GUID guidItem;
            ??? #endif
            } NOTIFYICONDATA, *PNOTIFYICONDATA;

            *Note:?更完全的信息可以去參考MSDN

            Creating the Application

            Create a new VC++ dialog based project and call it TrayMin.
            創建一個名叫TrayMin的基于對話框的VC++工程

            Step: 1

            自定義消息于 TrayMinDlg.h 頭文件.

            				#define WM_TRAY_MESSAGE (WM_USER + 1)
            		

            The WM_USER 常量用來幫助用戶定義自己的消息被用來建立個人的窗口類, 定義時通常用這種格式 WM_USER+X,?這里 X 是一個整形變量.

            *更詳細的看MSDN

            Step: 2

            現在在Now add the DECLARE_MESSAGE_MAP() 之前添加下面的用戶函數吧( TrayMinDlg.h file)?? afx_msg void OnTrayNotify(WPARAM wParam, LPARAM lParam);
            ?


            當添加一個圖標到托盤時這有一個圖標的回調消息,注意到 NOTIFYICONDATA 結構中有uCallbackMessage成員是回調消息識別的關鍵,它會被傳給NIM_ADD(我們之后將會見到更詳細的)。當添加托盤圖標這個事件發生時,系統發送一個回調函數到由hWnd成員對象指定的窗口過程(winproc),wParam 參數可以用來被識別究竟發生了什么操作。lParam參數存放發生事件相關的鼠標或者鍵盤消息。舉個例子,當一個鼠標指針指向一個托盤圖標,lParam將包括WM_MOUSEMOVE

            Step: 3


            現在添加下面的這行在消息宏中(MessageMap)在TrayMinDlg.cpp

            ON_MESSAGE(WM_TRAY_MESSAGE,OnTrayNotify)
            ?

            現在應該是這樣的.

                BEGIN_MESSAGE_MAP(CTrayMinDlg, CDialog)
                  //{{AFX_MSG_MAP(CTrayMinDlg)
                  ON_WM_SYSCOMMAND()
                  ON_WM_PAINT()
                  ON_WM_QUERYDRAGICON()
                  ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify)
                  //}}AFX_MSG_MAP
                END_MESSAGE_MAP()
            
              

            Step: 4

            現在在TrayMinDlg.cpp 定義OnTrayNotify函數,不要忘記在函數頭部添加afx_msg。

              afx_msg void CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam)
              {
                UINT uID; 
                UINT uMsg; 
             
                uID = (UINT) wParam;
                uMsg = (UINT) lParam; 
             
              
                if (uID != 1)
                  return;
              
                CPoint pt;  
              
              
                switch (uMsg ) 
                { 
            
                case WM_LBUTTONDOWN:
                  GetCursorPos(&pt);
                  ClientToScreen(&pt);
                  OnTrayLButtonDown(pt);
                  break;
              
                case WM_RBUTTONDOWN:
                case WM_CONTEXTMENU:
                  GetCursorPos(&pt);
                  OnTrayRButtonDown(pt);
                  break;
            
                } 
                return; 
              }
              

            Step: 5

            現在在TrayMinDlg類添加兩個成員函數來相應鼠標事件。

            實現鼠標左鍵單擊的相應

            • 函數類型:void ?
            • 函數聲明:?OnTrayLButtonDown(CPoint pt)

            實現鼠標右鍵單擊的相應

            • 函數類型: void
            • 函數聲明: OnTrayRButtonDown(CPoint pt)

            OnTrayLButtonDown(CPoint pt)的定義如下.

            				void CTrayMinDlg::OnTrayLButtonDown(CPoint pt)
                {  
                  MessageBox("You have clicked Left mouse Button ");
                }
              

            The Declaration of OnTrayRButtonDown(CPoint pt) is as following.

            				void CTrayMinDlg::OnTrayRButtonDown(CPoint pt)
                {  
                  //m_menu is the member of CTrayMinDlg as CMenu m_menu;
                  m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN|
                   TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this);      
                }
              

            Step: 6

            Add two member variable to the CTrayMinDlg.
            為CTrayMinDlg添加兩個成員變量

            • Variable Type: NOTIFYICONDATA
            • Variable Name: m_TrayData;
            • Variable Type: CMenu
            • Variable Name: m_menu;


            現在添加菜單資源

            Step: 7

            現在畫一個最小化的按鈕在對話框設計中
            并且添加這個按鈕的執行函數
            void CShellDlg::OnMinimize() 
              {
                m_TrayData.cbSize = sizeof(NOTIFYICONDATA);
                //Size of this structure, in bytes. 
                
                
                m_TrayData.hWnd  = this->m_hWnd;
                //Handle to the window that receives notification //messages associated with an icon in the taskbar //status area. The Shell uses hWnd and uID to //identify which icon to operate on when //Shell_NotifyIcon is invoked. 
              
                m_TrayData.uID = 1;
                //Application-defined identifier of the taskbar icon.//The Shell uses hWnd and uID to identify which icon //to operate on when Shell_NotifyIcon is invoked. You// can have multiple icons associated with a single //hWnd by assigning each a different uID. 
            
                m_TrayData.uCallbackMessage  = WM_TRAY_MESSAGE;
                //Application-defined message identifier. The system //uses this identifier to send notifications to the //window identified in hWnd. These notifications are //sent when a mouse event occurs in the bounding //rectangle of the icon, or when the icon is selected //or activated with the keyboard. The wParam parameter //of the message contains the identifier of the taskbar //icon in which the event occurred. The lParam parameter //holds the mouse or keyboard message associated with the// event. For example, when the pointer moves over a //taskbar icon, lParam is set to WM_MOUSEMOVE. 
                
            
            
                m_TrayData.hIcon = this->m_hIcon;
                //Handle to the icon to be added, modified, or deleted
                
                strcpy(m_TrayData.szTip,"My Icon");
                //Pointer to a null-terminated string with the text //for a standard ToolTip. It can have a maximum of 64 //characters including the terminating NULL. 
                
                
                m_TrayData.uFlags = NIF_ICON|NIF_MESSAGE;
                //Flags that indicate which of the other members contain 
                valid data.  
              
            
                BOOL bSuccess = FALSE;
                BOOL BSus = FALSE;
            
                BSus = m_menu.LoadMenu(IDR_MENU1);
                if(!(BSus))
                  MessageBox("Unabled to Loa menu");
            
                bSuccess = Shell_NotifyIcon(NIM_ADD,&m_TrayData);
            
                if(!(bSuccess))
                  MessageBox("Unable to Set Tary Icon");
                else
                {
                  this->ShowWindow(SW_MINIMIZE);
                  this->ShowWindow(SW_HIDE);
            
                }
              }
              
              

            Step: 8


            在退出菜單的執行函數寫下如下

            Shell_NotifyIcon(NIM_DELETE,&m_TrayData);
            ? DestroyWindow();


            現在可以運行程序,并且嘗試最小化按鈕的使用(他會最小化導系統托盤)。
            現在盡情發揮,完善這些步驟,完成自己的系統托盤圖標吧!

            Yasar Arslan

            posted on 2007-03-06 19:06 Gohan 閱讀(1880) 評論(0)  編輯 收藏 引用 所屬分類: C++

            精品精品国产自在久久高清| 无码乱码观看精品久久| 久久A级毛片免费观看| 国产69精品久久久久777| 亚洲国产成人久久精品影视| 日本WV一本一道久久香蕉| 久久国产色AV免费观看| 久久免费观看视频| 欧洲精品久久久av无码电影 | 国产精品久久网| 久久久久无码精品| 精品久久久久久久无码| 久久亚洲高清综合| 日本免费久久久久久久网站| 伊人久久大香线蕉亚洲| 欧美久久久久久精选9999| 久久久久亚洲av无码专区| 久久久久久国产a免费观看不卡| 久久精品中文字幕无码绿巨人 | 久久99精品国产自在现线小黄鸭| 国产一级做a爰片久久毛片| 精品久久久久久国产| 欧美午夜A∨大片久久| 99久久无码一区人妻| 99国产欧美久久久精品蜜芽| 久久亚洲AV成人出白浆无码国产 | 草草久久久无码国产专区| 亚洲AV无码成人网站久久精品大| 亚洲国产成人久久精品99 | 久久精品国产99国产精品导航| 伊人久久大香线蕉影院95| 久久99精品久久久久久动态图| 久久亚洲AV成人无码电影| 久久夜色精品国产网站| 久久久久成人精品无码中文字幕| 亚洲国产精品成人久久| 亚洲成色www久久网站夜月| 午夜天堂精品久久久久| 久久亚洲春色中文字幕久久久| 国内精品久久久久影院一蜜桃| 久久天天躁狠狠躁夜夜躁2O2O|