CChildView::CChildView()
{
m_pClientDC = NULL;
m_lpThread = NULL;
m_nFloorIndex = 0;
}
CChildView::~CChildView()
{
if ( m_lpThread != NULL )
{
delete m_lpThread;
m_lpThread = NULL;
}
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if ( ! CWnd::PreCreateWindow( cs ) )
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass( CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
::LoadCursor( NULL, IDC_ARROW ), HBRUSH( COLOR_WINDOW + 1 ), NULL );
return TRUE;
}
BOOL CChildView::PreTranslateMessage( MSG* pMsg )
{
if ( pMsg->message == WM_KEYDOWN && ( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_SPACE ) )
{
if ( ++m_nFloorIndex >= 3 )
m_nFloorIndex = 0;
}
return CWnd::PreTranslateMessage( pMsg );
}
int CChildView::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if ( CWnd::OnCreate( lpCreateStruct ) == -1 )
{
TRACE0( "Failed to create the CChildView" );
return -1;
}
m_lpThread = AfxBeginThread( Thread, NULL, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED );
ASSERT( m_lpThread );
InitOpenGL();
SetTimer( 1, 50, NULL );
m_lpThread->ResumeThread();
return 0;
}
void CChildView::OnSize( UINT nType, int cx, int cy )
{
CWnd::OnSize( nType, cx, cy );
if ( cy == 0 )
cy = 1;
glViewport( 0, 0, cx, cy ); // Reset The Current View-port
glMatrixMode( GL_PROJECTION ); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective( 45.0f, ( GLfloat ) cx / ( GLfloat ) cy, 0.1f, 400.0f );
glMatrixMode( GL_MODELVIEW ); // Select The Model-view Matrix
glLoadIdentity();
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CBitmap bitmap;
bitmap.LoadBitmap( IDB_SNOW_FLOOR );
// TODO: Add your message handler code here
DrawOpenGLScene();
// Do not call CWnd::OnPaint() for painting messages
}
BOOL CChildView::OnEraseBkgnd( CDC* pDC )
{
UNREFERENCED_PARAMETER( pDC );
return TRUE;
}
void CChildView::OnDestroy()
{
HGLRC hrc = NULL;
hrc = ::wglGetCurrentContext();
::wglMakeCurrent( NULL, NULL );
if ( hrc != NULL )
::wglDeleteContext( hrc );
if ( m_pClientDC != NULL )
{
delete m_pClientDC;
m_pClientDC = NULL;
}
ASSERT( m_pClientDC == NULL );
CWnd::OnDestroy();
}
没有合适的资源?快使用搜索试试~ 我知道了~
aaa.rar_OnDestroy_PreTranslateMessage_childview opengl_onsize_vi
共1个文件
cpp:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 163 浏览量
2022-09-23
09:18:03
上传
评论
收藏 1KB RAR 举报
温馨提示
这是用MFC编写的使用openGL的视口代码。 CChildView::CChildView() 构造函数 CChildView::~CChildView() 析构函数 BEGIN_MESSAGE_MAP(CChildView,CWnd ) 消息映射 BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)创建窗口重新设置窗口参数 BOOL CChildView::PreTranslateMessage( MSG* pMsg ) 翻译消息 int CChildView::OnCreate( LPCREATESTRUCT lpCreateStruct ) 窗口创建好后进入此函数 完成openGL的初始化 void CChildView::OnSize( UINT nType, int cx, int cy ) 当窗口大小发生改变时重新设置OPenGL的视口参数。 void CChildView::OnDestroy() 销毁窗口
资源推荐
资源详情
资源评论
收起资源包目录
aaa.rar (1个子文件)
aaa.cpp 3KB
共 1 条
- 1
资源评论
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功