Original Post
Hello, I have implemented simple MFC ActiveX control(VS7.1). It draws a simple bar graph, using data from .xls files. I have implemented SDI application with two panes and load control twice. In the first time it works fine, bud when I drag the splitter between panes first one is resizing properly, bud the second one looks like shabby. If anybody an idea why it's happen? there is a part of source code: // COpenGLGraphCtrl::OnDraw - Drawing function void COpenGLGraphCtrl::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { if (!pdc) return; wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC); glClearColor(GetRValue(m_clrBackground)/255.0f, GetGValue(m_clrBackground)/255.0f, GetBValue(m_clrBackground)/255.0f, 1.0f);//black bkgr glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GetClientRect(&m_oldRect); glViewport(0,0,m_oldRect.Width(),m_oldRect.Height()); DrawScene(); glFlush(); SwapBuffers(m_pDC->GetSafeHdc()); } void COpenGLGraphCtrl::DrawScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); try { glPushMatrix(); glLoadIdentity(); //translate scene glTranslated( m_pProperties->GetMoveX(), m_pProperties->GetMoveY(), m_pProperties->GetMoveZ()); //rotate scene glRotatef((GLfloat)m_pProperties->GetRotationX(),1,0,0); glRotatef((GLfloat)m_pProperties->GetRotationY(),0,1,0); glRotatef((GLfloat)m_pProperties->GetRotationZ(),0,0,1); //translate scene glTranslated( -m_pProperties->GetStrechX()/2.0f,-m_pProperties->GetStrechY()/2.0f,-m_pProperties->GetStrechZ()/2.0f); //draw scene m_pData->DrawScene(); glPopMatrix(); glFinish(); SwapBuffers(wglGetCurrentDC()); } catch(...) { AfxMessageBox("There is an exception!!!"); } } void COpenGLGraphCtrl::OnSize(UINT nType, int cx, int cy) { COleControl::OnSize(nType, cx, cy); if(cy > 0) { glViewport(0, 0, cx, cy); m_oldRect.top = 0; m_oldRect.left = 0; m_oldRect.right = cx; m_oldRect.bottom = cy; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLdouble)cx/cy, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); } } //---------------------------- Select method ------------------------------ // Make selection and return true when we have change of selection's state // returns TRUE - when there is select new graph's element, FALSE - otherwise bool COpenGLGraphCtrl::Select(CPoint point) { //return variable bool bResult = false; try { GetClientRect(&m_oldRect); glSelectBuffer(c_uiBufferSize,m_arSelectBuffer); glRenderMode(GL_SELECT); glInitNames(); glPushName(GLuint(0)); glMatrixMode(GL_PROJECTION); glGetFloatv(GL_PROJECTION_MATRIX,m_arProjectionMatrix); glPushMatrix(); glLoadIdentity(); glGetIntegerv(GL_VIEWPORT,m_arViewport); gluPickMatrix(point.x,m_oldRect.bottom-point.y,1,1,m_arViewport); glMultMatrixf(m_arProjectionMatrix); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glGetFloatv(GL_MODELVIEW_MATRIX, m_arModelViewMatrix); //prepare scene - apply current movement and rotation //translate scene glTranslated( m_pProperties->GetMoveX(), m_pProperties->GetMoveY(), m_pProperties->GetMoveZ() ); //rotate scene glRotatef((GLfloat)m_pProperties->GetRotationX(),1,0,0); glRotatef((GLfloat)m_pProperties->GetRotationY(),0,1,0); glRotatef((GLfloat)m_pProperties->GetRotationZ(),0,0,1); //translate scene glTranslated( -m_pProperties->GetStrechX()/2.0f, -m_pProperties->GetStrechY()/2.0f, -m_pProperties->GetStrechZ()/2.0f ); //call all GLList to draw for(int i=0;i<(int)m_pData->m_pGraph->m_vecGraphElements.size(); i++) { if(m_pData->m_pGraph->m_vecBaseGLList[(int) m_pData->m_pGraph->m_vecGraphElements]>0 && m_pData->m_pGraph->IsElementShown(m_pData->m_pGraph->m_vecGraphElements) ) { glCallList(m_pData->m_pGraph->m_vecBaseGLList[(int) m_pData->m_pGraph->m_vecGraphElements]); } } UINT hits=glRenderMode(GL_RENDER); UINT hit; GLuint selectionName = etNone; float fZDepth; //receive selection name if (hits>0 && hits < 1024) { GLuint min=0xffffffff; for (unsigned i=0, j=0; i m_arSelectBuffer[j+1]) { min = m_arSelectBuffer[j+1]; hit = j; } j += (3+m_arSelectBuffer[j]); //j %= 1024; } selectionName = m_arSelectBuffer[hit+3]; fZDepth=float(min)/0xffffffff; } //set selected element m_eSelName = (EGraphElementType)selectionName; if(hits>0) { switch(m_eSelName) { case etNone: case etFrame: case etDataSelection: case etXLabels: case etYLabels: case etZLabels: case etXGrid: case etYGrid: case etZGrid: //avoid flicking and m_eSelName = m_pData->m_eSelectionName; break; case etData: { //data m_iSelIndex = (int)m_arSelectBuffer[hit+4]; m_iSelGroup = (int)m_arSelectBuffer[hit+5]; break; } case etHandle: { //handles m_iSelIndex = (int)m_arSelectBuffer[hit+4]; m_iSelGroup = -1; break; } } } else { //deselect m_eSelName = etNone; m_iSelIndex = -1; m_iSelGroup = -1; } //check is change of selections hapened if( (m_eSelName != m_pData->m_eSelectionName) || (m_iSelGroup != m_pData->m_iSelectionGroup) || (m_iSelIndex != m_pData->m_iSelectionIndex) ) { m_pData->SetSelection(m_eSelName,m_iSelGroup,m_iSelIndex); bResult = true; } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } catch(...) { AfxMessageBox("Exception in select method!!!"); } return bResult; }