15,979
社区成员
发帖
与我相关
我的任务
分享
void CGradientArcDlg::HLSGradientTorus(HDC hDC, int OrigX, int OrigY, int InnerR, int OuterR,
COLORREF cStart, COLORREF cEnd, int Degree)
{
KColor c0(cStart); c0.ToHLS();
KColor c1(cEnd); c1.ToHLS();
Degree *=10;
for (int i=0; i<Degree; i++)
{
KColor c;
c.hue = ( c0.hue * (Degree-1-i) + c1.hue * i ) / (Degree-1);
c.lightness = ( c0.lightness * (Degree-1-i) + c1.lightness * i ) / (Degree-1);
c.saturation = ( c0.saturation* (Degree-1-i) + c1.saturation* i ) / (Degree-1);
c.ToRGB();
#if 0
HBRUSH hBrush = CreateSolidBrush(c.GetColorRef());
RECT rect = { x0+i*(x1-x0)/nPart, y0,
x0+(i+1)*(x1-x0)/nPart, y1 };
FillRect(hDC, & rect, hBrush);
DeleteObject(hBrush);
#else
HPEN hpen=CreatePen(PS_SOLID,1,c.GetColorRef());
HPEN old=(HPEN)SelectObject(hDC,hpen);
double Ix=OrigX-InnerR*cos(i*3.1415926/Degree);
double Iy=OrigY-InnerR*sin(i*3.1415926/Degree);
double Ox=OrigX-OuterR*cos(i*3.1415926/Degree);
double Oy=OrigY-OuterR*sin(i*3.1415926/Degree);
MoveToEx(hDC,(int)(Ix+0.5),(int)(Iy+0.5),0);
LineTo(hDC,(int)(Ox+0.5),(int)(Oy+0.5));
SelectObject(hDC,old);
DeleteObject(hpen);
#endif
}
}
void CGradientArcDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
HLSGradientTorus(dc.m_hDC, 350, 250, 100, 108, RGB(0,255,0), RGB(255,0,0), 180);
// CDialog::OnPaint();
}
}