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

查看:134
本文介绍了如何修复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天全站免登陆