1. 程式人生 > >怎麼在介面中 設定 [設定按鈕] -- MFC

怎麼在介面中 設定 [設定按鈕] -- MFC

假如:有兩種設定

1,設定型別A

2,設定型別B

型別A和型別B都需要一個對話方塊:

1,A對話方塊

2,B對話方塊

將A和B放在一個Menu中

步驟:

具體Menu的操作:

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

CMenu類:

https://blog.csdn.net/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;