VC6.0中怎样根据 *** 作在图像控件中显示图片

VC6.0中怎样根据 *** 作在图像控件中显示图片,第1张

这个简单,看代码:
CStatic st=(CStatic)GetDlgItem(IDC_PIC);//IDC_PIC是控件的ID,此处建议将默认的ID(即IDC_STATIC)改成其他的,比如说这里的IDC_PIC
HBITMAP hBitmap=LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1));//加载IDB_BITMAP1
st->SetBitmap(hBitmap);//设置位图显示
以上实现的就是代码控制位图在控件上的显示了,你只要分别在两个单选按钮里加载不同的位图就可以了。

要列出“所有的画图函数”,未免太多了吧,你还是在网上搜一些有关图形设备接口GDI的课件吧!
任何图形程序的输出,都离不开图形设备接口GDI(Graphic Device Interface),它是管理Windows应用程序在窗口内的绘图 *** 作和与此相关的许多其它信息。如图形设备(打印机、显示器)的信息、绘图的坐标系统和映射模式、绘图工具的当前状态(什么样的画笔、画刷、文本的前景色与背景色、文本所使用的字体)。
Windows的GDI绘制的各种图形(点、线、圆、多边形、矩形等)是与设备无关的,即在屏幕的窗口内绘图与在打印机上绘图是相似的。GDI是一个可执行程序,它接收Windows应用程序的绘图请求(表现为GDI调用),并将它们传送给相应的设备驱动程序,再由设备驱动程序驱动相应的硬件设备,如打印机或显示器输出。
1 绘制点与线
1)画点
CDC类的成员函数SetPixel用来在指定位置上绘制一个特定的像素点,其原型为:
COLORREF SetPixel( POINT point, COLORREF crColor );
其中参数point指定所绘制的点,crColor指定画点所用的颜色。
倘若要在屏幕的(100,100)处画一个红色点,则代码为:
pDC-> SetPixel(CPoint(100,100),RGB(255,0,0));
2)画直线
画直线需要LineTo()和MoveTo()两个函数的配合使用。
LineTo()函数以当前位置所在的点为直线的起点,另指定一个点为直线的终点,画出一段直线。直线的颜色通过画笔的颜色来设定,在后面介绍。LineTo()函数原型说明如下:
BOOL CDC:: LineTo(int nXEnd, int nYEnd);
直线的终点位置由(nXEnd, nYEnd)指定。如果函数调用成功,那么该点就成为当前位置,并返回TRUE,否则返回FALSE。
MoveTo()函数只是将当前位置移动到指定位置,它并没有画出直线,其函数说明为:
BOOL CDC:: MoveTo (int X, int Y);
2 绘制封闭图形
1)画矩形
BOOL Rectangle( int x1, int y1, int x2, int y2 );
BOOL Rectangle( LPCRECT lpRect );
此函数成功调用后返回非0值,否则返回0。其中参数(x1,y1)为指定矩形的左上角逻辑x与y坐标;(x2,y2)为指定矩形右下角的逻辑x与y坐标。参数lpRect为一个矩形结构[3]的指针,用它来表示矩形的四个角。
2)画椭圆或圆
使用CDC的成员函数Ellipse,可以使用当前笔绘制一个用当前画刷填充的椭圆或圆。其函数原型如下:
BOOL Ellipse(int x1, int y1, int x2, int y2 );
BOOL Ellipse( LPCRECT lpRect );
这两个函数画椭圆成功后返回非0值,否则返回0。所画椭圆高度为y2-y1,宽度为x2-x1。在该函数中,椭圆是由其外接矩形来确定的。外接矩形的中心与椭圆中心重合,矩形的长和宽和椭圆的长短轴相等。函数中的参数与画矩形的相仿,分别表示椭圆外接矩形的左上角和右下角坐标。
3 画笔与画刷
31 画笔
画笔是绘图的基本工具,在MFC中画笔是CPen类的对象,它用来在DC上完成绘制线条的任务。初始化时,系统自动提供了一支黑色的默认画笔。如果程序设计人员对这个默认的画笔不满意,可以自己创建画笔来替换它。所谓的自定义画笔,就是程序员自己创建的CPen类对象,创建画笔对象是,需要使用CPen类的构造函数,它的原型为:
CPen(Int style,int width ,COLORREF color);
style:画笔的样式
width:画笔的宽度
color:画笔的颜色(颜色用RGB值来描述)
32 画刷
类CBrush封装了Windows图形设备接口(GDI)中的画刷。使用CBrush对象之前要构造它,然后传给需要画刷的CDC成员函数。画刷可以是实线的、阴影线的或图案的。
在进行区域填充或绘制封闭图形时,需要用到画刷。MFC把GDI画刷封装在CBrush类中。画刷分三种基本类型:纯色画刷、阴影画刷和图案画刷。
纯色画刷绘图使用单色来定义,颜色由RGB()函数来确定。纯色画刷可以采用直接声明的方法,例如:
CBrush Brush(RGB(255,0,0)); //创建一个红色画刷。
也可以采用分步方法,由CreateSolidBrush()函数创建。
CBrush Brush;
Brush->Create->CreateSolidBrush(RGB(255,0,0));
Windows预定义了七种画刷,包括:BLACK_BRUSH、 DKGRAY_BRUSH、 GRAY_BRUSH、LTGRAY_BRUSH、HOLLOW_BRUSH、NULL_BRUSH和WHITE_BRUSH。可以参照CPen类的方法,采用CreateStockObject()来使用预定义的画刷。
///////////////////////////////////////////
3)直线
(1)当鼠标左键按下时,需要将鼠标当前按下点保存起来,当鼠标d起时,也需要将d起点保存,因此为CMyGraphicView类添加一个CPoint类型的保护型变量m_ptStart和一个CPoint类型的保护变量m_ptEnd,并在View类构造函数中将其初始化为0。
protected:
UINT m_nDrawType;//保存用户选择的功能
CRect m_rectDraw;//鼠标按下到d起构成的区域
BOOL m_bNeedErase;//是否擦除
CPoint m_ptEnd, m_ptStart;
void CMyGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptStart=point;
CScrollView::OnLButtonDown(nFlags, point);
}
void CMyGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
GetClientRect(&rect);//用来得到客户区域
CClientDC dc(this);
CPen pen;
CPen ptrOldPen;
int nMode;
CMyGraphicDoc ptrDoc;
ptrDoc=(CMyGraphicDoc )GetDocument();//得到Doc类指针
penCreatePen(PS_DOT,1,RGB(0,0,0));//创建画笔
ptrOldPen=dcSelectObject(&pen);
nMode=dcSetROP2(R2_XORPEN);
dcMoveTo(m_ptStart);
dcLineTo(m_ptEnd);
dcSetROP2(nMode);
dcSelectObject(ptrOldPen);
penDeleteObject();
m_ptEnd=point;
ptrDoc->AddLine(CRect(m_ptStartx,m_ptStarty,m_ptEndx,m_ptEndy));
m_bNeedErase=FALSE;
InvalidateRect(rect,FALSE);//刷新客户区
CScrollView::OnLButtonUp(nFlags, point);
}
在OnMouseMove函数中添加如下代码:
if(nFlags&MK_LBUTTON)//如果左键按下且鼠标移动
{
nMode=dcSetROP2(R2_XORPEN);
if(m_bNeedErase==TRUE)
{
dcMoveTo(m_ptStart);
dcLineTo(m_ptEnd);
}
else
{
m_bNeedErase=TRUE;
}
m_ptEnd=point;
dcMoveTo(m_ptStart);
dcLineTo(m_ptEnd);
dcSetROP2(nMode);
dcSelectObject(ptrOldPen);
}
m_ptEnd=point;

#include <stdlibh>

#include <GL/gluth>
#pragma comment(lib,"glut32lib")

//

#if 0
// the points of the curve - these are the same as the bezier curve
// points demonstrated in the bezier curve example

float Points[4][3] = {
{ 10,10,0 },
{ 5,10,2 },
{ -5,0,0 },
{-10,5,-2}
};

#define NUM_POINTS 4

// The following sets of 4 indices are the curves that need to
// be drawn to create a clamped cubic b-spline In total there
// are 5 curve segments to draw
//
// 0 0 0 1
// 0 0 1 2
// 0 1 2 3
// 1 2 3 3
// 2 3 3 3
//
// Remember this when trying to understand knot vectors!!
//

#else

float Points[9][3] = {
{ 10,5,0 },
{ 5,10,0 },
{ -5,15,0 },
{ -10,-5,0 },
{ 4,-4,0 },
{ 10,5,0 },
{ 5,10,0 },
{ -5,15,0 },
{ -10,-5,0 }
};

#define NUM_POINTS 9

//若绘制过首尾控制点的曲线
// 0 0 0 1
// 0 0 1 2
// 0 1 2 3
// 1 2 3 4
// 2 3 4 5
// 3 4 5 6
// 4 5 6 6
// 5 6 6 6
//
// Remember this when trying to understand knot vectors!!
//
//若绘制首尾相接的平滑曲线 ,即为当前绘制
// 0 1 2 3
// 1 2 3 4
// 2 3 4 5
// 3 4 5 6
#endif

