15,980
社区成员




case NM_CUSTOMDRAW:
pcd = (NMCUSTOMDRAW*)lParam;
if(wParam == IDC_TREE1)
{
ptvcd = (NMTVCUSTOMDRAW*)lParam;
if(ptvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
{
return CDRF_NOTIFYITEMDRAW; //多次进入该循环
}
else if(ptvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
newfont = (HFONT)GetStockObject(ANSI_FIXED_FONT); //从不进入该循环
SelectObject(ptvcd->nmcd.hdc, newfont);
ptvcd->clrText = RGB(255, 0, 0);
ptvcd->clrTextBk = RGB(0, 150, 50);
return CDRF_NEWFONT;
}
}
return FALSE;
default:
return FALSE;
case NM_CUSTOMDRAW:
pcd = (NMCUSTOMDRAW*)lParam;
if(wParam == IDC_TREE1)
{
ptvcd = (NMTVCUSTOMDRAW*)lParam;
if((ptvcd->nmcd.dwDrawStage & CDDS_ITEM) && (ptvcd->nmcd.uItemState & CDIS_HOT))//CDIS_SELECTED))
{
SetTextColor(ptvcd->nmcd.hdc, RGB(255,255,255));//white
SetBkColor(ptvcd->nmcd.hdc, RGB(255,0,0));
return CDRF_NOTIFYITEMDRAW;
}
else
{
SetTextColor(ptvcd->nmcd.hdc, GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(ptvcd->nmcd.hdc, GetSysColor(COLOR_WINDOW));
return CDRF_NOTIFYITEMDRAW;
}
return CDRF_DODEFAULT;
}
return CDRF_DODEFAULT;
default:
return FALSE;
}
return FALSE;
LRESULT TreeViewNotify (HWND hWnd, LPARAM lParam)
{
char prompt[80];
LPNMHDR lpnmh = (LPNMHDR) lParam; // Contains data from a notification
switch (lpnmh->code)
{
case NM_CLICK:
sprintf(prompt,"Ctrl ID %d \r\n",lpnmh->idFrom);
OutputDebugString(prompt);
break;
case NM_DBLCLK:
OutputDebugString("NM_DBLCLK\n");
break;
case NM_RETURN://??
OutputDebugString("NM_RETURN\n");
break;
case NM_RCLICK:
OutputDebugString("NM_RCLICK\n");
break;
case NM_RDBLCLK://??
OutputDebugString("NM_RDBLCLK\n");
break;
case NM_SETFOCUS:
// OutputDebugString("NM_SETFOCUS\n");
break;
case NM_KILLFOCUS:
// OutputDebugString("NM_KILLFOCUS\n");
break;
case NM_HOVER:// ??
OutputDebugString("NM_HOVER\n");
break;
case NM_CUSTOMDRAW:
// OutputDebugString("NM_CUSTOMDRAW\n");
break;
case TVN_SELCHANGED:
OutputDebugString("TVN_SELCHANGED\n");
break;
}
// if(GetFocus() != m_hTreeView) return 0;
//
if(lpnmh->code==NM_CUSTOMDRAW)
{//
LPNMTVCUSTOMDRAW pDraw=(LPNMTVCUSTOMDRAW)lParam;
DWORD dwDrawStage=pDraw->nmcd.dwDrawStage;
UINT uItemState =pDraw->nmcd.uItemState;
HDC hdc=pDraw->nmcd.hdc;
//RECT rc;
//HTREEITEM hItem=(HTREEITEM) pDraw->nmcd.dwItemSpec;
//TreeView_GetItemRect(m_hTreeView,hItem,&rc,TRUE);
//HBRUSH brsh=0; // 0x00010000 0x0001
//char txt[260];
//TVITEM tvi;
if((dwDrawStage & CDDS_ITEM) && (uItemState & CDIS_HOT))//CDIS_SELECTED))
{//
//brsh=CreateSolidBrush(RGB(255,0,0));//red
//FillRect(hdc,&rc,brsh);
//DeleteObject(brsh);
//set colors
SetTextColor(hdc,RGB(255,255,255));//white
SetBkColor(hdc,RGB(255,0,0));
//
//memset(txt,0,sizeof(txt));
//tvi.mask= TVIF_HANDLE | TVIF_TEXT;
//tvi.hItem=hItem;
//tvi.pszText=txt;
//tvi.cchTextMax=sizeof(txt);
//TreeView_GetItem(m_hTreeView,&tvi);
//TextOut(hdc,rc.left+2,rc.top+2,txt,strlen(txt));//not sizeof(txt) !
//????
//OutputDebugString(txt);
//OutputDebugString("\n");
return CDRF_NOTIFYITEMDRAW;// | CDRF_SKIPDEFAULT);
}
else
{// without these ,1st blue !
SetTextColor(hdc,GetSysColor(COLOR_WINDOWTEXT));
SetBkColor(hdc,GetSysColor(COLOR_WINDOW));
//
return CDRF_NOTIFYITEMDRAW;
}
}
return 0;
}
/*
ptvcd=(NMTVCUSTOMDRAW*)lParam;
if(ptvcd->nmcd.dwDrawStage==CDDS_PREPAINT)//Before the painting cycle begins
{
//the control will send NM_CUSTOMDRAW notification messages to the parent,before and after drawing items
return CDRF_NOTIFYITEMDRAW;
}
if(ptvcd->nmcd.dwDrawStage==CDDS_ITEMPREPAINT)//Before an item is drawn
{
newfont=(HFONT)GetStockObject(ANSI_FIXED_FONT);
SelectObject(ptvcd->nmcd.hdc,newfont);
ptvcd->clrText=RGB(255,0,0);
ptvcd->clrTextBk=RGB(0,150,50);
return CDRF_NEWFONT;
}
*/
//
WndProc 里:
LRESULT APIENTRY WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
.........
case WM_NOTIFY:
if(wParam==IDC_LISTVIEW)
{
return (ListViewCustomDraw(m_hListView, lParam));
}
else if (wParam==IDC_TREEVIEW)
{
//OutputDebugString("WM_NOTIFY parant\n");
return (TreeViewNotify(hwnd, lParam));
}
else if(wParam==IDC_PICK)
{
PickerNotify(m_hPick, lParam);
}
break;
// OnCustomDraw
void CXListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
// This is the prepaint stage for a subitem. Here's where we set the
// item's text and background colors. Our return value will tell
// Windows to draw the subitem itself, but it will use the new colors
// we set here.
int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
int nSubItem = pLVCD->iSubItem;
XLISTCTRLDATA *pXLCD = (XLISTCTRLDATA *) pLVCD->nmcd.lItemlParam;
ASSERT(pXLCD);
COLORREF crText = m_crWindowText;
COLORREF crBkgnd = m_crWindow;
if (pXLCD)
{
crText = pXLCD[nSubItem].crText;
crBkgnd = pXLCD[nSubItem].crBackground;
if (!pXLCD[0].bEnabled)
crText = m_crGrayText;
}
// store the colors back in the NMLVCUSTOMDRAW struct
pLVCD->clrText = crText;
pLVCD->clrTextBk = crBkgnd;
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
CRect rect;
GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);
if (pXLCD && (pXLCD[nSubItem].bShowProgress))
{
DrawProgress(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
#ifndef DO_NOT_INCLUDE_XCOMBOLIST
else if (pXLCD && (pXLCD[nSubItem].bCombo))
{
if (GetItemState(nItem, LVIS_SELECTED))
DrawComboBox(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
else
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
#endif
else if (pXLCD && (pXLCD[nSubItem].nCheckedState != -1))
{
DrawCheckbox(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
else
{
rect.left += DrawImage(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
DrawText(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);
*pResult = CDRF_SKIPDEFAULT; // We've painted everything.
}
}
}
tree 的 意思差不多. 主要是CDRF 要对.