关闭

MFC 色变:形成有动感的图画

178人阅读 评论(0) 收藏 举报


switch判断老是忘掉写break;也是醉了……)


       CPoint Center(150,150);

int Radius = 100;
double PI = 3.141592653;


CRect rect(Center.x-Radius, Center.y-Radius, Center.x+Radius, Center.y+Radius);


CBrush brush1(RGB(0,0,0));
CBrush brush2(RGB(255,0,0));
CBrush brush3(RGB(0,255,0));
CBrush brush4(RGB(0,0,255));
CBrush *pOldBrush1;
CBrush *pOldBrush2;
CBrush *pOldBrush3;
CBrush *pOldBrush4;

double t = PI/4;
CPoint Start(Center.x-Radius*cos(t),Center.y-Radius*cos(t));
CPoint End1(Center.x-Radius*cos(t),Center.x+Radius*cos(t));
CPoint End2(Center.x+Radius*cos(t),Center.x+Radius*cos(t));
CPoint End3(Center.x+Radius*cos(t),Center.x-Radius*cos(t));


switch( a )
{
case 0:
pOldBrush1=pDC->SelectObject(&brush1);
pDC->Pie(rect,Start,End1);
pDC->SelectObject(pOldBrush1);


pOldBrush2=pDC->SelectObject(&brush2);
pDC->Pie(rect,End1,End2);
pDC->SelectObject(pOldBrush2);


pOldBrush3=pDC->SelectObject(&brush3);
pDC->Pie(rect,End2,End3);
pDC->SelectObject(pOldBrush3);


pOldBrush4=pDC->SelectObject(&brush4);
pDC->Pie(rect,End3,Start);
pDC->SelectObject(pOldBrush4);
break;


case 1:
pOldBrush1=pDC->SelectObject(&brush1);
pDC->Pie(rect,End1,End2);
pDC->SelectObject(pOldBrush1);


pOldBrush2=pDC->SelectObject(&brush2);
pDC->Pie(rect,End2,End3);
pDC->SelectObject(pOldBrush2);


pOldBrush3=pDC->SelectObject(&brush3);
pDC->Pie(rect,End3,Start);
pDC->SelectObject(pOldBrush3);


pOldBrush4=pDC->SelectObject(&brush4);
pDC->Pie(rect,Start,End1);
pDC->SelectObject(pOldBrush4);
break;


case 2:
pOldBrush1=pDC->SelectObject(&brush1);
pDC->Pie(rect,End2,End3);
pDC->SelectObject(pOldBrush1);


pOldBrush2=pDC->SelectObject(&brush2);
pDC->Pie(rect,End3,Start);
pDC->SelectObject(pOldBrush2);


pOldBrush3=pDC->SelectObject(&brush3);
pDC->Pie(rect,Start,End1);
pDC->SelectObject(pOldBrush3);


pOldBrush4=pDC->SelectObject(&brush4);
pDC->Pie(rect,End1,End2);
pDC->SelectObject(pOldBrush4);
break;


case 3:
pOldBrush1=pDC->SelectObject(&brush1);
pDC->Pie(rect,End3,Start);
pDC->SelectObject(pOldBrush1);


pOldBrush2=pDC->SelectObject(&brush2);
pDC->Pie(rect,Start,End1);
pDC->SelectObject(pOldBrush2);


pOldBrush3=pDC->SelectObject(&brush3);
pDC->Pie(rect,End1,End2);
pDC->SelectObject(pOldBrush3);


pOldBrush4=pDC->SelectObject(&brush4);
pDC->Pie(rect,End2,End3);
pDC->SelectObject(pOldBrush4);
break;

}


void CMy1_3View::OnTimer(UINT nIDEvent) 
{

  a=(a+1)%4;


    //此函数使客户区失效,以致重画


       Invalidate();



       CView::OnTimer(nIDEvent);


}


int CMy1_3View::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{


       if (CView::OnCreate(lpCreateStruct) == -1)


                return -1;




SetTimer(1,725,NULL);


return 0;


}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1421次
    • 积分:78
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档