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

            思勤無邪

            上學(xué)時(shí),因我年齡最小,個(gè)頭也最小,上課時(shí),就像大猩猩堆里的猴一般。如今,這猴偶爾也把最近的一些情況寫在這里。

               :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              132 Posts :: 1 Stories :: 178 Comments :: 0 Trackbacks

            公告

                 吾日常三省吾身,曰思、曰勤、曰無邪。

            積分與排名

            • 積分 - 184826
            • 排名 - 140

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            1 .彈出菜單( Pop-up) 是不能用來作命令響應(yīng)的。

            2 MFC 中菜單項(xiàng)消息如果利用 ClassWizard 來對(duì)菜單項(xiàng)消息分別在上述四個(gè)類中進(jìn)行響應(yīng),則菜單消息傳遞順序: View --Doc --CMainFrame --App 類。菜單消息一旦在其中一個(gè)類中響應(yīng)則不再在其它類中查找響應(yīng)函數(shù)。

            具體:

            當(dāng)點(diǎn)擊一個(gè)菜單項(xiàng)的時(shí)候,最先接受到菜單項(xiàng)消息的是 CMainFrame 框架類, CMainFrame 框架類將會(huì)把菜單項(xiàng)消息交給它的子窗口 View 類,由 View 類首先進(jìn)行處理;如果 View 類檢測(cè)到?jīng)]對(duì)該菜單項(xiàng)消息做響應(yīng),則 View 類把菜單項(xiàng)消息交由文檔類 Doc 類進(jìn)行處理;如果 Doc 類檢測(cè)到 Doc 類中也沒對(duì)該菜單項(xiàng)消息做響應(yīng),則 Doc 類又把該菜單項(xiàng)消息交還給 View 類,由 View 類再交還給 CMainFrame 類處理。如果 CMainFrame 類查看到 CMainFrame 類中也沒對(duì)該消息做響應(yīng),則最終交給 App 類進(jìn)行處理。

            3 .消息的分類:標(biāo)準(zhǔn)消息,命令消息,通告消息。

            [ 標(biāo)準(zhǔn)消息 ] :除 WM_COMMAND 之外,所有以 WM_ 開頭的消息。

            [ 命令消息 ] :來自菜單、加速鍵或工具欄按鈕的消息。這類消息都以 WM_COMMAND 呈現(xiàn)。

            MFC 中,通過菜單項(xiàng)的標(biāo)識(shí)( ID )來區(qū)分不同的命令消息;在 SDK 中,通過消息的 wParam 參數(shù)識(shí)別。

            [ 通告消息 ] :由控件產(chǎn)生的消息,例如,按鈕的單擊,列表框的選擇等均產(chǎn)生此類消息,為的是向其父窗口(通常是對(duì)話框)通知事件的發(fā)生。這類消息也是以 WM_COMMAND 形式呈現(xiàn)。

            說明:

            1 )從 CWnd 派生的類,都可以接收到 [ 標(biāo)準(zhǔn)消息 ]

            2 )從 CCmdTarget 派生的類,都可以接收到 [ 命令消息 ] [ 通告消息 ]

            4 .一個(gè)菜單攔可以有若干個(gè)子菜單,一個(gè)子菜單又可以有若干個(gè)菜單項(xiàng)等。對(duì)菜單欄的子菜單由左至右建立從 0 開始的索引。對(duì)特定子菜單的菜單項(xiàng)由上至下建立了從 0 開始的索引。訪問子菜單和菜單項(xiàng)均可以通過其索引或標(biāo)識(shí)(如果有標(biāo)識(shí)的話)進(jìn)行。

            相關(guān)重要函數(shù):

            CMenu* GetMenu( ) ;//CWnd::GetMenu 得到窗口菜單欄對(duì)象指針。

            CMenu* GetSubMenu(  ) ;//CMenu::GetSubMenu 獲得指向彈出菜單對(duì)象指針

            UINT CheckMenuItem( );//CMenu::CheckMenuItem Adds check marks to or removes check marks from menu items in the pop-up menu.

            BOOL SetDefaultItem();//CMenu::SetDefaultItem Sets the default menu item for the specified menu.

            BOOL SetMenuItemBitmaps( );//CMenu::SetMenuItemBitmaps 設(shè)置位圖標(biāo)題菜單。

            UINT EnableMenuItem();//CMenu::EnableMenuItem 使菜單項(xiàng)有效,無效,或變灰。

            BOOL SetMenu( CMenu* pMenu );//CWnd::SetMenu 在當(dāng)前窗口上設(shè)置新菜單或移除菜單。

            HMENU Detach( );//CMenu::Detach Detaches a Windows menu from a CMenu object and returns the handle.

            說明:

            1 )在計(jì)算子菜單菜單項(xiàng)的索引的時(shí)候,分隔欄符也算索引的。

            2 int GetSystemMetrics() 獲取系統(tǒng)信息度量。可以用它來獲取菜單標(biāo)題的尺寸從而設(shè)置位圖標(biāo)題菜單中位圖的大小。

            3 )在 MFC MFC 為我們提供了一套命令更新機(jī)制,所有菜單項(xiàng)的更新都是由這套機(jī)制來完成的。所以要想利用 CMenu::EnableMenuItem 來自己控制菜單使用或不使用變灰等,必須要在 CMainFrame 的構(gòu)造函數(shù)中將變量 m_bAutoMenuEnable 設(shè)置為 FALSE

            4 Create a CMenu object on the stack frame as a local, then call CMenu’s member functions to manipulate the new menu as needed. Next, call CWnd::SetMenu to set the menu to a window, followed immediately by a call to the CMenu object’s Detach member function. The CWnd::SetMenu member function sets the window’s menu to the new menu, causes the window to be redrawn to reflect the menu change, and also passes ownership of the menu to the window. The call to Detach detaches the HMENU from the CMenu object, so that when the local CMenu variable passes out of scope, the CMenu object destructor does not attempt to destroy a menu it no longer owns. The menu itself is automatically destroyed when the window is destroyed.

            5 You can use the LoadMenuIndirect member function to create a menu from a template in memory, but a menu created from a resource by a call to LoadMenu is more easily maintained, and the menu resource itself can be created and modified by the menu editor.

            6 EXAMPLE

            CMenu menu;// 定義為局部對(duì)象

            menu.LoadMenu(IDR_MAINFRAME);

            SetMenu(&menu);

            menu.Detach();// 這里 menu 對(duì)象作為一個(gè)局部對(duì)象。使用 Detach() menu 對(duì)象中分離窗口菜單句柄,從而當(dāng) menu 對(duì)象析構(gòu)的時(shí)候窗口菜單資源不隨之銷毀。

            5 .命令更新機(jī)制:

            菜單項(xiàng)狀態(tài)的維護(hù)是依賴于 CN_UPDATE_COMMAND_UI 消息,誰(shuí)捕獲 CN_UPDATE_COMMAND_UI 消息, MFC 就在其中創(chuàng)建一個(gè) CCmdUI 對(duì)象。

            在后臺(tái)操作系統(tǒng)發(fā)出 WM_INITMENUPOPUP 消息,然后由 MFC 的基類如 CFrameWnd 接管并創(chuàng)建一個(gè) CCmdUI 對(duì)象和第一個(gè)菜單項(xiàng)相關(guān)聯(lián),調(diào)用對(duì)象成員函數(shù) DoUpdate() (注:這個(gè)函數(shù)在 MSDN 中沒有找到說明)發(fā)出 CN_UPDATE_COMMAND_UI 消息,這條消息帶有指向 CCmdUI 對(duì)象的指針。此后同一個(gè) CCmdUI 對(duì)象又設(shè)置為與第二個(gè)菜單項(xiàng)相關(guān)聯(lián),這樣順序進(jìn)行,直到完成所有菜單項(xiàng)。

            更新命令 UI 處理程序僅應(yīng)用于彈出式菜單項(xiàng)上的項(xiàng)目,不能應(yīng)用于永久顯示的頂級(jí)菜單項(xiàng)目。

            說明:

            1 )可以手工或用 ClassWizard 來給菜單項(xiàng)添加 UPDATE_COMMAND_UI 消息響應(yīng),利用響應(yīng)函數(shù)中傳進(jìn)來的 CCmdUI 對(duì)象指針可完成設(shè)置菜單項(xiàng)可使用,不可使用,變灰,設(shè)置標(biāo)記菜單等操作。

            6 .如果要想讓工具欄上的某個(gè)圖標(biāo)與菜單項(xiàng)的某個(gè)菜單相關(guān)聯(lián),只需要將圖標(biāo)的 ID 設(shè)置為該菜單項(xiàng)的 ID

            工具欄圖標(biāo)的索引記數(shù)順序是:從做至右從 0 開始,分隔符也算索引號(hào)。

            7 .利用向項(xiàng)目中添加 VC POPMENU 控件: Project->Add to Project->Components and Controls..

            系統(tǒng)增加的內(nèi)容: A ,一個(gè)菜單資源; B ,在派生 View 類中增加了 OnContextMenu() 函數(shù)

            說明:

            1 CWnd::OnContextMenu Called by the framework when the user has clicked the right mouse button (right clicked) in the window. You can process this message by displaying a context menu using the TrackPopupMenu.

            2 BOOL TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = NULL );

            //CMenu::TrackPopupMenu Displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu. A floating pop-up menu can appear anywhere on the screen.

            8 .利用調(diào)用 TrackPopupMenu 函數(shù),手工添加彈出菜單:

            1 )用資源管理器添加一個(gè)菜單資源

            2 )在鼠標(biāo)右鍵消息響應(yīng)函數(shù)中,加載菜單資源,并獲得要顯示的子菜單指針,并用該指針調(diào)用 TrackPopupMenu 函數(shù)便完成任務(wù)(但要注意:鼠標(biāo)響應(yīng)函數(shù)傳進(jìn)來的坐標(biāo)是客戶區(qū)坐標(biāo),而 TrackPopupMenu 函數(shù)中使用的是屏幕坐標(biāo),在調(diào)用 TrackPopupMenu 前要調(diào)用 ClientToScreen 客戶區(qū)坐標(biāo)到屏幕坐標(biāo)的轉(zhuǎn)換)

            事例代碼:

            CMenu menu;

            menu.LoadMenu(IDR_MENU1);

            CMenu *pPopup=menu.GetSubMenu(0);

            ClientToScreen(&point);

            pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,this);

            說明:

            CWnd::ClientToScreen(..);// 將一個(gè)坐標(biāo)點(diǎn)或一個(gè)矩形區(qū)域坐標(biāo)轉(zhuǎn)換成屏幕坐標(biāo)。

            CMenu::TrackPopupMenu(..);// 在指定位置以指定的方式顯示彈出菜單。

            CWnd::ScreenToClient(..);

            //Converts the screen coordinates of a given point or rectangle on the display to client coordinates.

            9 .當(dāng)彈出菜單屬于框架窗口的時(shí)候(可在 TrackPopupMenu 函數(shù)參數(shù)中設(shè)置),彈出菜單上的消息,在路由的時(shí)候,仍然遵循 View-DOC-MainFrame-APP 的響應(yīng)順序。

            10 .動(dòng)態(tài)菜單編程:

            所有的資源對(duì)象都有一個(gè)數(shù)據(jù)成員保存了資源的句柄。

            CMenu::AppendMenu //Appends a new item to the end of a menu.

            CMenu::CreatePopupMenu //Creates an empty pop-up menu and attaches it to a CMenu object.

            CMenu::InsertMenu

            //Inserts a new menu item at the position specified by nPosition and moves other items down the menu.

            CMenu::GetSubMenu //Retrieves a pointer to a pop-up menu.

            CWnd::GetMenu //Retrieves a pointer to the menu for this window.

            CMenu::DeleteMenu //Deletes an item from the menu.

            11 .手動(dòng)給動(dòng)態(tài)菜單項(xiàng)添加響應(yīng)函數(shù):

            Resource.h 中可以添加資源的 ID

            在頭文件中寫消息函數(shù)原型

            在代碼文件中添加消息映射和添加消息響應(yīng)函數(shù)

            說明:

            可以先創(chuàng)建一個(gè)臨時(shí)的菜單項(xiàng),設(shè)置它的 ID 和動(dòng)態(tài)菜單項(xiàng)的一致,然后對(duì)它用向?qū)нM(jìn)行消息響應(yīng),然后刪除臨時(shí)菜單。

            再在代碼文件中把消息映射放到宏外(注意一定要放到宏外面,因?yàn)?/span> CLASSWIZARD 發(fā)現(xiàn)菜單刪除了,同時(shí)要把其宏對(duì)里的消息映射也刪除掉的)

            12 CWnd::DrawMenuBar

            //Redraws the menu bar. If a menu bar is changed after Windows has created the window, call this function to draw the changed menu bar

            CWnd::GetParent //get a pointer to a child window’s parent window (if any).

            CWnd::Invalidate // 注意其參數(shù)的作用

            13 .集合類:

            CStringArray CStringArray CDWordArray CPtrArray CStringArray CUIntArray CWordArray

            其中成員函數(shù):

            CArray::GetAt

            CArray::Add

            14 .命令消息是到 OnCommand 函數(shù)的時(shí)候完成路由的。

            由于 CWnd::OnCommand 是個(gè)虛函數(shù),可以在框架類中重寫 OnCommand 函數(shù),從而可以截獲菜單消息使它不再往下( VIEW 類)路由。

            例:

            BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)

            {

             // TODO: Add your specialized code here and/or call the base class

             int MenuCmdId=LOWORD(wParam);// 取命令 ID

             CMenu2View *pView=(CMenu2View*)GetActiveView();// 獲取當(dāng)前 VIEW 類指針

             if(MenuCmdId>=IDM_PHONE1 && MenuCmdId<IDM_PHONE1+pView->m_strArray.GetSize())// 消息范圍判斷

             {

              CClientDC dc(pView);

              dc.TextOut(0,0,pView->m_strArray.GetAt(MenuCmdId-IDM_PHONE1));

              return TRUE;

               // 函數(shù)返回,避免調(diào)用 CFrameWnd::OnCommand 函數(shù),在 CFrameWnd::OnCommand 中截獲的消息會(huì)交由 VIEW 類處理

             }

             return CFrameWnd::OnCommand(wParam, lParam);

              // 調(diào)用基類 OnCommand 函數(shù),在 CFrameWnd::OnCommand 中截獲的消息會(huì)交由 VIEW 類處理

            }

             

            MSDN 說明:

            virtual BOOL OnCommand( WPARAM wParam, LPARAM lParam );

            //The framework calls this member function when the user selects an item from a menu, when a child control sends a notification message, or when an accelerator keystroke is translated.

            OnCommand processes the message map for control notification and ON_COMMAND entries, and calls the appropriate member function.

            Override this member function in your derived class to handle the WM_COMMAND message. An override will not process the message map unless the base class OnCommand is called.

            15 LOWORD HIWORD

            WORD LOWORD(

              DWORD dwValue  // value from which low-order word is retrieved

            );

            WORD HIWORD(

              DWORD dwValue  // value from which high-order word is retrieved

            );

            //The LOWORD macro retrieves the low-order word from the given 32-bit value.

            //The HIWORD macro retrieves the high-order word from the given 32-bit value.

            16 CFrameWnd::GetActiveView

            CView* GetActiveView( ) const;// 獲取當(dāng)前視窗口指針(單文檔框架中)

            17 .源文件是單獨(dú)參與編譯的。

            posted on 2006-05-31 17:45 思勤無邪 閱讀(6844) 評(píng)論(3)  編輯 收藏 引用 所屬分類: C++

            Feedback

            # re: VC++菜單編程[未登錄] 2011-04-13 16:43 路人甲
            彈出菜單(pop up)可以做響應(yīng)!  回復(fù)  更多評(píng)論
              

            # re: VC++菜單編程[未登錄] 2011-04-13 16:45 路人甲
            對(duì)OnContextMenu事件進(jìn)行響應(yīng)就行,在這個(gè)事件中創(chuàng)建CMenu,調(diào)用CMenu的成員函數(shù)TrackPopupMenu,另外對(duì)這個(gè)Menu的各個(gè)項(xiàng)進(jìn)行響應(yīng)就行了。  回復(fù)  更多評(píng)論
              

            # re: VC++菜單編程[未登錄] 2011-05-17 19:32
            果然2,人家說菜單無法進(jìn)行事件響應(yīng),偏要扯到彈出窗口上去。@路人甲
              回復(fù)  更多評(píng)論
              

            久久人人青草97香蕉| 国产精久久一区二区三区| 7777精品伊人久久久大香线蕉| 少妇被又大又粗又爽毛片久久黑人| 亚洲AV伊人久久青青草原| 日韩精品久久久肉伦网站| 狠狠色丁香婷综合久久| 深夜久久AAAAA级毛片免费看 | 亚洲中文字幕无码久久综合网| 欧美牲交A欧牲交aⅴ久久| 久久精品成人欧美大片| 蜜臀av性久久久久蜜臀aⅴ| 久久午夜电影网| 亚洲色欲久久久综合网| 久久久久久极精品久久久| 成人免费网站久久久| 人妻丰满?V无码久久不卡| 久久91综合国产91久久精品| 久久无码高潮喷水| 久久精品国产99国产精品| 国产成人精品久久二区二区| 国色天香久久久久久久小说 | 99国产精品久久| 久久久久久久波多野结衣高潮| 国产亚洲美女精品久久久| 久久精品人成免费| 久久精品国产亚洲AV久| 久久久久这里只有精品| yellow中文字幕久久网| 亚洲综合精品香蕉久久网97 | 色欲久久久天天天综合网| 亚洲中文字幕伊人久久无码| 精品国产综合区久久久久久| 国产伊人久久| 久久国产三级无码一区二区| 久久99精品久久久久久噜噜| 91久久精品视频| 7国产欧美日韩综合天堂中文久久久久 | 精品国产一区二区三区久久蜜臀| 国产精品美女久久久久| 国产欧美久久久精品|