1

following my another question suppose that I have two public member data in my class used as modes:

bool WantToSetRectangle;
bool WantToDrawRectangle;  

and also I have two public member data which are vectors with 4 members that are used to set a rectangle and draw a rectangle.

vector<int>ViewRectangle;
vector<int>RectangleToDraw; 

and this is the implementation of the class's OnDraw function runned after each navigation task like zooming,paning and etc.

void COpenGLControl::OnDraw(CDC *pDC)
{
// TODO: Camera controls
wglMakeCurrent(hdc,hrc);
glLoadIdentity();
gluLookAt(0,0,1,0,0,0,0,1,0);
glTranslatef(m_fPosX, m_fPosY, 0.0f);
glScalef(m_fZoom,m_fZoom,1.0);
if (WantToSetRectangle)
    setViewRectangle();
if (WantToDrawRectangle)
    DrawRectangleOnTopOfTexture();
wglMakeCurrent(NULL, NULL);
}  

Now I create two instances of the class COpenGLControl in my CDialogEx:

COpenGLControl m_oglWindow1;
COpenGLControl m_oglWindow2;  

as you see in the first picture in my another question the m_oglWindow1 is the bigger window and m_oglWindow2 is the smaller one. I set the modes of two windows as follows:(these modes are set false in the constructor)

m_oglWindow1.WantToSetRectangle = true;
m_oglWindow2.WantToDrawRectangle = true;  

each time the onDraw function of the m_oglWindow1 is called the ViewRectangle is set. these data should be dynamically passed to the RectangleToDraw of m_oglWindow2 and immediately after that the OnDraw function of m-oglWindow2 should be called to draw the extent rectangle on the smaller window that is always in the Full Extent mode.
Remember that for tasks like Fixed Zoom in, I can easily write this in the button click handlers of my CDialogEx:

void CMyOpenGLTestDlg::OnBnClickedButton4()
{
    // TODO: Add your control notification handler code here
    m_oglWindow1.FixedZoomOut();
    m_oglWindow2.RectangleToDraw = m_oglWindow1.ViewRectangle;
    m_oglWindow2.OnDraw(NULL);
}  

but in other tasks like pan,zoom in to the point and zoom out of the point that are implemented using mouse-event handlers of the class COpenGLControl, I need some kind of rea-time data exchange between two instances of the class:

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);
}
4

1 回答 1

0

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

GetParent()->PostMessage(UWM_UPDATE2, 0, 0);

其中用户定义的消息是:

#define UWM_UPDATE1 (WM_APP + 1)
#define UWM_UPDATE2 (WM_APP + 2)

如果您将 ON_MESSAGE 放入其消息映射中,该对话框可以处理这些消息。

ON_MESSAGE(UWM_UPDATE2, OnUpdate2)

LRESULT CMyOpenGLTestDlg::OnUpdate2(WPARAM, LPARAM)
{


}
于 2013-08-28T20:10:27.460 回答