参考: 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 ;
* 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 ;
解决方案 »
- LocalFree 时 堆被破坏
- 关于屏幕录像的数据压缩的问题?
- WTL进度条控件
- 为什么我的DllMain中的DLL_PROCESS_ATTACH没有执行?
- CImage 和 Gdi+ Image 各自有缺点,使用哪一个比较好?
- VS2005里面的非托管VC++里的GRID CONTROL 控件去哪里了??
- 请问高手,这个程序为什么有异常呀??
- 一个接受前进后退消息的问题!
- 怎样在已注册为服务的程序中激活图形化的程序??急,在线等!!!!!
- 如何完整消除内存泄漏?
- 关于SECURITY_ATTRIBUTES mciSendString用法
- vc++2010怎么设置路径调用dll时不移动dll
{
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); //绘制渐变色