// COpenGLWnd.cpp : implementation file
//

#include "stdafx.h"
#include "OpenGLWnd.h"


// COpenGLWnd

IMPLEMENT_DYNAMIC(COpenGLWnd, CWnd)

COpenGLWnd::COpenGLWnd()
{

}

COpenGLWnd::~COpenGLWnd()
{
}


BEGIN_MESSAGE_MAP(COpenGLWnd, CWnd)
    ON_WM_CREATE()
    ON_WM_SIZE()
    ON_WM_PAINT()
    ON_WM_DESTROY()
    ON_WM_ERASEBKGND()
    ON_WM_LBUTTONDOWN()
//    ON_WM_MOVE()
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()



int COpenGLWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CWnd::OnCreate(lpCreateStruct) == -1)
    {
        return -1;
    }

    m_openGraph.Initialize(this->m_hWnd);

    return 0;
}


void COpenGLWnd::OnSize(UINT nType, int cx, int cy)
{
     m_openGraph.SetWindowSize(cx, cy);

    //CWnd::OnSize(nType, cx, cy);
}


void COpenGLWnd::OnPaint()
{
    CPaintDC dc(this); // device context for painting

    OutputDebugString(_T("COpenGLWnd::OnPaint()"));
    m_openGraph.Render();
}


void COpenGLWnd::OnDestroy()
{
    CWnd::OnDestroy();
}


BOOL COpenGLWnd::OnEraseBkgnd(CDC* pDC)
{
    return TRUE; // prevent flickering
}


void COpenGLWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
    CRect rect;
    m_openGraph.OnLButtonDown(rect, nFlags, point);

    CString strMsg;
    strMsg.Format(_T("(left = %d, top = %d, right = %d, bottom = %d)"),
        rect.left, rect.top, rect.right, rect.bottom);
    OutputDebugString(strMsg);

    __super::OnLButtonDown(nFlags, point);
}

void COpenGLWnd::OnMouseMove(UINT nFlags, CPoint point)
{
    m_openGraph.OnMouseMove(nFlags, point);

    CWnd::OnMouseMove(nFlags, point);
}


BOOL COpenGLWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    m_openGraph.OnSetCursor();
    return TRUE;
}


BOOL COpenGLWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    m_openGraph.ZoomMouseWheel(nFlags, zDelta, pt);
    return CWnd::OnMouseWheel(nFlags, zDelta, pt);
}
