如何修复 OnRButtonDown() 以检测对话框的右键单击?(使用 mfc) [英] How do I fix my OnRButtonDown() to detect right click for my dialog? (using mfc)

查看:15
本文介绍了如何修复 OnRButtonDown() 以检测对话框的右键单击?(使用 mfc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的代码没有检测到右键单击它的对话框.我错过了什么吗?另外,有什么重要的我应该知道的吗?检测在 mfc 中有效吗?

Right now my code isn't detecting a right click on it's dialog. Am I missing anything? Also, is there anything important I should know about how detection works in mfc?

在我的 .h 文件中包含此方法作为公共:

Inside my .h file contains this method as a public:

afx_msg void OnRButtonDown(UINT nFlags, CPoint point);

在我的 .cpp 文件中,我有这些人:

In my .cpp file I have these guys:

void CGadgetAddedDialog::OnRButtonDown(UINT nFlags, CPoint point)
{

char debugStr[1000];
sprintf_s(debugStr, "pressed on: %d, %d", point.x, point.y);
OutputDebugStringA(debugStr);

// TODO: Add your message handler code here and/or call default
CDialogEx::OnRButtonDown(nFlags, point);
}

BEGIN_MESSAGE_MAP(CGadgetAddedDialog, CDialogEx)
        ON_WM_ERASEBKGND()
        ON_WM_RBUTTONDOWN()
        ON_WM_CONTEXTMENU()
        ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

推荐答案

如果用鼠标右键单击子控件,子控件会收到消息.

If you click on a child control with the right mouse key, the child control receives the message.

如果您想处理上下文菜单的鼠标右键单击,而不仅仅是使用 WM_CONTEXTMENU 的处理程序.这保证了上下文菜单键也被正确处理.如果孩子不处理,这条消息也会从孩子转移到父母.

If you want to handle the right mouse click for a context menu than just use a handler for WM_CONTEXTMENU. This guaranties that also the context menu key is handled correct. Also this message is transferred from a child to the parent if the child doesn't handle it.

这篇关于如何修复 OnRButtonDown() 以检测对话框的右键单击?(使用 mfc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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