64,648
社区成员
发帖
与我相关
我的任务
分享
void CImgDisplay::DrawItemRect()
{
CDC *pdc = GetDC();
CRect rect;
GetClientRect(&rect);
m_rect[0].left = rect.right - 58;
m_rect[0].top = rect.top + 53;
m_rect[0].right = rect.right - 28;
m_rect[0].bottom = rect.top + 58;
m_dc.FillSolidRect(&m_rect[0],CLR_ITEMRECT);
m_rect[1].left = m_rect[0].left - 5;
m_rect[1].top = m_rect[0].top + 5;
m_rect[1].right = m_rect[0].left;
m_rect[1].bottom = m_rect[0].top + 35;
m_dc.FillSolidRect(&m_rect[1],CLR_ITEMRECT);
m_rect[2].left = m_rect[0].left;
m_rect[2].top = m_rect[0].top + 35;
m_rect[2].right = m_rect[0].right;
m_rect[2].bottom = m_rect[0].bottom + 35;
m_dc.FillSolidRect(&m_rect[2],CLR_CHARRECT);
m_rect[3].left = m_rect[0].right;
m_rect[3].top = m_rect[0].top + 5;
m_rect[3].right = m_rect[0].right + 5;
m_rect[3].bottom = m_rect[0].bottom + 30;
m_dc.FillSolidRect(&m_rect[3],CLR_CHARRECT);
m_rect[4].left = m_rect[0].left - 5;
m_rect[4].top = m_rect[0].top + 40;
m_rect[4].right = m_rect[0].left;
m_rect[4].bottom = m_rect[0].bottom + 65;
m_dc.FillSolidRect(&m_rect[4],CLR_CHARRECT);
m_rect[5].left = m_rect[0].left;
m_rect[5].top = m_rect[0].top + 70;
m_rect[5].right = m_rect[0].right;
m_rect[5].bottom = m_rect[0].bottom + 70;
m_dc.FillSolidRect(&m_rect[5],CLR_CHARRECT);
m_rect[6].left = m_rect[0].right;
m_rect[6].top = m_rect[0].top + 40;
m_rect[6].right = m_rect[0].right + 5;
m_rect[6].bottom = m_rect[0].bottom + 65;
m_dc.FillSolidRect(&m_rect[6],CLR_CHARRECT);
m_rect[7].left = m_rect[0].right + 9;
m_rect[7].top = m_rect[0].top + 70;
m_rect[7].right = m_rect[0].right + 14;
m_rect[7].bottom = m_rect[0].bottom + 70;
m_dc.FillSolidRect(&m_rect[7],CLR_CHARRECT);
//-----------------------------------------
m_rect[8].left = m_rect[0].left - 66;
m_rect[8].top = m_rect[0].top;
m_rect[8].right = m_rect[0].right - 66;
m_rect[8].bottom = m_rect[0].bottom;
m_dc.FillSolidRect(&m_rect[8],CLR_CHARRECT);
m_rect[9].left = m_rect[8].left - 5;
m_rect[9].top = m_rect[8].top + 5;
m_rect[9].right = m_rect[8].left;
m_rect[9].bottom = m_rect[8].top + 35;
m_dc.FillSolidRect(&m_rect[9],CLR_ITEMRECT);
m_rect[10].left = m_rect[8].left;
m_rect[10].top = m_rect[8].top + 35;
m_rect[10].right = m_rect[8].right;
m_rect[10].bottom = m_rect[8].bottom + 35;
m_dc.FillSolidRect(&m_rect[10],CLR_CHARRECT);
m_rect[11].left = m_rect[8].right;
m_rect[11].top = m_rect[8].top + 5;
m_rect[11].right = m_rect[8].right + 5;
m_rect[11].bottom = m_rect[8].bottom + 30;
m_dc.FillSolidRect(&m_rect[11],CLR_CHARRECT);
m_rect[12].left = m_rect[8].left - 5;
m_rect[12].top = m_rect[8].top + 40;
m_rect[12].right = m_rect[8].left;
m_rect[12].bottom = m_rect[8].bottom + 65;
m_dc.FillSolidRect(&m_rect[12],CLR_CHARRECT);
m_rect[13].left = m_rect[8].left;
m_rect[13].top = m_rect[8].top + 70;
m_rect[13].right = m_rect[8].right;
m_rect[13].bottom = m_rect[8].bottom + 70;
m_dc.FillSolidRect(&m_rect[13],CLR_CHARRECT);
m_rect[14].left = m_rect[8].right;
m_rect[14].top = m_rect[8].top + 40;
m_rect[14].right = m_rect[8].right + 5;
m_rect[14].bottom = m_rect[8].bottom + 65;
m_dc.FillSolidRect(&m_rect[14],CLR_CHARRECT);
m_rect[15].left = m_rect[8].right + 9;
m_rect[15].top = m_rect[8].top + 70;
m_rect[15].right = m_rect[8].right + 14;
m_rect[15].bottom = m_rect[8].bottom + 70;
m_dc.FillSolidRect(&m_rect[15],CLR_CHARRECT);
//....
}
void CImgDisplay::DrawItemRect()
{
CDC *pdc = GetDC();
CRect rect;
GetClientRect(&rect);
RECT roffset[] =
{
{-5, 5, 0, 35},
{0, 35, 0, 35},
{0, 5, 5, 30},
{-5, 40, 0, 65},
{0, 70, 0, 70},
{0, 40, 5, 65},
{9, 70, 14, 70},
};
RECT rbase[] =
{
{-58 + rect.left, 53 + rect.top, -28 + rect.right, 58 + rect.bottom},
{-66 + rbase[0].left, 0 + rbase[0].top, -66 + rbase[0].right, 0 + rbase[0].bottom},
};
for(int j = 0; j < 2; ++j)
{
for(int i = 0; i < 7; ++i)
{
RECT rtmp = {rbase[j].left + roffset[i].left, rbase[j].top + roffset[i].top,
rbase[j].right + roffset[i].right, rbase[j].bottom + roffset[i].bottom};
CRect r = rtmp;
m_dc.FillSolidRect(&r,CLR_ITEMRECT);
}
}
//....
}
void CImgDisplay::DrawItemRect()
{
CDC *pdc = GetDC();
CRect rect;
GetClientRect(&rect);
//填表式编程:(再一次体现出C/C++的强大!)
m_rect[ 0].left= rect .right-58;m_rect[ 0].top= rect .top+53;m_rect[ 0].right= rect .right-28;m_rect[ 0].bottom= rect .top +58;m_dc.FillSolidRect(&m_rect[ 0],CLR_ITEMRECT);
m_rect[ 1].left=m_rect[0].left - 5;m_rect[ 1].top=m_rect[0].top+ 5;m_rect[ 1].right=m_rect[0].left ;m_rect[ 1].bottom=m_rect[0].top +35;m_dc.FillSolidRect(&m_rect[ 1],CLR_ITEMRECT);
m_rect[ 2].left=m_rect[0].left ;m_rect[ 2].top=m_rect[0].top+35;m_rect[ 2].right=m_rect[0].right ;m_rect[ 2].bottom=m_rect[0].bottom+35;m_dc.FillSolidRect(&m_rect[ 2],CLR_CHARRECT);
m_rect[ 3].left=m_rect[0].right ;m_rect[ 3].top=m_rect[0].top+ 5;m_rect[ 3].right=m_rect[0].right+5 ;m_rect[ 3].bottom=m_rect[0].bottom+30;m_dc.FillSolidRect(&m_rect[ 3],CLR_CHARRECT);
m_rect[ 4].left=m_rect[0].left - 5;m_rect[ 4].top=m_rect[0].top+40;m_rect[ 4].right=m_rect[0].left ;m_rect[ 4].bottom=m_rect[0].bottom+65;m_dc.FillSolidRect(&m_rect[ 4],CLR_CHARRECT);
m_rect[ 5].left=m_rect[0].left ;m_rect[ 5].top=m_rect[0].top+70;m_rect[ 5].right=m_rect[0].right ;m_rect[ 5].bottom=m_rect[0].bottom+70;m_dc.FillSolidRect(&m_rect[ 5],CLR_CHARRECT);
m_rect[ 6].left=m_rect[0].right ;m_rect[ 6].top=m_rect[0].top+40;m_rect[ 6].right=m_rect[0].right+5 ;m_rect[ 6].bottom=m_rect[0].bottom+65;m_dc.FillSolidRect(&m_rect[ 6],CLR_CHARRECT);
m_rect[ 7].left=m_rect[0].right+ 9;m_rect[ 7].top=m_rect[0].top+70;m_rect[ 7].right=m_rect[0].right+14;m_rect[ 7].bottom=m_rect[0].bottom+70;m_dc.FillSolidRect(&m_rect[ 7],CLR_CHARRECT);
m_rect[ 8].left=m_rect[0].left -66;m_rect[ 8].top=m_rect[0].top ;m_rect[ 8].right=m_rect[0].right-66;m_rect[ 8].bottom=m_rect[0].bottom ;m_dc.FillSolidRect(&m_rect[ 8],CLR_CHARRECT);
m_rect[ 9].left=m_rect[8].left - 5;m_rect[ 9].top=m_rect[8].top+ 5;m_rect[ 9].right=m_rect[8].left ;m_rect[ 9].bottom=m_rect[8].top +35;m_dc.FillSolidRect(&m_rect[ 9],CLR_ITEMRECT);
m_rect[10].left=m_rect[8].left ;m_rect[10].top=m_rect[8].top+35;m_rect[10].right=m_rect[8].right ;m_rect[10].bottom=m_rect[8].bottom+35;m_dc.FillSolidRect(&m_rect[10],CLR_CHARRECT);
m_rect[11].left=m_rect[8].right ;m_rect[11].top=m_rect[8].top+ 5;m_rect[11].right=m_rect[8].right+5 ;m_rect[11].bottom=m_rect[8].bottom+30;m_dc.FillSolidRect(&m_rect[11],CLR_CHARRECT);
m_rect[12].left=m_rect[8].left - 5;m_rect[12].top=m_rect[8].top+40;m_rect[12].right=m_rect[8].left ;m_rect[12].bottom=m_rect[8].bottom+65;m_dc.FillSolidRect(&m_rect[12],CLR_CHARRECT);
m_rect[13].left=m_rect[8].left ;m_rect[13].top=m_rect[8].top+70;m_rect[13].right=m_rect[8].right ;m_rect[13].bottom=m_rect[8].bottom+70;m_dc.FillSolidRect(&m_rect[13],CLR_CHARRECT);
m_rect[14].left=m_rect[8].right ;m_rect[14].top=m_rect[8].top+40;m_rect[14].right=m_rect[8].right+5 ;m_rect[14].bottom=m_rect[8].bottom+65;m_dc.FillSolidRect(&m_rect[14],CLR_CHARRECT);
m_rect[15].left=m_rect[8].right+ 9;m_rect[15].top=m_rect[8].top+70;m_rect[15].right=m_rect[8].right+14;m_rect[15].bottom=m_rect[8].bottom+70;m_dc.FillSolidRect(&m_rect[15],CLR_CHARRECT);
//....
}
struct B
{
CRect re;
bool bVisible;
};
class A
{
public:
B m_Rect[7];
CPoint pt;
void Draw(CDC* pDC,int Num,CPoint point);
protected:
void InitRect(int Num);
};
void A::Draw(CDC* pDC,int Num,CPoint point)
{
int i;
for(i=0;i<7;i++)
{
if(m_Rect[i].bVisible)
{
pDC->FillSolidRect(&m_Rect[i].re,RGB(0,0,0));
}
}
}
void A::InitRect(int Num)
{
int i;
for(i=0;i<7;i++)
{
m_Rect[i].bVisible=true;
}
m_Rect[0].re.SetRect(pt.x,pt.y,pt.x+3,pt.y+10);
m_Rect[1].re.SetRect(pt.x,pt.y+11,pt.x+3,pt.y+21);
m_Rect[2].re.SetRect(pt.x+4,pt.y+18,pt.x+8,pt.y+21);
m_Rect[3].re.SetRect(pt.x+9,pt.y+11,pt.x+12,pt.y+21);
m_Rect[4].re.SetRect(pt.x+9,pt.y,pt.x+12,pt.y+10);
m_Rect[5].re.SetRect(pt.x+4,pt.y,pt.x+8,pt.y+3);
m_Rect[6].re.SetRect(pt.x+4,pt.y+9,pt.x+8,pt.y+12);
if(Num==0)
{
m_Rect[6].bVisible=false;
}
else if(Num==1)
{
m_Rect[0].bVisible=false;
m_Rect[1].bVisible=false;
m_Rect[2].bVisible=false;
m_Rect[5].bVisible=false;
m_Rect[6].bVisible=false;
}
else if(Num==2)
{
m_Rect[0].bVisible=false;
m_Rect[3].bVisible=false;
}
else if(Num==3)
{
m_Rect[0].bVisible=false;
m_Rect[1].bVisible=false;
}
else if(Num==4)
{
m_Rect[2].bVisible=false;
m_Rect[5].bVisible=false;
}
else if(Num==5)
{
m_Rect[1].bVisible=false;
m_Rect[4].bVisible=false;
}
else if(Num==6)
{
m_Rect[4].bVisible=false;
}
else if(Num==7)
{
m_Rect[0].bVisible=false;
m_Rect[1].bVisible=false;
m_Rect[2].bVisible=false;
m_Rect[6].bVisible=false;
}
else if(Num==8)
{
}
else if(Num==9)
{
m_Rect[1].bVisible=false;
}
else
{
for(i=0;i<7;i++)
{
m_Rect[i].bVisible=false;
}
}
}
m_rect[1].left = m_rect[0].left - 5;
// 把后面的常数存放到数组里面,然后用循环赋值.