vc++中添加操作功能表的方法

來源:互聯網
上載者:User

首先要在在檔案首定義功能表項目:

#define ID_MENU_EDIT   5001 
#define ID_MENU_DELETE 5002

    然後添加對話方塊的WM_CONTEXTMENU訊息函數,函數內容為:

 

    CMenu menuPopup;
    if (menuPopup.CreatePopupMenu())
    ...{
                  menuPopup.AppendMenu(MF_STRING,ID_MENU_EDIT,"修改(&E)");
              menuPopup.AppendMenu(MF_STRING,ID_MENU_DELETE,"刪除(&D)");
              menuPopup.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);    
    }

   然後定義菜單相應函數,

1,在標頭檔中添加函數定義語句:

 

// Generated message map functions
 //{{AFX_MSG(CAdo2Dlg)
 virtual BOOL OnInitDialog();
 afx_msg void onInfoEdit(); //  這個是編輯菜單的響應函數
 afx_msg void onInfoDelete();  //這個是刪除菜單的響應函數
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 afx_msg void OnPaint();
 afx_msg HCURSOR OnQueryDragIcon();
 afx_msg void OnButton1();
 afx_msg void OnButton2();
 afx_msg void OnRdblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
 afx_msg void OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult);
 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()

 

2,在cpp檔案中添加函數體:

 

void CAdo2Dlg::OnInfoEdit() 
...{
    AfxMessageBox("edit");
}

void CAdo2Dlg::OnInfoDelete() 
...{
    AfxMessageBox("delete");
}

 

3,然後在cpp檔案中添加影射:

 

BEGIN_MESSAGE_MAP(CAdo2Dlg, CDialog)
    //{{AFX_MSG_MAP(CAdo2Dlg)
    ON_COMMAND(ID_MENU_EDIT,    OnInfoEdit)
    ON_COMMAND(ID_MENU_DELETE,  OnInfoDelete)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

 

所有的工作完成了!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.