Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类CopinglControl的两个实例之间的动态数据交换_C++_Opengl_Real Time_Dynamic Data_Multiple Instances - Fatal编程技术网

C++ 类CopinglControl的两个实例之间的动态数据交换

C++ 类CopinglControl的两个实例之间的动态数据交换,c++,opengl,real-time,dynamic-data,multiple-instances,C++,Opengl,Real Time,Dynamic Data,Multiple Instances,下面假设我的类中有两个公共成员数据用作模式: bool WantToSetRectangle; bool WantToDrawRectangle; 我还有两个公共成员数据,它们是有4个成员的向量,用于设置一个矩形和绘制一个矩形 vector<int>ViewRectangle; vector<int>RectangleToDraw; 现在,我在我的CDialogEx中创建了类COpenGLControl的两个实例: COpenGLControl m_oglWin

下面假设我的类中有两个公共成员数据用作模式:

bool WantToSetRectangle;
bool WantToDrawRectangle;  
我还有两个公共成员数据,它们是有4个成员的向量,用于设置一个矩形和绘制一个矩形

vector<int>ViewRectangle;
vector<int>RectangleToDraw; 
现在,我在我的
CDialogEx
中创建了类
COpenGLControl
的两个实例:

COpenGLControl m_oglWindow1;
COpenGLControl m_oglWindow2;  
void CMyOpenGLTestDlg::OnBnClickedButton4()
{
    // TODO: Add your control notification handler code here
    m_oglWindow1.FixedZoomOut();
    m_oglWindow2.RectangleToDraw = m_oglWindow1.ViewRectangle;
    m_oglWindow2.OnDraw(NULL);
}  
正如您在
m_oglWindow1
的第一张图片中看到的,是较大的窗口,
m_oglWindow2
是较小的窗口。我将两个窗口的模式设置如下:(这些模式在构造函数中设置为
false

每次调用
m_oglWindow1
onDraw
函数时,都会设置
ViewRectangle
。这些数据应动态地传递到
m_oglWindow2
RectangleToDraw
,之后应立即调用
m-oglWindow2
OnDraw
函数,在始终处于
全范围
模式的较小窗口上绘制范围矩形。
请记住,对于像
固定放大
这样的任务,我可以很容易地在我的
CDialogEx
的按钮点击处理程序中编写:

COpenGLControl m_oglWindow1;
COpenGLControl m_oglWindow2;  
void CMyOpenGLTestDlg::OnBnClickedButton4()
{
    // TODO: Add your control notification handler code here
    m_oglWindow1.FixedZoomOut();
    m_oglWindow2.RectangleToDraw = m_oglWindow1.ViewRectangle;
    m_oglWindow2.OnDraw(NULL);
}  
但是在使用类
COpenGLControl
鼠标事件处理程序
实现的其他任务(如
pan
放大点
缩小点
)中,我需要在类的两个实例之间进行某种实时数据交换:

void COpenGLControl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToPan)
{
    if (m_fLastX < 0.0f && m_fLastY < 0.0f)
    {
        m_fLastX = (float)point.x;
        m_fLastY = (float)point.y;
    }
    int diffX = (int)(point.x - m_fLastX);
    int diffY = (int)(point.y - m_fLastY);
    m_fLastX = (float)point.x;
    m_fLastY = (float)point.y;
    if (nFlags & MK_MBUTTON)
    {
        m_fPosX += (float)0.2f*m_fZoomInverse*diffX;
        m_fPosY -= (float)0.2f*m_fZoomInverse*diffY;
    }
    OnDraw(NULL);
}
CWnd::OnMouseMove(nFlags, point);
}

void COpenGLControl::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToUseZoomTool)
{
    if (nFlags & MK_LBUTTON)
    {
        m_fZoom = 1.05f*m_fZoom;
        m_fZoomInverse = 1/m_fZoom;
        int diffX = (int)(point.x - oglWindowWidth/2);
        int diffY = (int)(point.y - oglWindowHeight/2);
        m_fPosX -= (float)diffX;
        m_fPosY += (float)diffY;
    }
    OnDraw(NULL);
}
CWnd::OnLButtonDown(nFlags, point);
}  

void COpenGLControl::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (WantToUseZoomTool)
{
    if (nFlags & MK_RBUTTON)
    {
        m_fZoom = 0.95f*m_fZoom;
        m_fZoomInverse = 1/m_fZoom;
        int diffX = (int)(point.x - oglWindowWidth/2);
        int diffY = (int)(point.y - oglWindowHeight/2);
        m_fPosX -= (float)diffX;
        m_fPosY += (float)diffY;
    }
    OnDraw(NULL);
}
CWnd::OnRButtonDown(nFlags, point);
}
void COpenGLControl::OnMouseMove(UINT nFlags,CPoint point)
{
//TODO:在此处添加消息处理程序代码和/或调用默认值
如果(WANTOPAN)
{
if(mu fLastX<0.0f&&mu fLastY<0.0f)
{
m_fLastX=(浮点)点x;
m_fLastY=(浮点)点y;
}
int diffX=(int)(点x-m_fLastX);
int diffY=(int)(点y-m_fLastY);
m_fLastX=(浮点)点x;
m_fLastY=(浮点)点y;
if(nFlags和MK_MBUTTON)
{
m_fPosX+=(浮点)0.2f*m_fZoomInverse*diffX;
m_fPosY-=(浮点)0.2f*m_fZoomInverse*diffY;
}
OnDraw(空);
}
CWnd::OnMouseMove(nFlags,point);
}
void COpenGLControl::OnLButtonDown(UINT nFlags,CPoint point)
{
//TODO:在此处添加消息处理程序代码和/或调用默认值
如果(要使用ZoomTool)
{
if(nFlags和MK按钮)
{
m_fZoom=1.05f*m_fZoom;
m_fZoomInverse=1/m_fZoom;
int diffX=(int)(点x-oglWindowWidth/2);
int-diffY=(int)(点y-oglWindowHeight/2);
m_fPosX-=(浮点)diffX;
m_fPosY+=(浮点)diffY;
}
OnDraw(空);
}
CWnd::ONLBUTDOWN(nFlags,点);
}  
void COpenGLControl::OnRButtonDown(UINT nFlags,CPoint point)
{
//TODO:在此处添加消息处理程序代码和/或调用默认值
如果(要使用ZoomTool)
{
if(nFlags和MK按钮)
{
m_fZoom=0.95f*m_fZoom;
m_fZoomInverse=1/m_fZoom;
int diffX=(int)(点x-oglWindowWidth/2);
int-diffY=(int)(点y-oglWindowHeight/2);
m_fPosX-=(浮点)diffX;
m_fPosY+=(浮点)diffY;
}
OnDraw(空);
}
CWnd::OnRButtonDown(nFlags,点);
}

每个控件都可以通知父对话框需要更新另一个控件

GetParent()->PostMessage(UWM_UPDATE2, 0, 0);
其中,用户定义的消息是:

#define UWM_UPDATE1 (WM_APP + 1)
#define UWM_UPDATE2 (WM_APP + 2)
如果将_消息放入其消息映射中,该对话框可以处理这些消息

ON_MESSAGE(UWM_UPDATE2, OnUpdate2)

LRESULT CMyOpenGLTestDlg::OnUpdate2(WPARAM, LPARAM)
{


}

谢谢@ScottMcP MVP告诉我这样做对吗?事实上,我只是想到了用户定义的消息,但由于我是MFC的新手,实现它需要一段时间。这个项目应该尽快准备好,所以我不想走错方向,从零开始?那么,请告诉我用户定义的消息是否是我应该学习的正确概念?是的,用户定义的消息是通知父窗口的正确概念。它不需要一段时间就能实现。