怎么在界面中 设置 [设置按钮] -- MFC

本文介绍如何在C++中使用CMenu类创建并操作菜单,包括加载菜单资源、修改菜单项以及响应菜单命令。同时展示了如何通过对话框进行设置A和设置B的交互,提供了一个具体的代码实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

假如:有两种设置

1,设置类型A

2,设置类型B

类型A和类型B都需要一个对话框:

1,A对话框

2,B对话框

将A和B放在一个Menu中

步骤:

具体Menu的操作:

http://www.lingchenliang.com/post/1876.html

CMenu类:

https://blog.youkuaiyun.com/alexander_frank/article/details/52126660

	CMenu *pMenu = new CMenu();
	ASSERT(pMenu != NULL);
	BOOL bRet = pMenu->LoadMenu(IDR_MENU_SET);
	if (bRet == FALSE)
	{
		delete pMenu;
		return;
	}

	CMenu* pSubMenu = pMenu->GetSubMenu(0);
	ASSERT(pSubMenu != NULL);

	UINT nID = pSubMenu->GetMenuItemID(0);
	pSubMenu->ModifyMenu(0, MF_BYPOSITION , nID , _T("设置A"));
	nID = pSubMenu->GetMenuItemID(1);
	pSubMenu->ModifyMenu(1, MF_BYPOSITION , nID , _T("设置B"));

需要在设置旁边显示设置菜单:主要设置属性问题

摘自msdn的例子:

// The code fragment shows how to get the File menu from the 
// application window and displays it as a floating popup menu 
// when the right mouse button is clicked in view. 
// CMdiView is a CView-derived class. 
void CMdiView::OnRButtonDown(UINT nFlags, CPoint point)
{
   CView::OnRButtonDown(nFlags, point);

   CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
   CMenu* file_menu = menu_bar->GetSubMenu(0);    
   ASSERT(file_menu);

   ClientToScreen(&point);
   file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
      point.y, this);
}
	if (nCmd == ID_SET_A)
	{
		ADlg dlg;
		if (dlg.DoModal() == IDOK) {

		}
	}
	else if (nCmd == ID_SET_B)
	{
        BDlg dlg;
        if(){
        }
	}
	delete pMenu;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值