如何修复 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.
相关文章