//这个程序运行后,在窗口中央出现一个
//绿色的小三角形,并且不断地旋转
//以下是主应用程序文件
#include "File.h"
#include "math.h"
BEGIN_MESSAGE_MAP(CFileWnd,CFrameWnd) //
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
void CFileWnd::OnPaint()
{
CFrameWnd::OnPaint();
OnShow();
}
CFileWnd::CFileWnd()
{
angle=0;
}
void CFileWnd::OnShow()
{
CClientDC dc(this);
CRect rc;
CPoint poi;
GetClientRect(&rc);
poi.x=GetRand(rc.right);
poi.y=GetRand(rc.bottom);
poi.x=(rc.left+rc.right)/2;
poi.y=(rc.top+rc.bottom)/2;
radius=100;
CRect rc1;
rc1.left=poi.x-radius;
rc1.top=poi.y-radius;
rc1.right=poi.x+radius;
rc1.bottom=poi.y+radius;
for(int i=0;i<3;i++)
{
point[i].x=poi.x-radius*sin(angle);
point[i].y=poi.y-radius*cos(angle);
angle+=2*3.1415926/3;
}
CBrush brush(RGB(120,255,0));
CBrush* oldbrush;
oldbrush=dc.SelectObject(&brush);
dc.SetPolyFillMode(WINDING);
dc.Polygon(point,3);
dc.SelectObject(oldbrush);
ReleaseDC(&dc);
}
int CFileWnd::GetRand(int nRand)
{
float nang=(float)rand()/RAND_MAX;
float nconst=(float)nRand*nang;
return (float)nconst;
}
void CFileWnd::OnTimer(UINT nIDEvent)
{
angle+=2*3.1415926/100;
angle=fmod(angle,2*3.1415926);
Invalidate();
}
BOOL CFileApp::InitInstance()
{
CFileWnd* pFrame=new CFileWnd;
pFrame->Create(0,"coding");
pFrame->ShowWindow(SW_SHOWNORMAL);
pFrame->UpdateData();
pFrame->SetTimer(1,20,NULL);
this->m_pMainWnd=pFrame;
return TRUE;
}
CFileApp theApp;