// the level of detail for the curve
unsigned int LOD=20;

#define NUM_SEGMENTS (NUM_POINTS-3)
//

float GetPoint(int i)
{
// return 1st point
if (i<0)
{
return Points[0];
}

if (i<NUM_POINTS)
{
return Points[i];
}
// return last point

return Points[NUM_POINTS-1];
}

//------------------------------------------------------------ OnKeyPress()
void myIdle(void)
{
glutPostRedisplay();
}

//------------------------------------------------------------ OnDraw()
void OnDraw()
{
// clear the screen & depth buffer
glClear(GL_COLOR_BUFFER_BIT);
// clear the previous transform
glLoadIdentity();
// set the camera position
// gluLookAt( 1,10,30, // eye pos
// 0,0,0, // aim point
// 0,1,0); // up direction
// glColor3f(05,02,0);
glPointSize(3);
//
// // draw curve hull
glColor3f(03,0,05);
glBegin(GL_LINE_STRIP);
for(int i=0;i!=NUM_POINTS;++i)
{
glVertex3fv( Points[i] );
}
glEnd();

glColor3f(0,1,0);

// begin drawing our curve
glBegin(GL_LINE_STRIP);

for(int start_cv=0,j=0;j<NUM_SEGMENTS;j++,start_cv++)
{
// for each section of curve, draw LOD number of divisions
for(int i=0;i!=LOD;++i)
{
// use the parametric time value 0 to 1 for this curve
// segment
float t = (float)i/LOD;
// the t value inverted
float it = 10f-t;

// calculate blending functions for cubic bspline
float b0 = ititit/60f;
float b1 = (3ttt - 6tt +4)/60f;
float b2 = (-3ttt +3tt + 3t + 1)/60f;
float b3 = ttt/60f;

// calculate the x,y and z of the curve point
float x = b0 GetPoint( start_cv + 0 )[0] +
b1 GetPoint( start_cv + 1 )[0] +
b2 GetPoint( start_cv + 2 )[0] +
b3 GetPoint( start_cv + 3 )[0] ;

float y = b0 GetPoint( start_cv + 0 )[1] +
b1 GetPoint( start_cv + 1 )[1] +
b2 GetPoint( start_cv + 2 )[1] +
b3 GetPoint( start_cv + 3 )[1] ;

float z = b0 GetPoint( start_cv + 0 )[2] +
b1 GetPoint( start_cv + 1 )[2] +
b2 GetPoint( start_cv + 2 )[2] +
b3 GetPoint( start_cv + 3 )[2] ;

// specify the point

glVertex2f( x,y );
}
}

// we need to specify the last point on the curve
//glVertex3fv( Points[NUM_POINTS-1] );
glEnd();

// draw CV's
glBegin(GL_POINTS);
for(int i=0;i!=NUM_POINTS;++i)
{
glVertex3fv( Points[i] );
}
glEnd();

// currently we've been drawing to the back buffer, we need
// to swap the back buffer with the front one to make the image visible
glutSwapBuffers();
}

//------------------------------------------------------------ OnInit()
void OnInit()
{
//glClearColor(1,1,1,0);
}

//------------------------------------------------------------ OnExit()
void OnExit()
{
}
//------------------------------------------------------------ OnReshape()
void OnReshape(int w, int h)
{
// prevents division by zero when minimising window
if (h==0)
{
h=1;
}

// set the drawable region of the window
glViewport(0,0,w,h);
// set up the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// just use a perspective projection
//gluPerspective(45,(float)w/h,01,100);
if(w<=h)
{
glOrtho(-200,200,-200(GLfloat)h/(GLfloat)w,200(GLfloat)h/(GLfloat)w,00,1000);
}
else
{
glOrtho(-200,200,-200(GLfloat)h/(GLfloat)w,200(GLfloat)h/(GLfloat)w,00,1000);
}
// go back to modelview matrix so we can move the objects about
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

//------------------------------------------------------------ main()
int main(int argc,char argv)
{
// initialise glut
glutInit(&argc,argv);
// request a depth buffer, RGBA display mode, and we want double buffering
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
// set the initial window size
glutInitWindowSize(640,480);
// create the window
glutCreateWindow("Clamped B-Spline Curve");
// run our custom initialisation
OnInit();
// set the function to use to draw our scene
glutDisplayFunc(OnDraw);
<a href=">MFC中应该是没带原型按钮类的,需要自己继承CButton然后重写DrawItem函数
那个CButtonST应该就是这样做的。
但是以前经常的做法是画一个圆形的GIF,(GIF可以做成圆的外面透明)然后当用户点击该的时候触发Click事件。

画多边形更容易。
画矩形,这就要求在MouseMove消息响应中有画线、画矩形的相应函数的调用,但正是因为mouse移动的过程中画了很多的线、矩形,所以我们就要在mouse移动的过程中将之前画出的线、矩形消隐掉,才能保证实现了自己所要实现的功能动态画线、画矩形,但又没有产生多余的线和矩形。
在最后的LButtonUp消息响应中,需要将上面的MouseMove消息响应中循环的最后一次中最后所画的临时图形消隐掉,之后根据LButtonUp消息响应中point参数画出最终的图形。

不管画
矩形波
还是什么其他曲线,核心思想都是换算
原始数据
为屏幕
坐标轴
上的坐标位置,下面信息仅供供参考。
画坐标曲线的主要思路是:先找到坐标值中x的最小值minX,最大值maxX。同样取到y的最小值minY,最大值maxY。设图形宽度为width,高度为height,于是对于坐标(x,y)对应到图上的位置是

((x-minX)width/(maxX-minX),(y-minY)height/(maxY-minY))
void
CDrawCoorView::OnDraw(CDC
pDC)
{
CDrawCoorDoc
pDoc
=
GetDocument();
ASSERT_VALID(pDoc);
//
TODO:
add
draw
code
for
native
data
here
//初始化坐标值,一般从数据库取得。这里为了示例方便取得比较简单
const
int
num=10;
float
initX[num]={1,2,3,4,5,6,7,8,9,10};
float
initY[num]={05,2,28,4,56,6,7,94,138,234};
//分别取得X和Y最大值,最小值
float
maxX=initX[0];
float
minX=initX[0];
float
maxY=initY[0];
float
minY=initY[0];
for(int
i=0;i
maxX)
maxX=initX;
if(initX
maxY)
maxY=initY;
if(initY
0)
minX=0;
//如果原点必须在Y轴上,加上下面2行,否则注释掉
if(minY>0)
minY=0;
//确定图象显示大小
int
width=500;
int
height=300;
//确定坐标图四周预留的空白大小
const
int
mytop=10;
const
int
mybottom=40;
const
int
myleft=80;
const
int
myright=50;
//确定X,Y轴每单位显示宽度
float
intervalX=(width-myleft-myright)/(maxX-minX);
float
intervalY=(height-mybottom-mytop)/(maxY-minY);
//绘制曲线。由于绘图坐标的Y轴是向下延升,所以这里每个点的Y值是用
//图象高度减去y值大小。
pDC->MoveTo(int(myleft+(initX[0]-minX)intervalX),
int(height-(mybottom+(initY[0]-minY)intervalY)));
for(i=0;i
LineTo(int(myleft+(initX-minX)intervalX),
int(height-(mybottom+(initY-minY)intervalY)));
}
//绘制X,Y轴
//X轴从图形区域最左端到最右端
float
bottomY=0;
float
leftX=0;
//bottomY表示X轴的y值,leftX表示Y轴的x值
if(minY>0)
bottomY=minY;
if(minX>0)
leftX=minX;
pDC->MoveTo(int(myleft),int(height-(mybottom+(bottomY-minY)intervalY)));
pDC->LineTo(int(width-myright),int(height-(mybottom+(bottomY-minY)intervalY)));
//Y轴从图形区域最底端到最顶端
pDC->MoveTo(int(myleft+(leftX-minX)intervalX),int(height-mybottom));
pDC->LineTo(int(myleft+(leftX-minX)intervalX),int(mytop));
//确定显示刻度个数
const
int
count=5;
//确定每个显示刻度之间的宽度
float
spaceX=(width-myleft-myright)/count;
float
spaceY=(height-mybottom-mytop)/count;
//绘制刻度和刻度值
CString
str;
//X轴
for(i=0;i<=count;i++)
{
strFormat("%1f",minX+i(maxX-minX)/count);
pDC->MoveTo(int(myleft+spaceXi),int(height-(mybottom+(bottomY-minY)intervalY)));
pDC->LineTo(int(myleft+spaceXi),int(height-(mybottom+(bottomY-minY)intervalY+5)));
pDC->TextOut(int(myleft+spaceXi-10),
int(height-(mybottom+(bottomY-minY)intervalY-5)),str);
}
//Y轴
for(i=0;i<=count;i++)
{
strFormat("%1f",minY+i(maxY-minY)/count);
pDC->MoveTo(int(myleft+(leftX-minX)intervalX),int(height-(mybottom+spaceYi)));
pDC->LineTo(int(myleft+(leftX-minXintervalX+5),int(height-(mybottom+spaceYi)));
pDC->TextOut(int(myleft+(leftX-minX)intervalX-30),
int(height-(mybottom+spaceYi+8)),str);
}
//绘制X,Y轴的变量名
pDC->TextOut(width/2,height-20,"时间(h)");
pDC->TextOut(0,height/2,"产量(kg)");
}

#include "stdafxh"
#include "MFCFrame1h"

#include "MFCFrame1Doch"
#include "MFCFrame1Viewh"
#include "PointDialogh"
#include "mathh"
GLUquadricObj objCylinder = gluNewQuadric();

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View

IMPLEMENT_DYNCREATE(CMFCFrame1View, CView)

BEGIN_MESSAGE_MAP(CMFCFrame1View, CView)
//{{AFX_MSG_MAP(CMFCFrame1View)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_COMMAND(IDM_ZIXUAN, OnZixuan)
ON_WM_TIMER()
ON_COMMAND(IDM_ChangDirect, OnChangDirect)
//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View construction/destruction

CMFCFrame1View::CMFCFrame1View()
{
// TODO: add construction code here
this->m_GLPixelIndex = 0;
this->m_hGLContext = NULL;
Angle1=00;
Angle2=300;
Timer=0;
x=00;
z=00;
juli=400;
}

CMFCFrame1View::~CMFCFrame1View()
{
}

BOOL CMFCFrame1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
csstyle |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);

return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View drawing
/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View printing

BOOL CMFCFrame1View::OnPreparePrinting(CPrintInfo pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CMFCFrame1View::OnBeginPrinting(CDC /pDC/, CPrintInfo /pInfo/)
{
// TODO: add extra initialization before printing
}

void CMFCFrame1View::OnEndPrinting(CDC /pDC/, CPrintInfo /pInfo/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View diagnostics

#ifdef _DEBUG
void CMFCFrame1View::AssertValid() const
{
CView::AssertValid();
}

void CMFCFrame1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CMFCFrame1Doc CMFCFrame1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCFrame1Doc)));
return (CMFCFrame1Doc)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCFrame1View message handlers

BOOL CMFCFrame1View::SetWindowPixelFormat(HDC hDC)
{
PIXELFORMATDESCRIPTOR pixelDesc=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|
PFD_DOUBLEBUFFER|PFD_SUPPORT_GDI,
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
};

this->m_GLPixelIndex = ChoosePixelFormat(hDC,&pixelDesc);
if(this->m_GLPixelIndex==0)
{
this->m_GLPixelIndex = 1;
if(DescribePixelFormat(hDC,this->m_GLPixelIndex,sizeof(PIXELFORMATDESCRIPTOR),&pixelDesc)==0)
{
return FALSE;
}
}

if(SetPixelFormat(hDC,this->m_GLPixelIndex,&pixelDesc)==FALSE)
{
return FALSE;
}
return TRUE;
}

