VC++60-MFC学习-右键菜单-RMenu

源码访问链接:

1
2
gitee:   https://gitee.com/piazini/MFC-stu
github:  https://github.com/piazini/MFC-stu

 

编译器:

VC++ 6.0 (SP6) 简体中文企业版

 

项目名:RMenu 

( 如何新建项目 ?  --> VC++60新建MFC框架程序 - 对话框程序 )

 

成品截图:

 

代码:

RMenuDlg.h

1
2
3
4
5
6
7
8
class CRMenuDlg : public CDialog
{
protected:
    //右键菜单
    afx_msg void On_32772();  //右键-大家好
    afx_msg void On_32773();  //右键-同学好
    afx_msg void On_32774();  //右键-你好
};

 

RMenuDlg.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//注意是MAP里的参数是CRMenuDlg里填写,不是上面的CAboutDlg里填写
BEGIN_MESSAGE_MAP(CRMenuDlg, CDialog)
    // 菜单栏代码需要手动添加
    //菜单栏
    ON_COMMAND(ID_MENUITEM32772, On_32772)  //右键-大家好
    ON_COMMAND(ID_MENUITEM32773, On_32773)  //右键-同学好
    ON_COMMAND(ID_MENUITEM32774, On_32774)  //右键-你好
 
END_MESSAGE_MAP()
 
//鼠标右键弹起
void CRMenuDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
     
    //载入菜单资源IDR_MENU1
    CMenu menu;
    menu.LoadMenu(IDR_MENU1);
     
    //获取菜单项里的子菜单
    CMenu *pPopup = menu.GetSubMenu(NULL);
 
    //获取鼠标点击位置
    CPoint pointPos;
    GetCursorPos(&pointPos);
 
    //弹出菜单
    pPopup ->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pointPos.x, pointPos.y,this);
 
 
    CDialog::OnRButtonUp(nFlags, point);
}
 
//右键-大家好
void CRMenuDlg::On_32772()
{
    MessageBox(_T("On_32772"));
 
//右键-同学好
void CRMenuDlg::On_32773() 
{
    MessageBox(_T("On_32773"));
 
//右键-你好
void CRMenuDlg::On_32774()
{
    MessageBox(_T("On_32774"));

  

 

 

参考:

https://blog.csdn.net/weixin_43694353/article/details/84935050

黑马MFC 三天课程

posted @   悟透  阅读(385)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示