Article ID: 127071
Article Last Modified on 11/21/2006
119591 How to Obtain Microsoft Support Files from Online Services
void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
{
CFrameWnd::OnPaletteChanged(pFocusWnd);
if (pFocusWnd != this)
OnQueryNewPalette();
}
BOOL CMainFrame::OnQueryNewPalette()
{
WORD i;
CPalette *pOldPal;
CMfcOglView *pView = (CMfcOglView *)GetActiveView();
CClientDC dc(pView);
pOldPal = dc.SelectPalette(&pView->m_cPalette, FALSE);
i = dc.RealizePalette();
dc.SelectPalette(pOldPal, FALSE);
if (i > 0)
InvalidateRect(NULL);
return CFrameWnd::OnQueryNewPalette();
}
BOOL CMfcOglView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
return CView::PreCreateWindow(cs);
}
- Implement OnCreate() to initialize a rendering context and make it current. Also, initialize any OpenGL states here:
int CMfcOglView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
Init(); // initialize OpenGL
return 0;
}
- Implement OnSize() if the window is sizeable:
void CMfcOglView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (cy > 0)
{
glViewport(0, 0, cx, cy);
if ((m_oldRect.right > cx) || (m_oldRect.bottom > cy))
RedrawWindow();
m_oldRect.right = cx;
m_oldRect.bottom = cy;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLdouble)cx / cy, 3.0f, 7.0f);
glMatrixMode(GL_MODELVIEW);
}
}
- Implement OpenGL rendering code. This can be done in OnDraw() or other application-specific places such as OnTimer().
- Implement clean-up code, which is typically done in OnDestroy():
void CMfcOglView::OnDestroy()
{
HGLRC hrc;
if (m_nTimerID)
KillTimer(m_nTimerID);
hrc = ::wglGetCurrentContext();
::wglMakeCurrent(NULL, NULL);
if (hrc)
::wglDeleteContext(hrc);
CPalette palDefault;
// Select our palette out of the dc
palDefault.CreateStockObject(DEFAULT_PALETTE);
m_pDC->SelectPalette(&palDefault, FALSE);
if (m_pDC)
delete m_pDC;
CView::OnDestroy();
}
Additional query words: graphics kbfile
Keywords: kbfile kbinfo kbsample KB127071