【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“cmyView.cpp”一文,供大家参考学习
// cmyView.cpp : implementation of the CCmyView class
//
#include "stdafx.h"
#include "cmy.h"
#include "MainFrm.h"
#include "Math.h"
#include "cmyDoc.h"
#include "cmyView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCmyView
IMPLEMENT_DYNCREATE(CCmyView, CView)
BEGIN_MESSAGE_MAP(CCmyView, CView)
//{{AFX_MSG_MAP(CCmyView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_BUTTONfull, OnBUTTONfull)
ON_WM_TIMER()
ON_COMMAND(ID_BUTTONcball, OnBUTTONcball)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCmyView construction/destruction
CCmyView::CCmyView()
{
// TODO: add construction code here
my_pDC=NULL;
mytbar=FALSE;
mysbar=FALSE;
listi=-1;
mykey=TRUE;
bh=0.0f;
for(int i=0;i<10;i++){
cb[i][0]=1.0f*rand()/RAND_MAX;
cb[i][1]=1.0f*rand()/RAND_MAX;
cb[i][2]=1.0f*rand()/RAND_MAX;
cb[i][3]=0.1f+0.3f*rand()/RAND_MAX;
cb[i][4]=-0.30f;
cb[i][5]=-0.1f-0.3f*rand()/RAND_MAX;
cb[i][6]=0.4f;
};
}
CCmyView::~CCmyView()
{
}
BOOL CCmyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style=WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCmyView drawing
void CCmyView::OnDraw(CDC* pDC)
{
CCmyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
static BOOL bBusy = FALSE;
if(bBusy) return;
bBusy = TRUE;
glClearColor(0.0f,0.6f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
mydraw();
glFinish();
SwapBuffers(wglGetCurrentDC());
bBusy = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CCmyView printing
BOOL CCmyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCmyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCmyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCmyView diagnostics
#ifdef _DEBUG
void CCmyView::AssertValid() const
{
CView::AssertValid();
}
void CCmyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCmyDoc* CCmyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCmyDoc)));
return (CCmyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCmyView message handlers
BOOL CCmyView::mypixelformat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER,
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 CCmyView::mydraw()
{
glTranslatef(0.0f,0.0f,-7.0f);
//glEnable(GL_LINE_STIPPLE);
//glEnable(GL_LINE_SMOOTH);
glPushMatrix();
glScalef(0.4f,0.3f,0.4f);
colorbox();
glPopMatrix();
glPushMatrix();
lm();
glPopMatrix();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);
if(listi==-1){
listi=glGenLists(10);
glListBase(listi);
mylist();
}else{
for(int i=0;i<10;i++){
glPushMatrix();
glTranslatef(cb[i][3],cb[i][4],cb[i][5]);
glScalef(cb[i][6],cb[i][6],cb[i][6]);
glCallList(i);
glPopMatrix();
};
};
glDisable(GL_LIGHTING);
//glDisable(GL_LINE_SMOOTH);
//glDisable(GL_LINE_STIPPLE);
}
void CCmyView::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 CCmyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
myfirst();
return 0;
}
void CCmyView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
KillTimer(1);
HGLRC hrc;
hrc = ::wglGetCurrentContext();
::wglMakeCurrent(NULL, NULL);
if (hrc)
::wglDeleteContext(hrc);
if (my_pDC)
delete my_pDC;
}
void CCmyView::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,1.0,-1.0*cy/cx,1.0*cy/cx,5.0,9.0);
glViewport(0, 0, cx, cy);
}
RedrawWindow();
}
BOOL CCmyView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
// return CView::OnEraseBkgnd(pDC);
}
void CCmyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMainFrame* pframe=(CMainFrame*)AfxGetApp()->m_pMainWnd;
pframe->xyshow(point.x,point.y);
if(pframe->fullscreenkey){
if(point.y<5){
if(!mytbar){mytbar=TRUE;pframe->PostMessage(WM_COMMAND,ID_VIEW_TOOLBAR);};
}else{
if(mytbar){mytbar=FALSE;pframe->PostMessage(WM_COMMAND,ID_VIEW_TOOLBAR);};
};
};
CView::OnMouseMove(nFlags, point);
}
void CCmyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and
上一篇:
CMYODBCEXCELDLG.CPP
下一篇:
如何提高博士论文的构思能力