#include "stdafx.h"
#include "F.h"#include "FDoc.h"
#include "FView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CFViewIMPLEMENT_DYNCREATE(CFView, CView)BEGIN_MESSAGE_MAP(CFView, CView)
//{{AFX_MSG_MAP(CFView)
ON_WM_CREATE()
ON_WM_CANCELMODE()
ON_WM_DESTROY()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_BUTTONnurbs, OnBUTTONnurbs)
ON_COMMAND(ID_BUTTONbezier, OnBUTTONbezier)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CFView construction/destructionCFView::CFView()
{
// TODO: add construction code here
my_pDC=NULL;
mybezier=FALSE;
mynurbs=FALSE;
}CFView::~CFView()
{
}BOOL CFView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CFView drawingvoid CFView::OnDraw(CDC* pDC)
{
CFDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
static BOOL bBusy=FALSE;
if(bBusy) return;
bBusy=TRUE;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
mydraw();
glFinish();
SwapBuffers(wglGetCurrentDC());
bBusy=FALSE;
}/////////////////////////////////////////////////////////////////////////////
// CFView printingBOOL CFView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CFView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CFView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CFView diagnostics#ifdef _DEBUG
void CFView::AssertValid() const
{
CView::AssertValid();
}void CFView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CFDoc* CFView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFDoc)));
return (CFDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CFView message handlersBOOL CFView::mypixelformat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL| // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
int pixelformat; if ( (pixelformat = ChoosePixelFormat(my_pDC->GetSafeHdc(), &pfd)) == 0 )
{
MessageBox("ChoosePixelFormat failed");
return FALSE;
} if (SetPixelFormat(my_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
{
MessageBox("SetPixelFormat failed");
return FALSE;
} return TRUE;
}void CFView::myfirst()
{
PIXELFORMATDESCRIPTOR pfd;
int n;
HGLRC hrc; my_pDC = new CClientDC(this); ASSERT(my_pDC != NULL); if (!mypixelformat())
return;
n =::GetPixelFormat(my_pDC->GetSafeHdc());
::DescribePixelFormat(my_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
hrc = wglCreateContext(my_pDC->GetSafeHdc());
wglMakeCurrent(my_pDC->GetSafeHdc(), hrc); GetClientRect(&my_oldRect);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}int CFView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
myfirst();
return 0;
}void CFView::OnCancelMode()
{
CView::OnCancelMode();
// TODO: Add your message handler code here
}void CFView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
HGLRC hrc; hrc = ::wglGetCurrentContext(); ::wglMakeCurrent(NULL, NULL);
if (hrc)
::wglDeleteContext(hrc); if (my_pDC)
delete my_pDC;
}
void CFView::OnBUTTONnurbs()
{
// TODO: Add your command handler code here
mynurbs=!mynurbs;
glClearColor(0.0f,0.0f,1.0f,1.0f);
Invalidate(FALSE);
}void CFView::mydraw()
{
glTranslatef(0.0f,0.0f,-6.0f);
if(mybezier) {Mybezier();};
if(mynurbs){Mynurbs();};
}void CFView::Mynurbs()
{
glPushMatrix();
glBegin(GL_LINES);
glVertex2f(0.0f,0.0f);
glVertex2f(0.01f,-0.4f);
glEnd();
glPopMatrix();
}
#include "F.h"#include "FDoc.h"
#include "FView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CFViewIMPLEMENT_DYNCREATE(CFView, CView)BEGIN_MESSAGE_MAP(CFView, CView)
//{{AFX_MSG_MAP(CFView)
ON_WM_CREATE()
ON_WM_CANCELMODE()
ON_WM_DESTROY()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_BUTTONnurbs, OnBUTTONnurbs)
ON_COMMAND(ID_BUTTONbezier, OnBUTTONbezier)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CFView construction/destructionCFView::CFView()
{
// TODO: add construction code here
my_pDC=NULL;
mybezier=FALSE;
mynurbs=FALSE;
}CFView::~CFView()
{
}BOOL CFView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CFView drawingvoid CFView::OnDraw(CDC* pDC)
{
CFDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
static BOOL bBusy=FALSE;
if(bBusy) return;
bBusy=TRUE;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
mydraw();
glFinish();
SwapBuffers(wglGetCurrentDC());
bBusy=FALSE;
}/////////////////////////////////////////////////////////////////////////////
// CFView printingBOOL CFView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CFView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CFView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CFView diagnostics#ifdef _DEBUG
void CFView::AssertValid() const
{
CView::AssertValid();
}void CFView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CFDoc* CFView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFDoc)));
return (CFDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CFView message handlersBOOL CFView::mypixelformat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL| // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
int pixelformat; if ( (pixelformat = ChoosePixelFormat(my_pDC->GetSafeHdc(), &pfd)) == 0 )
{
MessageBox("ChoosePixelFormat failed");
return FALSE;
} if (SetPixelFormat(my_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
{
MessageBox("SetPixelFormat failed");
return FALSE;
} return TRUE;
}void CFView::myfirst()
{
PIXELFORMATDESCRIPTOR pfd;
int n;
HGLRC hrc; my_pDC = new CClientDC(this); ASSERT(my_pDC != NULL); if (!mypixelformat())
return;
n =::GetPixelFormat(my_pDC->GetSafeHdc());
::DescribePixelFormat(my_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
hrc = wglCreateContext(my_pDC->GetSafeHdc());
wglMakeCurrent(my_pDC->GetSafeHdc(), hrc); GetClientRect(&my_oldRect);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}int CFView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
myfirst();
return 0;
}void CFView::OnCancelMode()
{
CView::OnCancelMode();
// TODO: Add your message handler code here
}void CFView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
HGLRC hrc; hrc = ::wglGetCurrentContext(); ::wglMakeCurrent(NULL, NULL);
if (hrc)
::wglDeleteContext(hrc); if (my_pDC)
delete my_pDC;
}
void CFView::OnBUTTONnurbs()
{
// TODO: Add your command handler code here
mynurbs=!mynurbs;
glClearColor(0.0f,0.0f,1.0f,1.0f);
Invalidate(FALSE);
}void CFView::mydraw()
{
glTranslatef(0.0f,0.0f,-6.0f);
if(mybezier) {Mybezier();};
if(mynurbs){Mynurbs();};
}void CFView::Mynurbs()
{
glPushMatrix();
glBegin(GL_LINES);
glVertex2f(0.0f,0.0f);
glVertex2f(0.01f,-0.4f);
glEnd();
glPopMatrix();
}
http://blog.csdn.net/xianglitian/archive/2011/01/26/6164103.aspx
void CFView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(cy>0)
{
my_oldRect.right=cx;
my_oldRect.bottom=cy;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,0.0,-1.0*cy/cx,1.0*cy/cx,5.0,9.0);
}
RedrawWindow();
}
是哪里错了呢?怎么改呢?