Owner Draw CListView not showing selection box 
Author Message
 Owner Draw CListView not showing selection box

Hi,

I'm using an owner drawn CListView, which works fine, except that i can not
get it to
draw a box around the currently selected item(s)

What am i doing wrong ?

Many thanks for any help given.

Duncan

void CWindowStyleListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
 //for this notification, the structure is actually a
 // NMLVCUSTOMDRAW that tells you what's going on with the custom
 // draw action. So, we'll need to cast the generic pNMHDR pointer.
 LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;

 switch(lplvcd->nmcd.dwDrawStage)
 {
  case CDDS_PREPAINT:
   *pResult = CDRF_NOTIFYSUBITEMDRAW;          // ask for subitem
notifications.
   break;

  case CDDS_ITEMPREPAINT:
   *pResult = CDRF_NOTIFYSUBITEMDRAW;
   break;

  case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
  {
   int iCol = lplvcd->iSubItem;
   int iRow = lplvcd->nmcd.dwItemSpec;
   CString sItem = GetItemText(iRow, iCol);

   CRect rc;
   GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);

   // get the device context.
   CDC *pDC= CDC::FromHandle(lplvcd->nmcd.hdc);
   int x1,y1,x2,y2;

   if (ListView_GetItemState(m_hWnd, iRow, LVIS_SELECTED)==LVIS_SELECTED)
   {
    x1=rc.left;y1=rc.top;
    x2=rc.right;y2=rc.bottom;

    CPen aSolidRedPen(PS_SOLID,1,RGB(255,0,0));

    CPen *pOldPen=pDC->SelectObject(&aSolidRedPen);

    pDC->MoveTo(x1,y1);
    pDC->LineTo(x2,y1);
    pDC->LineTo(x2,y2);
    pDC->LineTo(x1,y2);
    pDC->LineTo(x1,y1);

    pDC->SelectObject(pOldPen);
   }

   x1=rc.left+5;y1=rc.top+5;
   x2=rc.right-5;y2=rc.bottom-5;

   CPoint oldorg;

   oldorg = pDC->SetViewportOrg(x1,y1);

   int oldmapmode=pDC->GetMapMode();
   CSize oldsize=pDC->GetWindowExt();

   DrawMyItemPictureHere();

   pDC->SetWindowExt(oldsize);
   pDC->SetMapMode(oldmapmode);

   pDC->SetViewportOrg(oldorg);

   *pResult= CDRF_SKIPDEFAULT;
   break;
  }

  default:// it wasn't a notification that was interesting to us.
   *pResult = CDRF_DODEFAULT;
 }

Quote:
}



Sat, 30 Aug 2003 17:57:26 GMT  
 Owner Draw CListView not showing selection box
Sorted out the problem,

Now i get the selected state before i draw my picture, then it draws the
selection box.

Duncan


Quote:
> Hi,

> I'm using an owner drawn CListView, which works fine, except that i can
not
> get it to
> draw a box around the currently selected item(s)

> What am i doing wrong ?

> Many thanks for any help given.

> Duncan

> void CWindowStyleListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
> {
>  //for this notification, the structure is actually a
>  // NMLVCUSTOMDRAW that tells you what's going on with the custom
>  // draw action. So, we'll need to cast the generic pNMHDR pointer.
>  LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;

>  switch(lplvcd->nmcd.dwDrawStage)
>  {
>   case CDDS_PREPAINT:
>    *pResult = CDRF_NOTIFYSUBITEMDRAW;          // ask for subitem
> notifications.
>    break;

>   case CDDS_ITEMPREPAINT:
>    *pResult = CDRF_NOTIFYSUBITEMDRAW;
>    break;

>   case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
>   {
>    int iCol = lplvcd->iSubItem;
>    int iRow = lplvcd->nmcd.dwItemSpec;
>    CString sItem = GetItemText(iRow, iCol);

>    CRect rc;
>    GetCellRect(iRow, iCol, LVIR_BOUNDS, rc);

>    // get the device context.
>    CDC *pDC= CDC::FromHandle(lplvcd->nmcd.hdc);
>    int x1,y1,x2,y2;

>    if (ListView_GetItemState(m_hWnd, iRow, LVIS_SELECTED)==LVIS_SELECTED)
>    {
>     x1=rc.left;y1=rc.top;
>     x2=rc.right;y2=rc.bottom;

>     CPen aSolidRedPen(PS_SOLID,1,RGB(255,0,0));

>     CPen *pOldPen=pDC->SelectObject(&aSolidRedPen);

>     pDC->MoveTo(x1,y1);
>     pDC->LineTo(x2,y1);
>     pDC->LineTo(x2,y2);
>     pDC->LineTo(x1,y2);
>     pDC->LineTo(x1,y1);

>     pDC->SelectObject(pOldPen);
>    }

>    x1=rc.left+5;y1=rc.top+5;
>    x2=rc.right-5;y2=rc.bottom-5;

>    CPoint oldorg;

>    oldorg = pDC->SetViewportOrg(x1,y1);

>    int oldmapmode=pDC->GetMapMode();
>    CSize oldsize=pDC->GetWindowExt();

>    DrawMyItemPictureHere();

>    pDC->SetWindowExt(oldsize);
>    pDC->SetMapMode(oldmapmode);

>    pDC->SetViewportOrg(oldorg);

>    *pResult= CDRF_SKIPDEFAULT;
>    break;
>   }

>   default:// it wasn't a notification that was interesting to us.
>    *pResult = CDRF_DODEFAULT;
>  }
> }



Sat, 30 Aug 2003 21:17:21 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Owner-draw combo box not work in NT

2. owner-draw combo box does not change its size

3. Newbie to owner drawn: Scroll Bars in Owner drawn ListCtrl

4. How do I make an owner-draw CListView??

5. How to show an owner draw try icon?

6. text box that fades out - owner drawn

7. Owner Draw Combo Box

8. Owner Drawn List Box - URGENT Please HELP!!!

9. Need example of owner-drawn combo box using VC 4.2

10. Owner-Draw Combo Box

11. list box's owner-draw in windows CE

12. : owner draw on check box (push-like)

 

 
Powered by phpBB® Forum Software