如何启用或禁用MFC中的事件处理程序? [英] How to enable or disable an event hander in MFC?
问题描述
我已经搜索过很多,但找不到我想要的!
假设我有一个派生自 CWnd
的类。实际上,这是class COpenGLControl这里在codeguru 由我自己定制的。
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $按钮写成如下:
I have searched the web a lot but couldn't find exactly what I want!
suppose that I have a class derived from CWnd
. In fact, it is the class COpenGLControl here in codeguru customized by me for my own purposes.
the event handler for the WM_MOUSEMOVE
button is written as follows:
void COpenGLControl::OnMouseMove(UINT nFlags, CPoint point)
{
int diffX = (int)(point.x - m_fLastX);
int diffY = (int)(point.y - m_fLastY);
m_fLastX = (float)point.x;
m_fLastY = (float)point.y;
// Left mouse button
if (nFlags & MK_LBUTTON)
{
m_fRotX += (float)0.5f * diffY;
if ((m_fRotX > 360.0f) || (m_fRotX < -360.0f))
{
m_fRotX = 0.0f;
}
m_fRotY += (float)0.5f * diffX;
if ((m_fRotY > 360.0f) || (m_fRotY < -360.0f))
{
m_fRotY = 0.0f;
}
}
// Right mouse button
else if (nFlags & MK_RBUTTON)
{
m_fZoom -= (float)0.1f * diffY;
}
// Middle mouse button
else if (nFlags & MK_MBUTTON)
{
m_fPosX += (float)0.05f * diffX;
m_fPosY -= (float)0.05f * diffY;
}
OnDraw(NULL);
CWnd::OnMouseMove(nFlags, point);
}
但是我不希望这个事件处理程序是有效
或启用
。我想在我的对话框上放三个按钮,名为 pan
, rotate
和 zoom
。
当我点击 pan
我想要$ code> OnMouseMove 按钮
当我点击旋转
我想让中间按钮变得不活动,左按钮获得活动
当我点击 zoom
我希望左边的按钮变得非活动,右边的一个变得活跃。
,最后当我点击另一个按钮,如缩放范围
, select
等等,我希望 OnMouseMove
事件处理程序以这样的方式处于非活动状态,即使我在opengl窗口中,玛雅风格的鼠标
将不会被激活?
如何在我定制的COpenGLControl课程
或我的MFC对话框
?
请给我一些指示开始我的搜索了解更多。
But I don't want this event handler to be active
or enabled
at all times. I want to put three buttons on my dialog named pan
,rotate
and zoom
.
when I click pan
I want OnMouseMove
get active just for middle button
when I click rotate
I want middle button get inactive and left button get active
when I click zoom
I want left button get inactive and right one get active and so.
and finally when I click another button like Zoom extent
, select
and etc, I want the OnMouseMove
event handler get inactive in such a way that even if I'm on the opengl window the Maya-style mouse
won't be active?
How can I implement something like this whether in my customized COpenGLControl class
or in My MFC dialog
?
Please give some instructions to me to begin my search to find out more.
------------------------ -------------------------------------------------- ---------------- 编辑我的问题的一部分
我也考虑过将手动添加到我的类中的事件处理程序就像 OnDraw 函数-OpenGL-in-an-MFC-Control.htmrel =nofollow> COpenGLControl class ,所以做了这样的事情:
------------------------------------------------------------------------------------------ Edited part of my question
I also thought about adding an event-handler manually to my class just like the OnDraw
function in the COpenGLControl class so did something like this:
OpenGLContro .h
afx_msg void Pan(UINT nFlags, CPoint point);
OpenGLControl.cpp
void COpenGLControl::Pan(UINT nFlags, CPoint point)
{
int diffX = (int)(point.x - m_fLastX);
int diffY = (int)(point.y - m_fLastY);
if (nFlags & MK_MBUTTON)
{
m_fPosX += (float)0.05f * diffX;
m_fPosY -= (float)0.05f * diffY;
}
OnDraw(NULL);
}
每当按钮 pan
被点击我会调用这个函数,但是我还没有在$ code> OpenGL窗口,并且不知道帽子作为参数传递给函数 Pan
?
and whenever the button pan
is clicked I will call this function but there I'm not still on the OpenGL Window
and don't know hat to pass as the parameters to the function Pan
?
推荐答案
将一个状态/模式成员变量添加到类中, 模式一个专用的处理函数。事件处理程序您使用模式变量来决定哪些从事件处理程序调用的依赖于模式的处理程序,传递所有参数。
Add a state/mode member variable to the class and for each "mode" a dedicated handler function. The event handlers you use the mode variable to decide, which of the mode dependent handlers you call from the event handler, passing all the parameters.
这篇关于如何启用或禁用MFC中的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!