基于Dialog的应用程序中的上下文菜单 [英] Context Menu in Dialog based application

查看:87
本文介绍了基于Dialog的应用程序中的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个应用程序,我需要在List Control中显示上下文菜单。有没有人知道如何展示它。



Regds

SNI

解决方案

看看这一步 - 逐步说明: http://www.functionx.com/visualc/howto/contextmenu.htm [ ^ ]





有时您可能想要显示上下文菜单。也就是说,如果用户右键单击而不是(左)单击,则可能需要显示特定菜单。许多MFC控件都没有自己提供这个功能;你必须在父控件上应用动作。



1.启动Microsoft Visual C ++ MFC应用程序命名为ControlContext

2.创建它作为没有AboutBox的对话框

3.在控件上设置对话框标题为上下文相关菜单

4.添加一个按钮对话框。将其ID更改为IDC_SUBMIT_BTN及其提交的标题

5.在对话框中添加一个复选框。将其ID更改为IDC_APPROVED_CHK,其标题更改为已批准:....(等等)


对于控件的上下文菜单,基于对话框和框架的应用程序之间没有区别。要将上下文菜单添加到列表控件,请使用资源编辑器创建菜单,然后添加 ON_WM_CONTEXTMENU() / OnContextMenu()处理程序到你的列表控件类:

  void  CMyListCtrl :: OnContextMenu(CWnd * pWnd, CPoint点)
{
CMenu菜单;
VERIFY(menu.LoadMenu(IDR_MYLIST_POPUP_MENU));
CMenu * pSub = menu.GetSubMenu( 0 );
// 必要时修改菜单项(例如灰色项目)
int nCmd = pSub-> TrackPopupMenuEx(
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_VERPOSANIMATION | TPM_RETURNCMD | TPM_NONOTIFY,
point.x,point.y,AfxGetMainWnd (), 空值);
if (nCmd)
SendMessage(WM_COMMAND,nCmd);
}



请注意,使用 AfxGetMainWnd()需要指定指向主对话框窗口的指针在 InitInstance()中的 CWinApp 成员变量 m_pMainWnd


Hi,

I have an application where I need to show context menu in List Control. Does anybody have idea how to show it.

Regds
SNI

解决方案

Take a look at this step-by-step explanation: http://www.functionx.com/visualc/howto/contextmenu.htm[^]


Sometimes you may want to display a context menu. That is, if the user right-clicks, instead of a (left) click, you may want to display a particular menu. Many MFC controls don''t provide this functionality on their own; you would have to apply the action on the parent control.

1.Start Microsoft Visual C++ MFC Application named ControlContext
2.Create it as Dialog Box without the AboutBox
3.Set the Dialog Title to Context-Sensitive Menu on Controls
4.Add a button to dialog box. Change its ID to IDC_SUBMIT_BTN and its Caption to Submit
5.Add a check box to the dialog box. Change its ID to IDC_APPROVED_CHK and its Caption to Approved: .... (and so long)


There is no difference between dialog and frame based applications regarding context menus of controls. To add a context menu to a list control, create the menu using the resource editor and add the ON_WM_CONTEXTMENU() / OnContextMenu() handler to your list control class:

void CMyListCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
    CMenu menu;
    VERIFY(menu.LoadMenu(IDR_MYLIST_POPUP_MENU));
    CMenu *pSub = menu.GetSubMenu(0);
    // Modify menu items here if necessary (e.g. gray out items)
    int nCmd = pSub->TrackPopupMenuEx(
        TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_VERPOSANIMATION | TPM_RETURNCMD | TPM_NONOTIFY,
        point.x, point.y, AfxGetMainWnd(), NULL);
    if (nCmd)
        SendMessage(WM_COMMAND, nCmd);
}


Note that using AfxGetMainWnd() requires that the pointer to your main dialog window is assigned to the CWinApp member variable m_pMainWnd in InitInstance().


这篇关于基于Dialog的应用程序中的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