How do I fix my OnRButtonDown() to detect right click for my dialog? (using mfc)(如何修复 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何修复 OnRButtonDown() 以检测对话框的右键单击?(使用 mfc)


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09