当有人在Windows文本框中单击鼠标右键时,是否可以修改显示的标准弹出菜单? [英] Is there a way to modify the standard pop up menu shown when someone right click in a windows text box?

查看:103
本文介绍了当有人在Windows文本框中单击鼠标右键时,是否可以修改显示的标准弹出菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本框中单击鼠标右键弹出菜单.
我想添加自己的剪切,复制项目以及剪切和复制的快捷方式.

I want to make pop up menu for a right click on text box.
I would like to add own cut ,copy items and short cut for cut and copy also.

推荐答案

尝试
在应用程序中使用Shell ContextMenu [如何自定义WebBrowser控件的上下文菜单通过IDocHostUIHandler接口. [ ^ ]
Try
Use Shell ContextMenu in your applications[^]
How to customize the context menus of a WebBrowser control via the IDocHostUIHandler interface.[^]


通过在您的CEdit派生类中添加WM_CONTEXTMENU处理函数来覆盖CWnd :: OnContextMenu.在此处理程序中,您必须加载自己的弹出菜单,调用TrackPopupMenu并根据返回的ID调用菜单函数.

示例:
Override CWnd::OnContextMenu by adding a WM_CONTEXTMENU handler to your CEdit derived class. From within this handler, you must load your own popup menu, call TrackPopupMenu and call the menu functions according to the returned ID.

Example:
void CMyEdit::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
{
    CMenu menu;
    VERIFY(menu.LoadMenu(IDR_MYEDIT_POPUP_MENU));
    CMenu *pSub = menu.GetSubMenu(0);
    // When right clicking on a control, the focus is sometimes not moved to it
    //  before calling this function.
    if (GetFocus() != this)
        SetFocus();

    // if opened by keyboard (not mouse)
    if (point.x < 0 && point.y < 0)					
    {
        CRect rect;
        GetWindowRect(rect);
        point.x = rect.left;
        point.y = rect.bottom;
    }
    int nCommand = pSub->TrackPopupMenuEx(
        TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_VERPOSANIMATION | TPM_RETURNCMD | TPM_NONOTIFY, 
        point.x, point.y, 
        AfxGetMainWnd(), NULL); 
    switch (nCommand)
    {
    case ID_EDIT_COPY : OnCopy(); break;
    case ID_EDIT_CUT : OnCut(); break;
    }
}


为此,您必须拦截发送到编辑框的消息,您需要
用您自己的替换它的窗口过程.这种技术称为
子类化.
您可以在此处了解有关子类化的信息: Windows子类化并与C ++类挂钩 [
For this you have to intercept messages that sent to the edit box you need to
replace its window procedure with your own. This technique called
subclassing.
You can read about subclassing here : Windows subclassing and hooking with C++ classes[^]


这篇关于当有人在Windows文本框中单击鼠标右键时,是否可以修改显示的标准弹出菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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