📄 welcomeview.cpp
字号:
// welcomeView.cpp : implementation of the CWelcomeView class
//
#include "stdafx.h"
#include "welcome.h"
#include "MainFrm.h"
#include "welcomeDoc.h"
#include "welcomeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView
IMPLEMENT_DYNCREATE(CWelcomeView, CView)
BEGIN_MESSAGE_MAP(CWelcomeView, CView)
//{{AFX_MSG_MAP(CWelcomeView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_COMMAND(ID_BUTTONfull, OnBUTTONfull)
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView construction/destruction
CWelcomeView::CWelcomeView()
{
// TODO: add construction code here
bkcolor[0]=0.0f;
bkcolor[1]=0.1f;
bkcolor[2]=0.1f;
my_pDC=NULL;
mytbar=FALSE;
mysbar=FALSE;
}
CWelcomeView::~CWelcomeView()
{
}
BOOL CWelcomeView::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);
}
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView drawing
void CWelcomeView::OnDraw(CDC* pDC)
{
CWelcomeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
///////////////////////////////////////
static BOOL bBusy = FALSE;
if(bBusy) return;
bBusy = TRUE;
// glClearColor(0.2f,0.2f,0.5f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
mydraw();
glFinish();
SwapBuffers(wglGetCurrentDC());
bBusy = FALSE;
////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView printing
BOOL CWelcomeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWelcomeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWelcomeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView diagnostics
#ifdef _DEBUG
void CWelcomeView::AssertValid() const
{
CView::AssertValid();
}
void CWelcomeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWelcomeDoc* CWelcomeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWelcomeDoc)));
return (CWelcomeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWelcomeView message handlers
int CWelcomeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
myfirst();
return 0;
}
void CWelcomeView::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();
}
BOOL CWelcomeView::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 CWelcomeView::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 CWelcomeView::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();
}
void CWelcomeView::mydraw()
{
}
void CWelcomeView::OnBUTTONfull()
{
// TODO: Add your command handler code here
CMainFrame* pframe=(CMainFrame*)AfxGetApp()->m_pMainWnd;
if(pframe->fullscreenkey){
if(!mysbar){
pframe->PostMessage(WM_COMMAND,ID_VIEW_STATUS_BAR);mysbar=TRUE;
};
}else{
if(mysbar){
pframe->PostMessage(WM_COMMAND,ID_VIEW_STATUS_BAR);mysbar=FALSE;
};
};
pframe->fullscreenkey=!pframe->fullscreenkey;
}
BOOL CWelcomeView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
//del// return CView::OnEraseBkgnd(pDC);
}
void CWelcomeView::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 CWelcomeView::OnLButtonDown(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(!mysbar){pframe->PostMessage(WM_COMMAND,ID_VIEW_STATUS_BAR);mysbar=TRUE;};
};
CView::OnLButtonDown(nFlags, point);
}
void CWelcomeView::OnLButtonUp(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(mysbar){pframe->PostMessage(WM_COMMAND,ID_VIEW_STATUS_BAR);mysbar=FALSE;};
};
if(bkcolor[2]>1.0){
bkcolor[0]=0.0f;
bkcolor[1]=0.1f;
bkcolor[2]=0.1f;
}else{
bkcolor[0]=bkcolor[0];
bkcolor[1]=bkcolor[1]+0.1f;
bkcolor[2]=bkcolor[2]+0.2f;
};
glClearColor(bkcolor[0],bkcolor[1],bkcolor[2],1.0);
RedrawWindow();
CView::OnLButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -