VisualC++ J'va y penser ... | Euh copie coller d un petit soft que j ai fait
Code :
- void CMyListCtrl::OnCustomdraw ( NMHDR* pNMHDR, LRESULT* pResult )
- {
- LPNMTVCUSTOMDRAW pCustomDraw = (LPNMTVCUSTOMDRAW)pNMHDR;
- static CRect rcItem;
- static BOOL bHot;
- *pResult = CDRF_DODEFAULT;
- switch (pCustomDraw->nmcd.dwDrawStage) {
- case CDDS_PREPAINT:
- *pResult = CDRF_NOTIFYITEMDRAW;
- break;
- case CDDS_ITEMPREPAINT:
- bHot = FALSE;
- if (pCustomDraw->nmcd.uItemState & CDIS_HOT) {
- bHot = TRUE;
- }
- pCustomDraw->clrText = RGB(255,255,255);
- pCustomDraw->clrTextBk = RGB(255,255,255);
- pCustomDraw->nmcd.uItemState &= ~CDIS_FOCUS;
- pCustomDraw->nmcd.uItemState &= ~CDIS_SELECTED;
- GetItemRect((HTREEITEM) pCustomDraw->nmcd.dwItemSpec, &rcItem, TRUE);
- *pResult = CDRF_NOTIFYPOSTPAINT;
- break;
- case CDDS_ITEMPOSTPAINT:
- DrawTreeItem(bHot, rcItem, pCustomDraw->nmcd.hdc, (HTREEITEM) pCustomDraw->nmcd.dwItemSpec);
- break;
- }
- }
- void CMyListCtrl::DrawTreeItem(BOOL bHot, CRect rcItem, HDC hdc, HTREEITEM hItem)
- {
- RECT rcFocus = rcItem;
- RECT treerect;
- GetClientRect(&treerect);
- rcFocus.left = treerect.left + 2;
- rcFocus.right = treerect.right - 2;
- if(bHot == TRUE) {
- TRIVERTEX vert[2] ;
- GRADIENT_RECT gRect;
- vert [0] .x = rcFocus.left;
- vert [0] .y = rcFocus.top;
- vert [0] .Red = USHORT((m_dwRightColorSide & 0x000000ff) << 8);
- vert [0] .Green = USHORT(((m_dwRightColorSide & 0x0000ff00) >> 8) << 8);
- vert [0] .Blue = USHORT(((m_dwRightColorSide & 0x00ff0000) >> 16) << 8);
- vert [0] .Alpha = 0x0000;
- vert [1] .x = rcFocus.right;
- vert [1] .y = rcFocus.bottom;
- vert [1] .Red = USHORT((m_dwLeftColorSide & 0x000000ff) << 8);
- vert [1] .Green = USHORT(((m_dwLeftColorSide & 0x0000ff00) >> 8) << 8);
- vert [1] .Blue = USHORT(((m_dwLeftColorSide & 0x00ff0000) >> 16) << 8);
- vert [1] .Alpha = 0x0000;
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
- ::GradientFill(hdc, vert, 2, &gRect, 1, GRADIENT_FILL_RECT_H);
- ::SetTextColor(hdc, RGB(0,0,0));
- }
- else {
- ::FillRect(hdc, &rcFocus, (HBRUSH)m_BackBrushDefault.m_hObject);
- ::SetTextColor(hdc, RGB(30,30,30));
- }
- ::SetBkMode(hdc, TRANSPARENT);
- HICON hicon = m_fnhiGetCurrentIcon(hItem);
- if (hicon != NULL) {
- BOOL bRet = DrawIconEx(hdc, rcItem.left - 16, rcItem.top + 2, hicon, 17, 17, 0, NULL, DI_NORMAL);
- if (bRet == 0) {
- TRACE("ret = %d\n", GetLastError());
- }
- DestroyIcon(hicon);
- }
- rcItem.left += 5;
- CString str = GetItemText(hItem);
- ::DrawText(hdc, str, -1, &rcItem, DT_VCENTER | DT_SINGLELINE);
- }
|
bon plus les autres fonctions mais bon |