int CMFCFrame1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
HWND hWnd = this->GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);
if(this->SetWindowPixelFormat(hDC)==FALSE)
{
return 0;
}
if(this->CreateViewGLContext(hDC)==FALSE)
{
return 0;
}
return 0;
}

BOOL CMFCFrame1View::CreateViewGLContext(HDC hDC)
{
this->m_hGLContext = wglCreateContext(hDC);
if(this->m_hGLContext==NULL)
{//创建失败
return FALSE;
}

if(wglMakeCurrent(hDC,this->m_hGLContext)==FALSE)
{//选为当前RC失败
return FALSE;
}

return TRUE;
}

void CMFCFrame1View::OnDestroy()
{
CView::OnDestroy();

// TODO: Add your message handler code here
if(wglGetCurrentContext()!=NULL)
{
wglMakeCurrent(NULL,NULL);
}
if(this->m_hGLContext!=NULL)
{
wglDeleteContext(this->m_hGLContext);
this->m_hGLContext = NULL;
}

}

void CMFCFrame1View::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
GLsizei width,height;
GLdouble aspect;
width = cx;
height = cy;
if(cy==0)
{
aspect = (GLdouble)width;
}
else
{
aspect = (GLdouble)width/(GLdouble)height;
}

glViewport(0,0,width,height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(400,aspect,50,10000);

}
void CMFCFrame1View::OnDraw(CDC pDC)
{
CMFCFrame1Doc pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPaintDC dc(this);

glClearColor(10,10,10,10);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(00,00,100,00,00,00,00,10,00);
glRotatef(-900,10,00,00);/返回原坐标/
glTranslatef(-30,00,00);
SwapBuffers(dcm_pshdc);
glDrawBuffer (GL_BACK);
glFlush();

}

