• <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 閱讀(1883) 評論(0)  編輯 收藏 引用 所屬分類: C++

            久久精品国产日本波多野结衣| 青青热久久国产久精品| 欧美牲交A欧牲交aⅴ久久| 欧美日韩精品久久免费| 精品综合久久久久久888蜜芽| 久久青青草原精品影院| 亚洲国产高清精品线久久| 99久久夜色精品国产网站| 久久久久夜夜夜精品国产| 2021国内精品久久久久久影院| 久久人人爽人人爽人人片AV不| 久久99精品国产99久久6男男| 国产亚洲精久久久久久无码AV| 欧美麻豆久久久久久中文| 国产精品99久久精品| 欧美亚洲色综久久精品国产| 久久亚洲精品无码aⅴ大香| 久久精品无码一区二区三区免费 | 婷婷久久综合九色综合绿巨人| 久久精品人人做人人爽电影蜜月| 国产成人无码精品久久久久免费| 日产精品久久久久久久| 中文精品久久久久人妻不卡| 国产精品美女久久福利网站| 久久国产成人午夜AV影院| 欧美久久一区二区三区| 亚洲中文字幕无码久久精品1| 久久国产精品99精品国产| 色欲综合久久躁天天躁蜜桃| 老色鬼久久亚洲AV综合| 国产精品天天影视久久综合网| 久久国产乱子伦精品免费午夜| 日韩十八禁一区二区久久| 国产精品美女久久久久久2018| 欧美久久综合性欧美| 麻豆av久久av盛宴av| 久久精品国产精品亚洲| 伊人久久大香线蕉亚洲| 欧美久久一区二区三区| 国产精品久久久久乳精品爆| 亚洲国产另类久久久精品小说|