CListCtrl控件总把后面图片盖住,有什么办法能实现透明效果或换一个其它控件也能实现透明效果并带能放置几百个图标?有时间的话给个示例代码更好,我这里能实现效果即结貼。谢谢!

解决方案 »

  1.   

    方法一;
    把背景图贴到ListCtrl背景上,这是可以实现的
    方法二;
    用DC画到界面上,至于滚动,自己加个scrollbar处理下
      

  2.   

    谢谢yfh1985sdq!我以前没怎么用过,能帮一个简单的示例代码吗?谢谢!
      

  3.   

    http://www.codeproject.com/KB/combobox/TransListBox.aspx
      

  4.   

    主要在onDrawItem和ONErasebkgnd()中处理了.这是我曾经实现的部分代码,你看看思路了.
    void CFMListBoxCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
    if(!lpszText)
    return;
    CString strText = lpszText;

    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    int nDCIndex = dc.SaveDC();
    CFont * pOldFont = dc.SelectObject(m_pListBoxAnno->FMCreateFont()); COLORREF crOldTextColor = dc.GetTextColor();
    COLORREF crOldBkColor = dc.GetBkColor();
    int nMode = dc.SetBkMode(TRANSPARENT);

    if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
    (lpDrawItemStruct->itemState  & ODS_SELECTED))
    {
      dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
          dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
          dc.FillSolidRect(&lpDrawItemStruct->rcItem,::GetSysColor(COLOR_HIGHLIGHT)); }
    else
    {
    dc.SetTextColor(m_pListBoxAnno->GetTextColor());
    if(!m_pListBoxAnno->IsTransparent())
    dc.FillSolidRect(&lpDrawItemStruct->rcItem,crOldBkColor);
    else
    DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem)); }

    // Draw the text.
    UINT nFormat = 0;
    if(m_pListBoxAnno->IsMultiline())
    nFormat |= DT_WORDBREAK;
    else
    nFormat |= DT_SINGLELINE; int nAlignType =m_pListBoxAnno->GetAlignType();
    switch(nAlignType) 
    {
    case TEXT_ALIGN_LEFT:
    nFormat |= DT_LEFT;
    break;
    case TEXT_ALIGN_CENTER:
    nFormat |= DT_CENTER;
    break;
    case TEXT_ALIGN_RIGHT:
    nFormat |= DT_RIGHT;
    break;
    }
    // DrawBackground(&dc,CRect(lpDrawItemStruct->rcItem));
    // if(lpszText[0] != '\0')
    if(!strText.IsEmpty())
    dc.DrawText(
    lpszText,
    strlen(lpszText),
    &lpDrawItemStruct->rcItem,
    nFormat);
    TRACE("x1 = %d,y1 = %d,x2 = %d ,y2 = %d \n",lpDrawItemStruct->rcItem.left,
    lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
    // original values.
    dc.SetTextColor(crOldTextColor);
    dc.SetBkColor(crOldBkColor);
    dc.SelectObject(pOldFont);
    dc.SetBkMode(nMode);
    dc.RestoreDC(nDCIndex);
    dc.Detach();
    }void CFMListBoxCtrl::DrawBackground(CDC * pDC,CRect rect)
    {
    ASSERT(pDC);
    if (pDC)
    {
    if (m_pListBoxAnno->IsTransparent())
    {
    CWnd* pMainWnd = AfxGetMainWnd();
    if (pMainWnd)
    {
    CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR);
    if (pDocMgr)
    {
    PIsm* pBkImg = pDocMgr->GetActivePageBkImg();
    if (pBkImg)
    {
    CRect rcPos;
    m_pListBoxAnno->GetAnnoPos(rcPos);
    rcPos.NormalizeRect();
    CRect rcClient(rect);
    CPoint ptOffset(rcPos.left,rcPos.top);
    //GetParent()->ClientToScreen(&rcClient);
    int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO);
    // Draw the background image in the Edit control
    ptOffset.y += rect.top;
    FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio);
    return ;
    }
    }
    }
    }
    }
    }BOOL CFMListBoxCtrl::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default if (pDC)
    {
    if (m_pListBoxAnno->IsTransparent())
    {
    CWnd* pMainWnd = AfxGetMainWnd();
    if (pMainWnd)
    {
    CDocMgr* pDocMgr = (CDocMgr*)pMainWnd->SendMessage(WM_GET_DOCMGR);
    if (pDocMgr)
    {
    PIsm* pBkImg = pDocMgr->GetActivePageBkImg();
    if (pBkImg)
    {
    CRect rcPos;
    m_pListBoxAnno->GetAnnoPos(rcPos);
    rcPos.NormalizeRect();
    CPoint ptOffset(rcPos.left,rcPos.top);
    CRect rcClient;
    GetClientRect(&rcClient);
    int nRatio = (int)pMainWnd->SendMessage(WM_GET_ZOOM_RATIO);
    // Draw the background image in the Edit control
    FMISM_DrawImage(pDC,pBkImg,ptOffset,GetSafeHwnd(),rcClient,nRatio);
    return TRUE;
    }
    }
    }
    }
    } return CListBox::OnEraseBkgnd(pDC);
    }