请各位帮忙,用VC画出表的形状,(这个是不是很难啊?反正我是一点也不懂,上面的图是我用 画图软件画的,很难看)
要求:
1.指针必须能动,而且成关系,(秒针1圈分针一个格,时针....)
2.当窗口变化是表盘依旧完整且成比例
3.(据老师要求,要在OnDraw中实现?)
4.谢谢!
5.电子邮箱:zyqd06@126.com
6.再次感谢!
真不好意思,我的程序太大了4M多,因为里面还有其它功能.
没办法了.巾段程序吧.
void CFill_areaView::myShowColok(CDC *pDC)
{
m_time=CTime::GetCurrentTime();
pDC->FillRect(&CRect(0,0,rect.Width(),rect.Height()),&CBrush(RGB(100,100,100)));
CBrush brush(RGB(150,150,150));
CBrush *oldbrush=pDC->SelectObject(&brush);
CPen pen(PS_SOLID,3,RGB(0,0,0));
CPen *oldpen=pDC->SelectObject(&pen);
pDC->Ellipse(&CRect(rect.Width()/2-(rect.Height()/2-10)/2,rect.Height()/2-(rect.Height()/2-10)/2,rect.Width()/2+(rect.Height()/2-10)/2,rect.Height()/2+(rect.Height()/2-10)/2));
pDC->Ellipse(&CRect(rect.Width()/2-3,rect.Height()/2-3,rect.Width()/2+3,rect.Height()/2+3));
CPen pen2(PS_SOLID,7,RGB(0,0,0));
pDC->SelectObject(&pen2);
pDC->MoveTo(rect.Width()/2,rect.Height()/2-16*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2-15*(rect.Height()/2-10)/20,rect.Height()/2-6*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2-15*(rect.Height()/2-10)/20,rect.Height()/2+12*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2+15*(rect.Height()/2-10)/20,rect.Height()/2+12*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2+15*(rect.Height()/2-10)/20,rect.Height()/2-6*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2,rect.Height()/2-16*(rect.Height()/2-10)/20);
pDC->MoveTo(rect.Width()/2-15*(rect.Height()/2-10)/20+25,rect.Height()/2+12*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2-15*(rect.Height()/2-10)/20+25,rect.Height()/2+12*(rect.Height()/2-10)/20+30);
pDC->LineTo(rect.Width()/2-15*(rect.Height()/2-10)/20+25+40,rect.Height()/2+12*(rect.Height()/2-10)/20+30);
pDC->LineTo(rect.Width()/2-15*(rect.Height()/2-10)/20+25+40,rect.Height()/2+12*(rect.Height()/2-10)/20);
pDC->MoveTo(rect.Width()/2+15*(rect.Height()/2-10)/20-25,rect.Height()/2+12*(rect.Height()/2-10)/20);
pDC->LineTo(rect.Width()/2+15*(rect.Height()/2-10)/20-25,rect.Height()/2+12*(rect.Height()/2-10)/20+30);
pDC->LineTo(rect.Width()/2+15*(rect.Height()/2-10)/20-25-40,rect.Height()/2+12*(rect.Height()/2-10)/20+30);
pDC->LineTo(rect.Width()/2+15*(rect.Height()/2-10)/20-25-40,rect.Height()/2+12*(rect.Height()/2-10)/20);
CPen pen1(PS_SOLID,1,RGB(0,0,0));
pDC->SelectObject(&pen1);
double alpha=0;
myPoint p1,p2,p3;
p1=m_pointColok[0],p2=m_pointColok[4],p3=m_pointColok[5];
for(int i=0;i<=60;i++)
{
alpha=i*6*pi/180;
p1.x=m_pointColok[0].x*cos(alpha)-m_pointColok[0].y*sin(alpha);
p1.y=m_pointColok[0].x*sin(alpha)+m_pointColok[0].y*cos(alpha);
pDC->MoveTo(ChangePoint(p1).x,ChangePoint(p1).y);
p2.x=m_pointColok[4].x*cos(alpha)-m_pointColok[4].y*sin(alpha);
p2.y=m_pointColok[4].x*sin(alpha)+m_pointColok[4].y*cos(alpha);
p3.x=m_pointColok[5].x*cos(alpha)-m_pointColok[5].y*sin(alpha);
p3.y=m_pointColok[5].x*sin(alpha)+m_pointColok[5].y*cos(alpha);
if(i%5==0)
pDC->LineTo(ChangePoint(p2).x,ChangePoint(p2).y);
else
pDC->LineTo(ChangePoint(p3).x,ChangePoint(p3).y);
pDC->SetBkMode(TRANSPARENT);
CFont font;
font.CreateFont(16,12,0,0,FW_NORMAL,FALSE,FALSE,FALSE,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"Arial");
CFont *oldfont=pDC->SelectObject(&font); //改变字体
pDC->SetTextColor(RGB(255,205,100));
pDC->TextOut(rect.Width()/2-0.9*(rect.Height()/2-10)/2,rect.Height()/2-5,"9");
pDC->TextOut(rect.Width()/2+0.9*(rect.Height()/2-30)/2,rect.Height()/2-5,"3");
pDC->TextOut(rect.Width()/2-10,rect.Height()/2-0.9*(rect.Height()/2-10)/2,"12");
pDC->TextOut(rect.Width()/2-10,rect.Height()/2+0.9*(rect.Height()/2-10)/2-10,"6");
CFont font1;
font1.CreateFont(10,8,0,0,FW_NORMAL,FALSE,FALSE,FALSE,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"Arial");
pDC->SelectObject(&font1); //改变字体
pDC->SetBkColor(RGB(255,0,0));
pDC->TextOut(rect.Width()/2-0.2*(rect.Height()/2-10)/2,rect.Height()/2+0.2*(rect.Height()/2-10)/2,"REDOR1");
pDC->TextOut(rect.Width()/2-0.1*(rect.Height()/2-10)/2,rect.Height()/2-0.7*(rect.Height()/2-10)/2,"DOC");
pDC->SelectObject(oldfont);
}////////////////////画表盘
////////////指针
p1.x=m_pointColok[1].x*cos(jiao1)-m_pointColok[1].y*sin(jiao1);
p1.y=m_pointColok[1].x*sin(jiao1)+m_pointColok[1].y*cos(jiao1);
p2.x=m_pointColok[2].x*cos(jiao2)-m_pointColok[2].y*sin(jiao2);
p2.y=m_pointColok[2].x*sin(jiao2)+m_pointColok[2].y*cos(jiao2);
p3.x=m_pointColok[3].x*cos(jiao3)-m_pointColok[3].y*sin(jiao3);
p3.y=m_pointColok[3].x*sin(jiao3)+m_pointColok[3].y*cos(jiao3);
myBiaoZhen(pDC,p1, RGB(255,0,0),1);
myBiaoZhen(pDC,p2,RGB(255,255,0),1);
myBiaoZhen(pDC,p3,RGB(0,0,255),1);
pDC->SelectObject(oldbrush);
pDC->SelectObject(oldpen);
CFont font1;
font1.CreateFont(24,20,0,0,FW_NORMAL,FALSE,FALSE,FALSE,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,"Arial");
CFont *oldfont1=pDC->SelectObject(&font1); //改变字体
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(200,0,0));
pDC->TextOut(50,30,"时钟模拟:");
CString str1=m_time.Format("%H:%M:%S ");
pDC->TextOut(rect.Width()-200,20,str1);
pDC->SelectObject(oldfont1);
}
void CFill_areaView::InitColok()
{
m_pointColok[0].x=0;
m_pointColok[0].y=10;
m_pointColok[1].x=0;
m_pointColok[1].y=8.7;
m_pointColok[2].x=0;
m_pointColok[2].y=6;
m_pointColok[3].x=0;
m_pointColok[3].y=5;
m_pointColok[4].x=0;
m_pointColok[4].y=9;
m_pointColok[5].x=0;
m_pointColok[5].y=9.5;
}
void CFill_areaView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1){
jiao1 =-(double)m_time.GetHour()*60*60*6*pi/180-(double)m_time.GetMinute()*60*6*pi/180-(double)m_time.GetSecond()*6*pi/180-6*pi/180;
jiao2=(-(double)m_time.GetMinute()-(double)m_time.GetSecond()/60)*6*pi/180;
sndPlaySound ("c:\sound\music.wav",SND_ASYNC);
jiao3=-((double)m_time.GetHour()+(double)m_time.GetMinute()/60+(double)m_time.GetSecond()/3600)*30*pi/180;
InvalidateRect(&CRect(rect.Width()/2-0.85*(rect.Height()/2-10)/2,rect.Height()/2-0.85*(rect.Height()/2-10)/2,rect.Width()/2+0.85*(rect.Height()/2-10)/2,rect.Height()/2+0.85*(rect.Height()/2-10)/2),TRUE);
InvalidateRect(&CRect(rect.Width()-250,10,rect.Width(),60),TRUE);
}
if(nIDEvent==2){
ds--;
InvalidateRect(&CRect(rect.Width()/2-250,ds-2,rect.Width()/2+250,ds+2),TRUE);
}
CView::OnTimer(nIDEvent);
}
void CFill_areaView::myBiaoZhen(CDC *pDC, myPoint point, COLORREF color, int i)
{
CPen pen(PS_SOLID,i,color);
CPen *oldpen=pDC->SelectObject(&pen);
pDC->MoveTo(rect.Width()/2,rect.Height()/2);
pDC->LineTo(ChangePoint(point).x,ChangePoint(point).y);
pDC->SelectObject(oldpen);
}
大体就用到上面三个函数.用到的变量你看着加吧.
呵呵.附件是效果.