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)
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01