📄 eblistview.c
字号:
dy = (pLVInternalData->nItemHeight - ((PBITMAP*)(psubitem->iImage))[0]->bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,
0,0,((PBITMAP*)(psubitem->iImage))[0]);
}
else
{
dy = (pLVInternalData->nItemHeight - ((PBITMAP*)(psubitem->iImage))[1]->bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,0,0,
((PBITMAP*)(psubitem->iImage))[1]);
}
}
}
return;
case ELV_BMPFILE:
{
BITMAP bmp;
char bmpfile[MAX_PATH+1];
memset(&bmp,0,sizeof(BITMAP));
bmpfile[0] = 0;
if(psubitem->iImage)
{
char * tmpfile,*str1;
tmpfile = (char *)(psubitem->iImage);
if (dwStyle & ELVS_TYPE2STATE)//2// 2?
{
if (!pItem->bMouseOver)
PrefixFileName(tmpfile, "nm", bmpfile, MAX_PATH);
else
PrefixFileName(tmpfile, "ov", bmpfile, MAX_PATH);
}
else
{
if (!pItem->bSelected)
{
if (!pItem->bMouseOver)
PrefixFileName(tmpfile, "nm", bmpfile, MAX_PATH);
else
PrefixFileName(tmpfile, "ov", bmpfile, MAX_PATH);
}
else
PrefixFileName(tmpfile, "st", bmpfile, MAX_PATH);
}
if(!LoadBitmap( HDC_SCREEN, &bmp, bmpfile))
{
// dy = (pLVInternalData->nItemHeight - bmp.bmHeight)/2;
dy = (pLVInternalData->nItemHeight -pLVInternalData->nItemGap - bmp.bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,0,0,&bmp);
UnloadBitmap(&bmp);
}
}
else
break;
}
return;
case ELV_ICON:
{
if(!pLVInternalData->nBKImage)
break;
if(dwStyle &ELVS_TYPE3STATE)
{
if (!pItem->bSelected)
{
if(!pItem->bMouseOver)
DrawIcon(hdc,x+2, y + pLVInternalData->nHeadHeight+2,0,0,
((HICON*)(psubitem->iImage))[0]);
else
DrawIcon(hdc,x+2, y + pLVInternalData->nHeadHeight+2,0,0,
((HICON*)(psubitem->iImage))[1]);
}
else
DrawIcon(hdc,x+2, y + pLVInternalData->nHeadHeight+2,0,0,
((HICON*)(psubitem->iImage))[2]);
}
else
{
if (!pItem->bSelected)
DrawIcon(hdc,x+2, y + pLVInternalData->nHeadHeight+2,0,0,
((HICON*)(psubitem->iImage))[0]);
else
DrawIcon(hdc,x+2, y + pLVInternalData->nHeadHeight+2,0,0,
((HICON*)(psubitem->iImage))[1]);
}
}
return;
case ELV_BOTH:
{
BITMAP bmp;
memset(&bmp,0,sizeof(BITMAP));
if(psubitem->iImage)
{
if(!LoadBitmap( HDC_SCREEN, &bmp, (char *)(psubitem->iImage)))
{
dy = (pLVInternalData->nItemHeight - bmp.bmHeight)/2;
FillBoxWithBitmap(hdc,x+2, y + pLVInternalData->nHeadHeight+dy,0,0,&bmp);
UnloadBitmap(&bmp);
}
}
}
break;
default:
break;
}
/*FillBox (hdc, x, y + pLVInternalData->nHeadHeight,
sGetSubItemWidth (nCols, pLVInternalData),
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
SetBrushColor (hdc, nOldBrushColor);
*/
if (psubitem->pszText != NULL)
{
if (dwStyle & ELVS_TYPE2STATE)//2// 2态
{
if(!pItem->bMouseOver)
{
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
temp2 = SetBkColor (hdc, pLVInternalData->nItemBKColor);
temp1 = SetTextColor (hdc, pItem->nTextColor);
}
else
{
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nMouseOverBkColor);
temp2 = SetBkColor (hdc, pLVInternalData->nMouseOverBkColor);
temp1 = SetTextColor (hdc, pLVInternalData->nMouseOverTextColor);
}
}
else if ((dwStyle & ELVS_TYPE3STATE)||(dwStyle & ELVS_SPECIAL2STATE) ) //3// 3态 or 特殊2态
{
if (!pItem->bSelected)
{
//if(!(dwStyle &ELVS_TYPE3STATE) || !(dwStyle &ELVS_TYPE2STATE) ||(!pItem->bMouseOver))
if(!pItem->bMouseOver)
{
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
temp2 = SetBkColor (hdc, pLVInternalData->nItemBKColor);
temp1 = SetTextColor (hdc, pItem->nTextColor);
}
else
{
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nMouseOverBkColor);
temp2 = SetBkColor (hdc, pLVInternalData->nMouseOverBkColor);
temp1 = SetTextColor (hdc, pLVInternalData->nMouseOverTextColor);
}
}
else
{
temp2 = SetBkColor (hdc, pLVInternalData->nSelectBKColor);
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nSelectBKColor);
temp1 = SetTextColor (hdc, pLVInternalData->nSelectTextColor);
}
}
else
{
nOldBrushColor = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
temp2 = SetBkColor (hdc, pLVInternalData->nItemBKColor);
temp1 = SetTextColor (hdc, pItem->nTextColor);
}
//add by tjb 2004-5-26
if (dwStyle & ELVS_MULTILINE)
uFormat = DT_VCENTER | DT_LEFT;
else
uFormat = DT_SINGLELINE | DT_VCENTER | DT_LEFT;
temp3 = SetBkMode(hdc,BM_TRANSPARENT);
i = sGetSubItemWidth (nCols, pLVInternalData);
GetTextExtent (hdc, psubitem->pszText, -1, &size);
if(!(dwStyle &ELVS_MULTILINE))
{
rect.left = x + 2;
rect.right = x + i - 2;
//rect.top = y + pLVInternalData->nHeadHeight + 2 +
// (pLVInternalData->nItemHeight-pLVInternalData->nItemGap-size.cy-2)/2;
//搞不懂为什么会在y方向偏差4个象素,解:因为字体的问题,字体的字在其显示区域偏上偏左,导致
//下面留下很大空间,把temp3 = SetBkMode(hdc,BM_TRANSPARENT);注释掉,就能看出为什么在y方向上偏移了
//4个象素
rect.top = y + pLVInternalData->nHeadHeight+(pLVInternalData->nItemHeight-pLVInternalData->nItemGap-size.cy)/2;
rect.bottom =
y + pLVInternalData->nHeadHeight + pLVInternalData->nItemHeight -pLVInternalData->nItemGap-(pLVInternalData->nItemHeight-pLVInternalData->nItemGap-size.cy)/2;
}
else
{
rect.left = x + 2;
// rect.right = x + 2 + size.cx;
rect.right = x + i -2;
rect.top = y + pLVInternalData->nHeadHeight + 2;
rect.bottom =y + pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nItemGap;
}
if (i > size.cx)
{
//edit by tjb 2004-3-8
//printf("___DEBUG sDrawTextToSubItem draw text2 !\n");
//printf("__DEBUG pLVInternalData->nItemHeight=%d,pLVInternalData->nItemGap=%d.\n",pLVInternalData->nItemHeight,pLVInternalData->nItemGap);
//printf("__DEBUG rect.left=%d,rect.right=%d,rect.top=%d,rect.bottom=%d.\n",rect.left,rect.right,rect.top,rect.bottom);
//DrawText (hdc, psubitem->pszText, -1, &rect, DT_SINGLELINE | DT_VCENTER |DT_CENTER);
if(psubitem->worddata == NULL)
{
DrawText (hdc, psubitem->pszText, -1, &rect, uFormat);
//TextOut(hdc,rect.left,rect.top+2,psubitem->pszText);
}
else
{
if(psubitem->worddata->wordfont &SUBITEM_WORD_NORMALFONT)
{
TextOut(hdc,x+psubitem->worddata->leftoffset,y+pLVInternalData->nHeadHeight+psubitem->worddata->topoffset,psubitem->pszText);
}
else if(psubitem->worddata->wordfont &SUBITEM_WORD_SHADOWFONT)
{
SetBkMode(hdc,BM_TRANSPARENT);
printf("____________DEBUF SUBITEM_WORD_SHADOWFONT.\n");
temp4 = SetTextColor (hdc, psubitem->worddata->shadowcolor);
TextOut(hdc,x+psubitem->worddata->leftoffset+2,y+pLVInternalData->nHeadHeight+psubitem->worddata->topoffset+2,psubitem->pszText);
SetTextColor (hdc, temp4);
TextOut(hdc,x+psubitem->worddata->leftoffset,y+pLVInternalData->nHeadHeight+psubitem->worddata->topoffset,psubitem->pszText);
}
}
}
else
{
pos_char = (int *) malloc (sizeof (int) * strlen (psubitem->pszText));
dx_char = (int *) malloc (sizeof (int) * strlen (psubitem->pszText));
GetTextExtent (hdc, "...", -1, &size);
GetTextExtentPoint (hdc,
psubitem->pszText, strlen (psubitem->pszText), i - 4 - size.cx,
&fit_char, pos_char, dx_char, &size);
rect.left = x + 2;
rect.right = x + 2 + size.cx;
rect.top = y + pLVInternalData->nHeadHeight + 2;
rect.bottom =y + pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nItemGap;
//edit by tjb 2004-3-8
//printf("___DEBUG sDrawTextToSubItem draw text !\n");
//DrawText (hdc, psubitem->pszText, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);//DT_LEFT
DrawText (hdc, psubitem->pszText, -1, &rect, uFormat);
/*if(strlen(psubitem->pszText)>0)
{
TextOut(hdc,rect.left,rect.top+2,psubitem->pszText);
}*/
//end edit
if (!(dwStyle & ELVS_MULTILINE))//若是多行,则不用显示省略号
{
rect1.left = x + 2;
rect1.right = x + i - 2;
rect1.top = y + pLVInternalData->nHeadHeight + 2;
rect1.bottom =y + pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nItemGap;;
DrawText (hdc, "...", -1, &rect1, DT_SINGLELINE | DT_RIGHT);
}
free (pos_char);
free (dx_char);
}
SetTextColor (hdc, temp1);
SetBkColor (hdc, temp2);
SetBrushColor (hdc, nOldBrushColor);
SetBkMode(hdc,temp3);
}
}
//画项的背景
static void lvDrawItemBK(HWND hwnd, HDC hdc, PEBITEMDATA pitem, int rows, DWORD pbitmap)
{
RECT rcClient;
int temp;
DWORD dwStyle = GetWindowStyle (hwnd);
PEBLSTVWDATA pLVInternalData = (PEBLSTVWDATA) GetWindowAdditionalData2 (hwnd);
GetClientRect (hwnd, &rcClient);
if(pbitmap)
{
if((dwStyle & ELVS_ITEMBKMASK) == ELVS_ITEMBKICON)
{
}
else
{
if(dwStyle & ELVS_TYPE3STATE)
{
PBITMAP * ppbmp = (PBITMAP *)pbitmap;
if(pitem->bSelected)
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[2]);
else
{
if(pitem->bMouseOver)
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[1]);
else
{
SetBrushColor (hdc, GetWindowBkColor(hwnd));
FillBox (hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[0]);
}
}
}
else if(dwStyle & ELVS_TYPE2STATE)//edit by tjb 2004-3-11
{
PBITMAP * ppbmp = (PBITMAP *)pbitmap;
if(pitem->bMouseOver)
{
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[1]);
}
else
{
/* temp = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
FillBox (hdc, rcClient.left-pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
SetBrushColor (hdc, temp);*/
SetBrushColor (hdc, GetWindowBkColor(hwnd));
FillBox (hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[0]);
}
}//end edit
else if(dwStyle & ELVS_SPECIAL2STATE)
{
PBITMAP * ppbmp = (PBITMAP *)pbitmap;
if(pitem->bSelected)
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[1]);
else
{
if(pitem->bMouseOver)
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY,
0, 0,(PBITMAP)ppbmp[0]);
else //当列表框某一行处于正常态时只有背景色
{
temp = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
//temp =SetBrushColor (hdc, RGBA2Pixel(hdc,147,169,213,230));
FillBox (hdc, rcClient.left-pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
SetBrushColor (hdc, temp);
}
}
}
else
{
FillBoxWithBitmap(hdc, rcClient.left - pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight - pLVInternalData->nOriginalY, 0, 0,(PBITMAP)pbitmap);
}
}
}
else
{
//edit by tjb 2004-4-20
//在2态时
if(dwStyle & ELVS_TYPE2STATE)
{
if(pitem->bMouseOver)
temp = SetBrushColor (hdc, pLVInternalData->nMouseOverBkColor);
else
temp = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
FillBox (hdc, rcClient.left-pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
SetBrushColor (hdc, temp);
}
else//3//3态
{
if (pitem->bSelected)//画选中条目的背景;
temp = SetBrushColor (hdc, pLVInternalData->nSelectBKColor);
else//画没选中条目的背景;
{
if(pitem->bMouseOver)
temp = SetBrushColor (hdc, pLVInternalData->nMouseOverBkColor);
else
temp = SetBrushColor (hdc, pLVInternalData->nItemBKColor);
}
FillBox (hdc, rcClient.left-pLVInternalData->nOriginalX,
(rows - 1) * pLVInternalData->nItemHeight +
pLVInternalData->nHeadHeight-pLVInternalData->nOriginalY,
rcClient.right - rcClient.left,
pLVInternalData->nItemHeight-pLVInternalData->nItemGap);
SetBrushColor(hdc, temp);
}
}
//add by tjb 2004-8-4 画选择框
if (dwStyle & ELVS_USECHECKBOX)
{
char bmpfile[MAX_PATH+1];
BITMAP bmp;
int off;
if (pLVInternalData->nCheckboxImg)
{
if(pitem->bChecked)
PrefixFileName((char *)pLVInternalData->nCheckboxImg, "ck", bmpfile, MAX_PATH);
else
PrefixFileName((char *)pLVInternalData->nCheckboxImg, "nm", bmpfile, MAX_PATH);
if(!LoadBitmap( HDC_SCREEN, &bmp, bmpfile))
{
off = (pLVInternalData->nItemHeight -pLVInternalData->nItemGap - bmp.bmHeight)/2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -