//绘制Logo
{
Font tFont(L"Microsoft Sans Serif", 36, FontStyleBoldItalic);
StringFormat sf;
LPCWSTR wstrLogo = L"Cool";
RectF rectLayer(0,0, 1000, -1), txBound;
graphics.MeasureString(wstrLogo, -1, &tFont, rectLayer, &sf, &txBound);
RectF ts = txBound;
ts.X = (float)(ptCent.x - txBound.Width/2);
ts.Y = (float)(ptCent.y + iMinSize/4 - txBound.Height/2);
SolidBrush txbrush(Color(255, 255, 0));
graphics.DrawString(wstrLogo, -1, &tFont, ts, &sf, &txbrush);
}
//画指针
{
SYSTEMTIME tmNow;
GetLocalTime(&tmNow);
int iSRadio = iMinSize/2-10; //秒针
int iMRadio = iSRadio - 50; //分针
int iHRadio = iMRadio - 30; //时针
//时针
{
Pen sPen(Color(0, 0, 0), 15);
Point s(ptCent.x, ptCent.y), e;
double fTime = tmNow.wHour
+ tmNow.wMinute/60.0
+ tmNow.wSecond/3600.0
+ 0;
double fAng = fPi/2.0 - fTime * (2.0*fPi) /12.0;
e.X = (int)(ptCent.x + iHRadio * cos(fAng));
e.Y = (int)(ptCent.y - iHRadio * sin(fAng));
graphics.DrawLine(&sPen, s, e);
}
//分针
{
Pen sPen(Color(0, 0, 0), 8);
Point s(ptCent.x, ptCent.y), e;
double fTime = tmNow.wMinute
+ tmNow.wSecond/60.0
+ 0;
double fAng = fPi/2.0 - fTime * (2.0*fPi) /60.0;
e.X = (int)(ptCent.x + iMRadio * cos(fAng));
e.Y = (int)(ptCent.y - iMRadio * sin(fAng));
graphics.DrawLine(&sPen, s, e);
}
//秒针
{
Pen sPen(Color(255, 0, 0), 3);
Point s(ptCent.x, ptCent.y), e;
double fTime = tmNow.wSecond
+ tmNow.wMilliseconds/1000.0
+ 0;
double fAng = fPi/2.0 - fTime * (2.0*fPi) /60.0;
e.X = (int)(ptCent.x + iSRadio * cos(fAng));
e.Y = (int)(ptCent.y - iSRadio * sin(fAng));
graphics.DrawLine(&sPen, s, e);
}
}
//中心点
{
RectF rc(ptCent.x - 15.0f, ptCent.y - 15.0f, 30.0f, 30.0f);
SolidBrush brush(Color(255, 0, 0));
graphics.FillEllipse(&brush, rc);
}
//画外圆
{
Rect rc(rcDraw.left + 4, rcDraw.top+4, rcDraw.Width()-8, rcDraw.Height()-8); //按椭圆
//Rect rc(ptCent.x + iSize/2 + 4, ptCent.y - iSize/2+4, iSize/2-8, iSize/2-8); //按圆形
Pen exRound(Color(230, 230, 0, 0), 6);
graphics.DrawEllipse(&exRound, rc);
}
return TRUE;
}
LRESULT CColockStatic::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case(WM_CREATE):
{
if(SetTimer(1, 100, NULL))
{
m_bTimerStarted = -1;
}
break;
}
case(WM_DESTROY):
{
if(m_bTimerStarted)
{
KillTimer(1);
}
break;
}
case(WM_TIMER):
{
Invalidate(TRUE);
break;
}
case(WM_ERASEBKGND):
{
return 1;
}
case(WM_PAINT):
{
CRect rcRect;
GetClientRect(&rcRect);
PAINTSTRUCT ps = {0};
CDC *pDstDC = BeginPaint(&ps);
//双缓冲绘制
CDC memDC, *pDC = &memDC;
pDC->CreateCompatibleDC(pDstDC);
int nSaveDC = pDC->SaveDC();
CBitmap memBmp;
memBmp.CreateCompatibleBitmap(pDstDC, rcRect.Width(), rcRect.Height());
CBitmap *pOldBmp = pDC->SelectObject(&memBmp);
//画钟
DrawClock(pDC->m_hDC, rcRect);
//贴图
pDstDC->BitBlt(rcRect.left, rcRect.top, rcRect.Width(), rcRect.Height(),
pDC,
0, 0,
SRCCOPY);
//结束清理
pDC->SelectObject(pOldBmp);
pDC->RestoreDC(nSaveDC);
EndPaint(&ps);
//启动定时刷新
if(!m_bTimerStarted
&& SetTimer(1, 100, NULL))
{
m_bTimerStarted = -2;
}
return 0;
}
}
return CStatic::WindowProc(message, wParam, lParam);
} |