void CMFCFrame1View::OnZixuan()
{
// TODO: Add your command handler code here
Timer=1;
SetTimer(1,100,NULL);

}

void CMFCFrame1View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CPaintDC dc(this);

if (Timer==1)
{ Angle1=Angle1-1;
Angle2=Angle2-1;
glClearColor(10,10,10,10);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);//
glLoadIdentity();
gluLookAt(00,200,0000000001,00,00,00,00,10,00);
glPushMatrix();
glColor3f(07,07,07);
glTranslatef(00,00,11);
glRotatef(-900,10,00,00);
glutSolidCone(50,00,600,600); /底盘/
glPopMatrix();

glPushMatrix();
glColor3f(00,00,00);
glTranslatef(39,099,10); /刻度/
glRotatef(900,00,10,00);
gluCylinder(objCylinder, 005, 005, 08, 9999, 9);
glPopMatrix();

glPushMatrix();
glColor3f(00,00,00);
glTranslatef(-47,099,10); /刻度/
glRotatef(900,00,10,00);
gluCylinder(objCylinder,005, 005, 08, 9999, 9);
glPopMatrix();

glPushMatrix();
glColor3f(00,00,00);
glTranslatef(00,099,-29); /刻度/
glRotatef(1800,00,10,00);
gluCylinder(objCylinder,005, 005, 08, 9999, 9);
glPopMatrix();

