求解此类vc控件 如图 (急)

www18665346 2012-08-14 05:27:49
颜色渐变的色带 上面可以多点选择
急用 谢谢各位!!!
...全文
312 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
gz_qmc 2012-08-16
  • 打赏
  • 举报
回复
自己写个控件不就得了
www18665346 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
颜色渐变的色带 上面可以多点选择
急用 谢谢各位!!!
[/Quote]
你的代码从哪来的?
wocow3 2012-08-16
  • 打赏
  • 举报
回复
矩形渐变GDI和容易就能实现,你这个只需要划分几个矩形块多次调用GradientFill拼起来即可
dog357 2012-08-16
  • 打赏
  • 举报
回复
绘制渐变色



BOOL CMyButton::DrawGraden(HDC hdc, CONST RECT *pRect, CONST DWORD *cl, int Num, DWORD dwMode)
{
int Width;
int Height;
TRIVERTEX *pvert;
GRADIENT_RECT *pgRect;

if (cl == NULL || Num < 1 || pRect == NULL || dwMode == GRADIENT_FILL_TRIANGLE)
{
::SetLastError(ERROR_INVALID_PARAMETER);
return TRUE;
}

if (Num == 1)
{
HBRUSH hBrush = CreateSolidBrush(cl[0]);
SelectObject(hdc, hBrush);
FillRect(hdc, pRect, hBrush);
DeleteObject(hBrush);
return TRUE;
}

pvert = new TRIVERTEX[Num * 2 - 2];
pgRect = new GRADIENT_RECT[Num];

Width = pRect->right - pRect->left;
Height = pRect->bottom - pRect->top;
for (int i = 0; i < Num - 1; i++)
{
if (dwMode == GRADIENT_FILL_RECT_V)
{
pvert[i * 2].x = pRect->left;
pvert[i * 2].y = pRect->top + Height / (Num - 1) * i;

pvert[i * 2 + 1].x = pRect->right;
pvert[i * 2 + 1].y = pRect->top + Height / (Num - 1) * (i + 1);
}
else if (dwMode == GRADIENT_FILL_RECT_H)
{
pvert[i * 2].x = pRect->left + Width / (Num - 1) * i;
pvert[i * 2].y = pRect->top;

pvert[i * 2 + 1].x = pRect->left + Width / (Num - 1) * (i + 1);
pvert[i * 2 + 1].y = pRect->bottom;
}

pvert[i * 2] .Red = (WORD)GetRValue((cl[i])) << 8;
pvert[i * 2] .Green = (WORD)GetGValue((cl[i])) << 8;
pvert[i * 2] .Blue = (WORD)GetBValue((cl[i])) << 8;
pvert[i * 2] .Alpha = 0x0000;

pvert[i * 2 + 1] .Red = (WORD)GetRValue((cl[i + 1])) << 8;
pvert[i * 2 + 1] .Green = (WORD)GetGValue((cl[i + 1])) << 8;
pvert[i * 2 + 1] .Blue = (WORD)GetBValue((cl[i + 1])) << 8;
pvert[i * 2 + 1] .Alpha = 0x0000;

pgRect[i].UpperLeft = i * 2;
pgRect[i].LowerRight = i * 2 + 1;
}

BOOL bRet = ::GradientFill(hdc, pvert, Num * 2, pgRect, Num - 1, dwMode);

delete []pvert;
delete []pgRect;

return bRet;
}

DrawGraden(dc.GetSafeHdc(), &CRect(rt.left + 1,rt.top + 1, rt.right - 1, rt.bottom), cl, 3, GRADIENT_FILL_RECT_V); //绘制渐变色
MFCJCK 2012-08-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

那个应该是贴的图吧,然后可以点击获取鼠标单击处的颜色
[/Quote]

补充一下,这个就是自绘的控件。
ljmj3256 2012-08-15
  • 打赏
  • 举报
回复
那个应该是贴的图吧,然后可以点击获取鼠标单击处的颜色
schlafenhamster 2012-08-15
  • 打赏
  • 举报
回复
就是用不同的颜色绘颜色条
www18665346 2012-08-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
参考:

C/C++ code

case WM_PAINT: /* Divide client width into equal-sized parts, one per palette
* entry, and re-calculate client width so that it will displ……
[/Quote]
没有直接使用的控件吗?
www18665346 2012-08-15
  • 打赏
  • 举报
回复
其实我还是不懂.....求详细
  • 打赏
  • 举报
回复
可以用GDI+实现
schlafenhamster 2012-08-14
  • 打赏
  • 举报
回复
参考:

case WM_PAINT: /* Divide client width into equal-sized parts, one per palette
* entry, and re-calculate client width so that it will display
* exactly as many vertical bars as there are palette entries. */
GetClientRect(hWnd,(LPRECT) &rClientRect);
nSizeX = (rClientRect.right - rClientRect.left);
nSizeX = (nSizeX/iNumColors) * iNumColors;
nSizeY = rClientRect.bottom - rClientRect.top;
GetWindowRect(hWnd,(LPRECT) &rClientRect);
/* Adjust window width so that it can display exactly
* as many vertical bars( of equal width) as there are palette
* colors. */
SetWindowPos( hWnd,(HWND)NULL, 0, 0, nSizeX + 2*nXBorder, rClientRect.bottom - rClientRect.top,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
hDC = BeginPaint(hWnd, &ps);
/* Select the palette into the window device context and
make the Palette Manager map the logical palette to the
system palette (realize it). */
SelectPalette (hDC,(HPALETTE)hPal, 1);
//could not used !
//n=RealizePalette (hDC);//=0 ??
/* Calculate width of each color bar to be displayed */
nIncr = nSizeX / iNumColors;
/* Paint the individual bars separately on the app. window */
for (nStart = iLoop = 0; iLoop < iNumColors; iLoop++)
{/* Since this app. uses a logical palette, use the
* PALETTEINDEX macro to specify the palette entry
* index instead of using an explicit RGB value. */
hBrush = CreateSolidBrush (PALETTEINDEX (iLoop));
dwPal[iLoop] = GetNearestColor (hDC, PALETTEINDEX (iLoop) );
hOldBrush = (HBRUSH)SelectObject (hDC,hBrush) ;
PatBlt (hDC, nStart, 0, nIncr, nSizeY, PATCOPY);
nStart += nIncr;
SelectObject (hDC, hOldBrush);
DeleteObject (hBrush) ;
}
wsprintf (szTitlebuf, "MyPal Colors= %d", iNumColors);
SetWindowText (hWnd, (LPSTR)szTitlebuf);
EndPaint(hWnd,&ps);
break ;

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