這鐘表界面我只做了個大概,用MFC建了個單文檔程序,在CMainFram類的PreCreateWindow里加了兩句cs.cx=200; cs.cy=290; 然后在View類的OnDraw函數里面整了一堆代碼:
const CRect rcBounds(10,10,180,180);
const CRect rcInvalid(10,10,180,180);
pDC->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
CPen pen(PS_SOLID,6,RGB(0,122,122));
pDC->SelectObject(&pen);
pDC->Rectangle(rcBounds);
// 顯示Clock里的3、6、9、12這幾個數字
pDC->TextOut(rcBounds.right/2-8,rcBounds.top+rcBounds.bottom/12,12);
pDC->TextOut(rcBounds.right/2-4,rcBounds.bottom-rcBounds.bottom/12-17,6);
pDC->TextOut(rcBounds.left+rcBounds.right/12,rcBounds.bottom/2-4,9);
pDC->TextOut(rcBounds.right-rcBounds.right/12-8,rcBounds.bottom/2-4,3);
然后搞了個當前時間CTime time = CTime::GetCurrentTime();
int nTime_s = time.GetSecond();
int nTime_m = time.GetMinute();
int nTime_h = time.GetHour();
接著定義了幾根指針長度int nLength_S,nLength_M,nLength_H;
if(rcBounds.right < rcBounds.bottom)
{
nLength_S = rcBounds.right/2 - rcBounds.right/7;
nLength_M = rcBounds.right/2 - r
const CRect rcBounds(10,10,180,180);
const CRect rcInvalid(10,10,180,180);
pDC->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
CPen pen(PS_SOLID,6,RGB(0,122,122));
pDC->SelectObject(&pen);
pDC->Rectangle(rcBounds);
// 顯示Clock里的3、6、9、12這幾個數字
pDC->TextOut(rcBounds.right/2-8,rcBounds.top+rcBounds.bottom/12,12);
pDC->TextOut(rcBounds.right/2-4,rcBounds.bottom-rcBounds.bottom/12-17,6);
pDC->TextOut(rcBounds.left+rcBounds.right/12,rcBounds.bottom/2-4,9);
pDC->TextOut(rcBounds.right-rcBounds.right/12-8,rcBounds.bottom/2-4,3);
然后搞了個當前時間CTime time = CTime::GetCurrentTime();
int nTime_s = time.GetSecond();
int nTime_m = time.GetMinute();
int nTime_h = time.GetHour();
接著定義了幾根指針長度int nLength_S,nLength_M,nLength_H;
if(rcBounds.right < rcBounds.bottom)
{
nLength_S = rcBounds.right/2 - rcBounds.right/7;
nLength_M = rcBounds.right/2 - r