public:
CClientDC* m_pDC;
HGLRC m_hRC;
//add in the init() function of view class
m_hRC = wglCreateContext(m_pDC->GetSafeHdc());
接着在某个视图需要更新的时候(一般在每个视图的 OnDraw()函数中),将这个
视图的设备上下文设为 OpenGL 当前的渲染上下文(OpenGL Rendering
context)
//add in the OnDraw() function of view class
//set current device
wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);
二、视图类型的切换及当前视图类型的判断
由于同一视图在不同的时刻根据用户的需要可能有不同的功能,因此需要在几个视
图之间进行功能的切换。本程序选取一个视图作为主视图,而另外两个视图作为子
视图。视图的类有一下几种:上、下视图,前、后视图,左、右视图。为此设计了
枚举类型变量用于指示视图的类型。为了保证不同视图类型之间的有效切换,即不
会产生重复的类型,设计了一个类用于操作视图之间的类型切换。
为了减小程序编制的负担,所有子视图共享一个视图类,而每个视图的当前类型是
存储在这个视图类之外的,因此在每个视图绘制的时候都需要判断自己的类型。这
样便出现了无法在子视图类中判断自己当前的视图类型的情况。为此在子视图类中
增加了一个成员变量用于记录自己的类型。
//add in the header le of child view class
//view ID, it will be assigned by parentframe when this
program begin
//[childviewA id = 1; childviewB id = 2]
int m_ViewID
然后在程序运行之初,浮动窗体创建之后,对每个浮动窗体所包含的子视图的类型
进行设置。
//add in the OnCreate() function of CMainFrame class
AssignViewID();
//the denition of AssignViewID()
void CMainFrame::AssignViewID()
{
CEdit3DMDoc* pdoc = (CEdit3DMDoc*)m_pMainView-
>GetDocument();
if(pdoc)
{
POSITION pos = pdoc->GetFirstViewPosition();
CView* pview;
int tempid = 1;