Fortschrittanzeige in ListView



  • Hallo zusammen,

    ich versuche eine Fortschrittanzeige innerhalb einer Listview-Zelle anzeigen zu lassen. Jetzt bräuchte ich ja ein ParentHwnd, dass eine solche Listview-Zelle ja nicht besitzt.
    Muss ich die jetzt selbst da rein malen oder gibt es eine andere Möglichkeit.

    Vielen Dank
    Gruß
    Kai



  • Da musst du wohl die ListView komplett selber zeichenen.
    Wenn ich das hier so richtig verstehe:

    https://www.codeproject.com/Articles/646482/Custom-Controls-in-Win-API-Control-Customization



  • Dann ist das wohl so.

    Danke vielmals für die schnelle Antwort und den Link.





  • Hi,

    hier findest Du eine der besten Prgressbars:

    https://github.com/dotnetinstaller/dotnetinstaller/blob/master/dotNetInstaller/KCBusyProgressCtrl.h

    Gruß Karsten.


  • |  Mod

    @kahnsoft Ist Dir vielleicht aufgefallen, dass Deine Antwort OT ist? Vermutlich nicht... Das was Du schreibst wurde nicht gefragt!



  • Hi Martin,

    man muss natürlich in das OwnerDraw ListView was reinzeichnen das macht die tolle Progressbar
    die ohne Fenster in den DC Painte'd: OT/UT Oberer/Unterer Totpunkt?

    Wie man ein ListView OwnerDraw macht, kann man natürlich auch darstellen:

    
    
     ... Code ... 
    #include "stdafx.h"
    #include "ThumbNailCtrl.h"
    
    CThumbNailCtrl::CThumbNailCtrl():m_thumbspc(THUMBSPACE),m_thumbsz(THUMBSIZE)
    {
       m_pInfoImages      = NULL;
       p_oldbitmap        = NULL;
       pImgOldBitmap      = NULL;
    }
    
    CThumbNailCtrl::~CThumbNailCtrl()
    {
    	for (int n(0); n<CListCtrl::GetItemCount(); n++)
    	{
    		LV_ITEM  lvItem; ZeroMemory(&lvItem, sizeof(LV_ITEM));
    		lvItem.iItem = n;
    		lvItem.mask = LVIF_PARAM;
    		CListCtrl::GetItem(&lvItem);
    
    		if (lvItem.lParam)
    			delete (CUsrDat *)lvItem.lParam;
    	}
    
    	CListCtrl::OnDestroy();
    
    	m_memDC.DeleteDC();
    	m_bitmap.DeleteObject();
    	m_imgbitmap.DeleteObject();
    	m_font.DeleteObject();
    
    	if (m_pInfoImages)
    	{
    		m_pInfoImages->DeleteImageList();
    		delete m_pInfoImages, m_pInfoImages = 0;
    	}
    }
     
    BEGIN_MESSAGE_MAP(CThumbNailCtrl, CListCtrl)
    	ON_WM_CREATE()
    	ON_WM_DESTROY()
    	ON_WM_SIZE()
    	ON_WM_PAINT()
    	ON_WM_ERASEBKGND()
    	ON_WM_LBUTTONDOWN()
    END_MESSAGE_MAP()
    
    
    int CThumbNailCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    	if(CListCtrl::OnCreate(lpCreateStruct) == -1)
    	  return -1;
    
    	CClientDC dc(this);
      
        if(!m_memDC.CreateCompatibleDC(&dc))
    	 return -1;
    
    	if(!(m_pInfoImages = new CImageList) )
         return -1;
    
    	// CImageList
        if(!m_pInfoImages->Create(m_thumbsz+m_thumbspc, m_thumbsz+m_thumbspc, ILC_COLOR24 | ILC_MASK, 0, 0))
    	 return -1;
    
        CListCtrl::SetImageList(m_pInfoImages,LVSIL_NORMAL);
    
    	if (m_imgbitmap.m_hObject)
    		m_imgbitmap.DeleteObject();
    
    	if (!m_imgbitmap.CreateCompatibleBitmap(&dc, m_thumbsz + m_thumbspc, m_thumbsz + m_thumbspc))
    		return 0;
    
    	LOGFONT lf;::ZeroMemory (&lf, sizeof (lf));
    	lf.lfHeight    = 65;//m_stretch?75.0/(float)m_dib.GetWidth() * (float)cx:75;
    	lf.lfWeight    = FW_LIGHT;
    	lf.lfUnderline = FALSE;
    	::strcpy (lf.lfFaceName, _T("Arial"));
            
    	m_font.DeleteObject();
    	m_font.CreatePointFontIndirect(&lf);
    
    	CListCtrl::SetFont(&m_font,TRUE);
    
    	ModifyStyle(0, LVS_SINGLESEL);
    
    	return 0;
    }
    
    void CThumbNailCtrl::OnDestroy()
    {
    }
    
    void CThumbNailCtrl::OnSize(UINT nType, int cx, int cy)
    {
      CListCtrl::OnSize(nType, cx, cy);
      
      CClientDC dc(this);//CDC
    
      CRect rcClient; GetClientRect(&rcClient);
    
      if(p_oldbitmap)
      {
       m_memDC.SelectObject(p_oldbitmap);
       p_oldbitmap=0;
      }
    
      if (m_bitmap.m_hObject)
    	  m_bitmap.DeleteObject();
    
      if(!m_bitmap.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height()))
    	return;
    
      p_oldbitmap = m_memDC.SelectObject(&m_bitmap); 
    }
    
    
    void CThumbNailCtrl::OnPaint()
    {
    	CPaintDC dc(this); // device context for painting
    
        CRect rc(dc.m_ps.rcPaint);
    
    	if(rc.IsRectEmpty())
    	 return;
    
    	CRect rcClient; GetClientRect( &rcClient );
    
        CWnd* pWnd = GetDlgItem(0);//headerctrl
        if(pWnd)
        {
    	    CRect rcItem;
    	    pWnd->GetClientRect(&rcItem);
    	    dc.ExcludeClipRect(&rcItem);
        }
    	
        m_memDC.FillSolidRect( rc,RGB(255,255,255));
    
        CWnd::DefWindowProc( WM_PAINT, (WPARAM)m_memDC.m_hDC, 0 );//dubble buffer
    
        dc.BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&m_memDC,rc.left,rc.top,SRCCOPY);
    }
    
    BOOL CThumbNailCtrl::OnEraseBkgnd(CDC* pDC)
    {
    	return true;
    }
    
    CString CThumbNailCtrl::GetItemText(int Item)
    {
    	if((Item > -1 && Item < CListCtrl::GetItemCount()))
    	{
    		LV_ITEM  lvItem; ZeroMemory(&lvItem,sizeof(LV_ITEM));
    		lvItem.iItem        = Item;
    		lvItem.mask         = LVIF_PARAM;
    		CListCtrl::GetItem(&lvItem);
    		if(lvItem.lParam)
    		 return ((CUsrDat *)lvItem.lParam)->name;
    	}
        
    	return CString();
    }
    
    bool CThumbNailCtrl::InsertItem(CDib *pDib,CString &fName, CString &fAlias)
    {
    	if(!m_pInfoImages->m_hImageList)
    	 return false;
    
    	int img = m_pInfoImages->Add( &m_imgbitmap,RGB(148,148,148) );
    	if(img < 0)
    	 return false;
    
    	int id = CListCtrl::GetItemCount();
    	LV_ITEM  lvItem;ZeroMemory(&lvItem,sizeof(LV_ITEM));
    	lvItem.mask         = LVIF_IMAGE|LVIF_TEXT|LVIF_PARAM;  
    	lvItem.iImage       = img;
    	lvItem.iItem        = id;
    	lvItem.lParam       = (LPARAM) new CUsrDat(fName,fAlias);
    	lvItem.pszText      = ((CUsrDat *)lvItem.lParam)->alias.GetBuffer(0);
    	CListCtrl::InsertItem(&lvItem);
    
    	Redraw();
    
    	return true;
    }
    
    bool CThumbNailCtrl::UpdateItem(CString &ItemName,CString &ItemAlias,COLORREF Color,CDib *pDib)
    {
    	int id = FindItem(ItemName);
    	if(!m_pInfoImages->m_hImageList)
    	 return false;
    
    	LV_ITEM  lvItem; ZeroMemory(&lvItem,sizeof(LV_ITEM));
    	lvItem.iItem        = id;
    	lvItem.mask         = LVIF_IMAGE|LVIF_PARAM;
    	CListCtrl::GetItem(&lvItem);
    
    	CUsrDat *pUsr((CUsrDat *)lvItem.lParam);
    	if(pUsr && pUsr->alias != ItemAlias)
    	{
    		pUsr->alias.Format("%s",ItemAlias);
    		CListCtrl::SetItemText(id,0,pUsr->alias.GetBuffer());
    		CListCtrl::SetItem(&lvItem);
    	}
    
    	ReplaceImage(id,pDib,Color);
    
    	Invalidate(false);//refresh tumbnail
    
    	return true;
    }
    
    __inline bool CThumbNailCtrl::ReplaceImage(int Item,CDib *pDib,COLORREF rgb)
    {
    	CClientDC dc(this);
    
    	CDC srcDC; srcDC.CreateCompatibleDC(&dc);
    	CBitmap* pImgOldBitmap = srcDC.SelectObject(&m_imgbitmap);
    	
    	srcDC.DrawFrameControl(CRect(0,0,m_thumbsz+m_thumbspc,m_thumbsz+m_thumbspc),DFC_BUTTON,DFCS_BUTTONPUSH);
    	srcDC.FillSolidRect(5,2,m_thumbsz,3,rgb);//draw a color indicator at left top edge
    	pDib->DrawStretch(&srcDC,pDib->GetMapMem(),CRect(m_thumbspc>>1,m_thumbspc>>1,m_thumbsz+(m_thumbspc>>1),m_thumbsz+(m_thumbspc>>1)));
    	
    	srcDC.SelectObject(pImgOldBitmap);
    	srcDC.DeleteDC();
    	
    	return m_pInfoImages->Replace(Item,&m_imgbitmap,0);
    }
    
    int CThumbNailCtrl::FindItem(CString &ItemName)
    {
    	LV_ITEM  lvItem; ZeroMemory(&lvItem,sizeof(LV_ITEM));
    	int cnt(CListCtrl::GetItemCount());
        for(int n(0); n<cnt; n++)
    	{
    		lvItem.iItem        = n;
    		lvItem.mask         = LVIF_PARAM;
    		CListCtrl::GetItem(&lvItem);
    		if(lvItem.lParam && ((CUsrDat *)lvItem.lParam)->name == ItemName)
    		 return n;
    	}
    
    	return -1;
    }
    
    int CThumbNailCtrl::FindSelectedItem(void)
    {
    	LV_ITEM  lvItem; ZeroMemory(&lvItem, sizeof(LV_ITEM));
    	int cnt(CListCtrl::GetItemCount());
    
    	for (int n(0); n<cnt; n++)
    	{
    		if (LVIS_SELECTED&CListCtrl::GetItemState(n, LVIS_SELECTED))
    			return n;
    	}
    
    	return -1;
    }
    
    void CThumbNailCtrl::SelectItem(CString &ItemName)
    {
    	SelectItem(FindItem(ItemName));
    }
    
    void CThumbNailCtrl::SelectItem(int iItem)
    {
    	const DWORD state(LVIS_SELECTED);// | LVIS_ACTIVATING | LVIS_FOCUSED | LVIS_DROPHILITED | LVIS_GLOW);
    	int cnt(CListCtrl::GetItemCount());
    	for (int i = 0; i<cnt; i++)
    	{
    		if (i == iItem)
    		{
    			CListCtrl::SetItemState(iItem, state, state);
    		}
    		else 
    			CListCtrl::SetItemState(i, 0, state);
    	}
    
    	CListCtrl::EnsureVisible(iItem, TRUE);
    }
    
    
    void CThumbNailCtrl::DeleteItem(CString &ItemName)
    {
    	LV_ITEM  lvItem; ZeroMemory(&lvItem,sizeof(LV_ITEM));
    	int cnt(CListCtrl::GetItemCount());
        for(int n(0); n<cnt; n++)
    	{
    		lvItem.iItem        = n;
    		lvItem.mask         = LVIF_PARAM;
    		CListCtrl::GetItem(&lvItem);
    		if(lvItem.lParam && ((CUsrDat *)lvItem.lParam)->name == ItemName)
    		{
    	        CListCtrl::DeleteItem(n); 
    			m_pInfoImages->Remove(n);
    			delete (CUsrDat *)lvItem.lParam,lvItem.lParam=0;
    		    break;
    		}
    	}
    
    	Redraw();
    }
    
    
    void CThumbNailCtrl::Redraw(void)
    {
    	register int cnt=CListCtrl::GetItemCount(); 
    	for(register int id=0; id<cnt; id++)
    	{
    		CRect rc; GetClientRect(&rc);
    		register int width = max(0,rc.Width()-((m_thumbsz+m_thumbspc)>>1));
    		register int iAnzHorz = max(1,width/(m_thumbsz+m_thumbspc));
    		register int x = id%iAnzHorz;
    		register int y = id/iAnzHorz;
    		CPoint pt(x*(m_thumbsz+m_thumbspc),y*(m_thumbsz+m_thumbspc+32));
    		CListCtrl::SetItemPosition(id, pt);
    		CListCtrl::EnsureVisible(id,false);
    	}
    	
    	Invalidate(true);
    	UpdateWindow();
    }
    
    void CThumbNailCtrl::OnLButtonDown(UINT nFlags, CPoint point)
    {
    	SetFocus();
    	CListCtrl::OnLButtonDown(nFlags, point);
    }
    
    void CThumbNailCtrl::SetThumbNailSize(int Size)
    {
    	m_thumbsz  = Size;
    	m_thumbspc =((double)Size/100.0)*20.0;
    }
    
    
    


  • @KahnSoft sagte in Fortschrittanzeige in ListView:

    register /* ... */
    

    *lach*

     ZeroMemory( // ...
    

    Auch so ein Relikt aus prähistorischer Zeit.



  • Dieser Beitrag wurde gelöscht!