modeless dialog.

     First of all, I must announce that the main ideas of this paper are from Programming Microsoft Visual C++ Fifth Edition.

 

 

In order to demostrate the modeless dialog. Here I take the following steps:

 

1   Setup a single document MFC project.

 

2   Add a dialog (here we must make the dialog visiable), Here I do nothing to the dialog.   The Create a new Dialog class for this dialog only has a pointer to its parent and also a User message to communicate with its parent. See the following segment for more information:

 

 

 

 

 

3 In the View class header, I add a CModelessDlg member, its forward declaration and the initialization of the class.

 

 

// forward declaration
class CModelessDlg;

 

 

private:
    CModelessDlg* m_pDlg;

 

 

CmodelessView::CmodelessView()
{
    // TODO: add construction code here
    m_pDlg=new CModelessDlg(this);
}

CmodelessView::~CmodelessView()
{
    if(m_pDlg)
        delete m_pDlg;
}

 

4 Add a menu item named "Find" to the edit menu. and map its on command like this.

 

 

 

5 The above operation we can implement a modeless dialog now. but i also forward the dialog message to its parent

    for more processing, The ToParent message.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我犯了一个错误。在 MFC ,CMenu 并没有提供 SetMenuStyle 这个成员函数,因此无法通过设置菜单样式的方式来避免 CMenu 折叠子菜单。实现菜单不折叠子菜单的方式可以考虑在菜单项添加“更多”菜单项,点击“更多”菜单项时,弹出一个新的对话框或窗口来显示所有子菜单。具体实现方式如下: 1. 首先,在菜单项添加一个“更多”菜单项,用于显示所有的子菜单。示例代码如下: ``` CMenu menu; menu.CreatePopupMenu(); menu.AppendMenu(MF_STRING, ID_MENU_ITEM1, _T("Menu Item 1")); menu.AppendMenu(MF_STRING, ID_MENU_ITEM2, _T("Menu Item 2")); // 添加“更多”菜单项 menu.AppendMenu(MF_STRING, ID_MORE, _T("More...")); ``` 2. 在菜单项的消息处理函数,判断如果点击了“更多”菜单项,就弹出一个新的对话框或窗口,并在对话框或窗口显示所有的子菜单。示例代码如下: ``` void CMyWindow::OnCommand(UINT nID) { switch (nID) { case ID_MENU_ITEM1: // 处理菜单项1的消息 break; case ID_MENU_ITEM2: // 处理菜单项2的消息 break; case ID_MORE: { CDialog dlg(IDD_MORE_DIALOG, this); dlg.DoModal(); } break; default: break; } } ``` 3. 在对话框或窗口,显示所有的子菜单。具体实现方式可以使用 CMenu::GetMenuItemRect 函数获取“更多”菜单项的位置和大小,然后在对话框或窗口显示所有的子菜单。示例代码如下: ``` CMenu menu; menu.CreatePopupMenu(); menu.AppendMenu(MF_STRING, ID_MENU_ITEM3, _T("Menu Item 3")); menu.AppendMenu(MF_STRING, ID_MENU_ITEM4, _T("Menu Item 4")); // 获取“更多”菜单项的位置和大小 CRect rect; CWnd* pWnd = GetDlgItem(IDC_MORE); pWnd->GetWindowRect(&rect); // 在对话框或窗口显示所有的子菜单 CMenu* submenu = menu.GetSubMenu(0); submenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rect.left, rect.bottom, this); ``` 注意:以上代码仅供参考,具体实现方式需要根据实际需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值