glPushMatrix();
glColor3f(00,00,00);
glTranslatef(00,099,58); /刻度/
glRotatef(1800,00,10,00);
gluCylinder(objCylinder,005, 005,08, 9999, 9);
glPopMatrix();

glPushMatrix();
glColor3f(00,10,00);
glRotatef(450,00,10,00);
glTranslatef(-067,099,07); /时针/
glRotatef(Angle1/129600,00,10,00);
gluCylinder(objCylinder, 007, 002, 25, 9999, 9);
glPopMatrix();

glPushMatrix();
glColor3f(10,00,00);
glTranslatef(00,099,10); /分针/
glRotatef(Angle2/360,00,10,00);
gluCylinder(objCylinder, 005, 002, 35, 9999, 9);
glPopMatrix();
glPushMatrix();
glColor3f(00,00,05);
glTranslatef(00,099,10); /秒针/
glRotatef(Angle1,00,10,00);
gluCylinder(objCylinder, 007, 002, 45, 9999, 9);
glPopMatrix();
SwapBuffers(dcm_pshdc);
glDrawBuffer (GL_BACK);
glFlush();
}

else if(Timer==2)

{ glClearColor(10,10,10,10);
glClear(GL_COLOR_BUFFER_BIT);

if (juli>120)
{
glMatrixMode(GL_MODELVIEW);/建立了从世界坐标系到观察坐标系的转换矩阵/
glLoadIdentity();
gluLookAt(00,80,juli,00,00,00,00,10,00);
juli=juli-01;

glPushMatrix();
glColor3f(00,00,00);
glRotatef(-900,10,00,00);
glutWireCone(400,00,300,300); /画高度为0的圆锥/
glPopMatrix();

glPushMatrix();
glColor3f(10,00,10);
glLineWidth(40);
glTranslatef(40,10,00);
glutWireOctahedron(); /画八面体/
glLineWidth(10);
glPopMatrix();
glPushMatrix();
glColor3f(10,00,10);
glTranslatef(00,11,00);
glRotatef(Angle2,00,10,00);
gluCylinder(objCylinder, 10, 10, 100, 9999, 9); /画壶/
glPopMatrix();

}

else if(juli<=120)
{
Angle2=Angle2+001;
if (Angle2==3600)
Angle2=00;

glMatrixMode(GL_MODELVIEW);/建立了从世界坐标系到观察坐标系的转换矩阵/
glLoadIdentity();

x=120sin(Angle2);
z=120cos(Angle2);
gluLookAt(x,50,z,00,00,00,00,10,00);

glPushMatrix();
glColor3f(00,00,00);
glRotatef(-900,10,00,00);
glutWireCone(400,00,300,300); /画高度为0的圆锥/
glPopMatrix();

glPushMatrix();
glColor3f(10,00,10);
glLineWidth(40);
glTranslatef(40,10,00);
glutWireOctahedron(); /画八面体/
glLineWidth(10);
glPopMatrix();
glPushMatrix();
glColor3f(10,00,10);
glTranslatef(00,11,00);
gluCylinder(objCylinder, 10, 10, 100, 9999, 9);
glPopMatrix();

}
SwapBuffers(dcm_pshdc);
glDrawBuffer (GL_BACK);
glFlush();
}
CView::OnTimer(nIDEvent);
}

void CMFCFrame1View::OnChangDirect()
{
// TODO: Add your command handler code here
Timer=2;
SetTimer(1,100 ,NULL);
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/10533094.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-09
下一篇 2023-05-09

发表评论

登录后才能评论

评论列表(0条)

保存