可编辑多行列表框

 

介绍 如果您查看一下

  

 

快照并运行.exe文件,您会发现这里没有我需要说明的内容。我需要这个具有项目编辑、插入、删除和移动功能的控件,于是我问,“为什么不与人们共享它呢?” 使用的代码 它很容易使用,只要添加一个基于类的变量,就可以了。您可以像使用普通列表框一样使用它。隐藏,收缩,复制Code

//
// powered by NetControl.ro
//
// .............
void CListBoxXP::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    CString szBuf="";
    COLORREF col;
    if(((int)lpDrawItemStruct->itemID==edited)&&(IsWindow(hHelper)))
        return;
    {
        GetText(lpDrawItemStruct->itemID,szBuf);
         SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,0));
         RECT r;
         memcpy((void*)&r,&lpDrawItemStruct->rcItem,sizeof(RECT));
         if(itm==(int)lpDrawItemStruct->itemID)
         {
            HBRUSH br;
            br=::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.9));
            ::FillRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct-&gt;rcItem,br);
            ::DeleteObject(br);
         }
         else
         {
             FillRect(lpDrawItemStruct-&gt;hDC,<BR>                &lpDrawItemStruct->rcItem,<BR>                (HBRUSH)GetStockObject(WHITE_BRUSH));
         }<BR>
         r.left+=5;
         r.top+=2;
         col=RGB(255,255,255);
         if(lpDrawItemStruct->itemState & ODS_SELECTED)
         {
            col=RGB(220,220,220);
            HBRUSH br;
            br=::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.75));
            ::FillRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct->rcItem,br);
            ::DeleteObject(br);
         }
         if(lpDrawItemStruct-&gt;itemState & ODS_FOCUS)
         {
            HBRUSH br;
            br = ::CreateSolidBrush(LightenColor(<BR>                GetSysColor(COLOR_HIGHLIGHT),0.5));
            ::FrameRect(lpDrawItemStruct->hDC,<BR>                &lpDrawItemStruct->rcItem,br);
            ::DeleteObject(br);
         }
         SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);<BR>
         r.left-=3;
         r.top-=2;
         if(CountLines(szBuf) > 1)
             DrawText(lpDrawItemStruct->hDC,szBuf,<BR>                strlen(szBuf),&r,<BR>                DT_LEFT|DT_TOP|DT_WORDBREAK);
         else
             DrawText(lpDrawItemStruct->hDC,szBuf,<BR>                strlen(szBuf),&r,<BR>                DT_LEFT|DT_VCENTER|DT_SINGLELINE);
    }
}

void CListBoxXP::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
    HDC hDC;
    TEXTMETRIC tm;
    char szBuf[512]="";
    ::SendMessage(this->m_hWnd, LB_GETTEXT,<BR>        (WPARAM)lpMeasureItemStruct->itemID,(LPARAM)szBuf);<BR>
    hDC = ::GetDC(this->m_hWnd);
    CRect r;
    GetClientRect(r);
    ::GetTextMetrics(hDC, &tm);
    lpMeasureItemStruct->itemHeight=(tm.tmHeight)*CountLines(szBuf);
    ::ReleaseDC(this->m_hWnd, hDC);
}
// ...<BR>

本文转载于:http://www.diyabc.com/frontweb/news248.html

posted @ 2020-08-04 10:19  Dincat  阅读(255)  评论(0编辑  收藏  举报