⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atloutbarctrl.h

📁 这是一本学习 window编程的很好的参考教材
💻 H
📖 第 1 页 / 共 5 页
字号:

	  CRect rc, irc;
	  GetInsideRect(irc);
	  GetItemRect(iSelFolder, iLastSel, rc);

	  if (iLastSel >= iFirstItem && irc.bottom > rc.bottom && irc.top < rc.top)
	  {
		  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
		  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);

		  ATLASSERT(index >= 0 && index < pbf->GetItemCount());
	    CBarItem* pi = GetBarItemListItem(pbf, index);

		  ATLASSERT(pi && ima);

		  CClientDC dc(m_hWnd);
		  if (IsSmallIconView())
		  {
			  if (ima)
			  {
				  IMAGEINFO ii;
				  ima->GetImageInfo(pi->iImageIndex, &ii);
				  CSize szImage = CRect(ii.rcImage).Size();
				  CPoint pt;
				  pt.x = rc.left + 2;
				  pt.y = rc.top + (rc.Height() - szImage.cy) / 2;

				  CRect rcBck(pt.x-1, pt.y-1, pt.x + szImage.cx+2, pt.y + szImage.cy+2);
				  dc.FillSolidRect(rcBck, crBackGroundColor);

				  pt.x += xoffset;
				  pt.y += yoffset;

				  ima->Draw(dc.m_hDC, pi->iImageIndex, pt, ILD_NORMAL);
			  }
		  }
		  else
		  {
			  if(ima)
			  {
				  IMAGEINFO ii;
				  ima->GetImageInfo(pi->iImageIndex, &ii);
				  CSize szImage = CRect(ii.rcImage).Size();
				  CPoint pt;
				  pt.x = rc.left + (rc.Width() - szImage.cx) / 2;
				  pt.y = rc.top;

				  CRect rcBck(pt.x-1, pt.y-1, pt.x + szImage.cx+2, pt.y + szImage.cy+2);
				  dc.FillSolidRect(rcBck, crBackGroundColor);

				  pt.x += xoffset;
				  pt.y += yoffset;

				  ima->Draw(dc.m_hDC, pi->iImageIndex, pt, ILD_NORMAL);
			  }
		  }
	  }
  }

	void SetAnimSelHighlight(const int iTime)
  {
	  if (iTime <= 0) KillTimer(3);
	  else 
    {
      if (::IsWindow(m_hWnd))
        SetTimer(3, iTime);
    }
	  iSelAnimTiming = iTime;
  }

	DWORD GetFolderData(int iFolder = -1)
  {
	  if (iFolder < 0) iFolder = iSelFolder;
	  CBarFolder* pbf = GetBarFolderListItem(iFolder);
	  return pbf->dwData;
  }

	CWindow* GetFolderChild(int iFolder = -1)
  {
	  if (GetFolderCount())
	  {
		  if (iFolder < 0) iFolder = iSelFolder;

	    CBarFolder* pbf = GetBarFolderListItem(iFolder);
		  return pbf->pChild;
	  }
	  return NULL;
  }

	int AddFolder(const char * cFolderName, const DWORD exData)
  {
	  CBarFolder* pbf = new CBarFolder(cFolderName, exData);
	  ATLASSERT(pbf);
	  arFolder.insert(arFolder.end(), pbf);

	  return arFolder.size() - 1;
  }


  int AddFolderBar(const char* pFolder, CWindow* pSon, const DWORD exData = 0)
  {
	  CBarFolder* pbf = new CBarFolder(pFolder, exData);
	  ATLASSERT(pbf);
	  pbf->pChild = pSon;

	  arFolder.insert(arFolder.end(), pbf);

	  //@@
    return arFolder.size() - 1;
  }

  BOOL IsValidItem(const int index)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  return (index >= 0 && index < pbf->GetItemCount());
  }

  CString GetItemText(const int index)
  {
	  CString item;

	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  if (IsValidItem(index))
	  {
	    CBarItem* pi = GetBarItemListItem(pbf, index);
		  if (pi->cItem) item = pi->cItem;
	  }
	  return item;
  }

	void SetAnimationTickCount(const long value) { lAnimationTickCount = value; };
	long GetAnimationTickCount() { return lAnimationTickCount; };

  BOOL GetFolderRect(const int iIndex, CRect & rect) const
  {
	  int max = arFolder.size();
	  ATLASSERT(iIndex >= 0 && iIndex < max);

	  if (iIndex >= 0 && iIndex < max)
	  {
		  CRect rc;
		  GetClientRect(rc);
		  if (iIndex > iSelFolder)
			  rect.SetRect(rc.left, rc.bottom - ((max - iIndex)) * iFolderHeight, rc.right, 
			  rc.bottom - (max - iIndex - 1) * iFolderHeight);
		  else 
			  rect.SetRect(rc.left, rc.top + iIndex * iFolderHeight - 1, rc.right, 
			  rc.top + (1 + iIndex) * iFolderHeight - 1);
		  return TRUE;
	  }
	  return FALSE;
  }

  void GetIconRect(const int iFolder, const int iIndex, CRect & rect)
  {
	  CRect rc;
	  GetInsideRect(rc);
	  int top = rc.top;
	  CSize sz(0,0);
	  int y = 0;
	  int spacing = IsSmallIconView() ? ySmallIconSpacing : yLargeIconSpacing;

	  for (int t = 0; t < iIndex; t++)
	  {
		  sz = GetItemSize(iFolder, t, ircAll);
		  top += sz.cy;
		  top += spacing;
		  if (t == iFirstItem - 1) y = top - rc.top;
	  }
	  top += spacing;

	  sz = GetItemSize(iFolder, iIndex, ircIcon);
	  if (IsSmallIconView())
	  {
		  rect.SetRect(rc.left, top, rc.left + sz.cx, top + sz.cy);
		  rect.left += xLeftMargin + 2;
		  rect.right += xLeftMargin + 2;
		  rect.top -= yTopMargin;
		  rect.bottom -= yTopMargin;

		  rect.top -= y;
		  rect.bottom -= y;
	  }
	  else
	  {
		  rect.SetRect(rc.left + (rc.Width() - sz.cx)/2, top, rc.left + (rc.Width() - sz.cx)/2 + sz.cx, top + sz.cy);
		  rect.top -= y + 3;
		  rect.bottom -= y + 2;
	  }
  }

  void DrawItem(CDC* pDC, const int iFolder, CRect rc, const int index, const BOOL bOnlyImage = FALSE)
  {
	  CImageList* ima = GetFolderImageList(iFolder, IsSmallIconView());

	  ATLASSERT(iFolder >= 0 && iFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iFolder);

	  ATLASSERT(index >= 0 && index < pbf->GetItemCount());
    CBarItem* pi = GetBarItemListItem(pbf, index);

	  ATLASSERT(pi && ima);

	  HFONT oft = pDC->SelectFont((HFONT)GetStockObject(DEFAULT_GUI_FONT));
	  COLORREF ocr = pDC->SetTextColor(crTextColor);
	  int obk = pDC->SetBkMode(TRANSPARENT);

	  if (IsSmallIconView())
	  {
		  if (ima)
		  {
			  IMAGEINFO ii;
			  ima->GetImageInfo(pi->iImageIndex, &ii);
			  CSize szImage = CRect(ii.rcImage).Size();
			  CPoint pt;
			  pt.x = rc.left + 2;
			  pt.y = rc.top + (rc.Height() - szImage.cy) / 2;
			  ima->Draw(pDC->m_hDC, pi->iImageIndex, pt, ILD_NORMAL);

			  if (!bOnlyImage)
			  {
				  rc.left += szImage.cx + xSmallIconLabelOffset;
				  pDC->TextOut(rc.left, rc.top, CString(pi->cItem));
			  }
			  
		  }
	  }
	  else
	  {
		  if (ima)
		  {
			  IMAGEINFO ii;
			  ima->GetImageInfo(pi->iImageIndex, &ii);
			  CSize szImage = CRect(ii.rcImage).Size();
			  CPoint pt;
			  pt.x = rc.left + (rc.Width() - szImage.cx) / 2;
			  pt.y = rc.top;// + (rc.Height() - szImage.cy) / 2;
			  ima->Draw(pDC->m_hDC, pi->iImageIndex, pt, ILD_NORMAL);
			  if (!bOnlyImage)
			  {
				  rc.top += szImage.cy + yLargeIconLabelOffset;
				  pDC->DrawText(pi->cItem, lstrlen(pi->cItem), rc, DT_CENTER|DT_WORDBREAK);
			  }
		  }
	  }
	  
	  if (dwFlags&fSelHighlight && iLastSel == index && iLastSel >= 0)
	  {
		  CRect rc;
		  GetIconRect(iSelFolder, iLastSel, rc);
		  rc.InflateRect(1,1);
		  pDC->Draw3dRect(rc, crDkShadowBorder, cr3dFace);
	  }

	  pDC->SetTextColor(ocr);
	  pDC->SelectFont(oft);
	  pDC->SetBkMode(obk);

  }

  void PaintItems(CDC* pDC, const int iFolder, CRect rc)
  {
	  ATLASSERT(iFolder >= 0 && iFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iFolder);
	  int max = pbf->GetItemCount(), t;
	  CRect irc;
	  GetInsideRect(irc);
	  int isdc = pDC->SaveDC();
	  CRgn itemRegion;
	  itemRegion.CreateRectRgnIndirect(&irc);
	  pDC->SelectClipRgn(itemRegion);
	  itemRegion.DeleteObject();
	  for (t = iFirstItem; t < max; t++)
	  {
      CBarItem* pi = GetBarItemListItem(pbf, t);
		  CRect itemRc;
		  GetItemRect(iFolder, t, itemRc);
		  if (itemRc.top > rc.bottom) break;
		  else DrawItem(pDC, iFolder, itemRc, t);
	  }
	  pDC->RestoreDC(isdc);
  }

  void DrawFolder(CDC * pDC, const int iIdx, CRect rect, const BOOL bSelected)
  {
	  CBarFolder* pbf = GetBarFolderListItem(iIdx);

	  if (!bSelected)
	  {
		  CPen pn1;
      pn1.CreatePen(PS_SOLID, 1, crBackGroundColor1);
		  HPEN op = pDC->SelectPen(pn1);
		  pDC->MoveTo(rect.left, rect.top);
		  pDC->LineTo(rect.right, rect.top);
		  pDC->SelectPen(op);
		  pn1.DeleteObject();

		  rect.top ++;


		  pDC->Draw3dRect(rect, crHilightBorder, crBackGroundColor1);
		  rect.InflateRect(-1,-1);
		  pDC->FillSolidRect(rect, cr3dFace);
		  int obk = pDC->SetBkMode(TRANSPARENT);
		  HFONT of = pDC->SelectFont((HFONT)GetStockObject(DEFAULT_GUI_FONT));
		  pDC->DrawText(CString(pbf->cName), -1, rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		  pDC->SetBkMode(obk);
		  pDC->SelectFont(of);
	  }
	  else
	  {
		  CPen pn1;
      pn1.CreatePen(PS_SOLID, 1, crBackGroundColor1);
		  HPEN op = pDC->SelectPen(pn1);
		  pDC->MoveTo(rect.left+1, rect.top);
		  pDC->LineTo(rect.right, rect.top);
		  pDC->SelectPen(op);
		  pn1.DeleteObject();

		  rect.top ++;

		  pDC->Draw3dRect(rect, crDkShadowBorder, crHilightBorder);
		  rect.InflateRect(-1,-1);
		  pDC->Draw3dRect(rect, crBackGroundColor1, cr3dFace);
		  rect.InflateRect(-1,-1);

		  pDC->FillSolidRect(rect, cr3dFace);

		  int obk = pDC->SetBkMode(TRANSPARENT);
		  HFONT of = pDC->SelectFont((HFONT)GetStockObject(DEFAULT_GUI_FONT));
		  pDC->DrawText(CString(pbf->cName), -1, rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		  pDC->SetBkMode(obk);
		  pDC->SelectFont(of);
	  }
  }

  void AnimateFolderScroll(const int iFrom, const int iTo)
  {
	  ATLASSERT(iFrom >= 0 && iFrom < GetFolderCount());
	  ATLASSERT(iTo >= 0 && iTo < GetFolderCount());

	  CRect rc, rc1, frc, frc1;
	  GetInsideRect(rc);
	  rc1.SetRect(0,0,rc.Width(),rc.Height());
	  GetFolderRect(iTo, frc);
	  frc1 = frc;

	  CClientDC dc(m_hWnd);
	  CDC memDC;
	  memDC.CreateCompatibleDC(dc.m_hDC);
	  CBitmap bmpFrom, bmpTo;
	  bmpFrom.CreateCompatibleBitmap(dc.m_hDC, rc1.Width(), rc1.Height() + frc.Height() * 2);
	  bmpTo.CreateCompatibleBitmap(dc.m_hDC, rc1.Width(), rc1.Height() + frc.Height() * 2);
	  CDC* pDC = &memDC;

	  CWindow* pWnd1 = GetFolderChild(iFrom);
	  CWindow* pWnd2 = GetFolderChild(iTo);


    HBITMAP obmp = pDC->SelectBitmap(bmpFrom);

	  if (iTo > iFrom)
	  {
		  rc1.bottom += frc.Height() * 2;
		  pDC->FillSolidRect(rc1, crBackGroundColor);
		  if (pWnd1) 
		  {
			  BOOL bPrev = pWnd1->ShowWindow(SW_SHOW);
			  pWnd1->SendMessage(WM_ERASEBKGND, (WPARAM) dc.m_hDC, (LPARAM) 0);
			  pWnd1->SendMessage(WM_PAINT, (WPARAM)dc.m_hDC, (LPARAM) 0);
			  if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
		  }
		  else 
        PaintItems(pDC, iFrom, rc1);

		  pDC->SelectBitmap(bmpTo);
		  frc.SetRect(0,0,frc.Width(),frc.Height());
		  rc1.SetRect(0,frc.Height(),rc.Width(), rc.Height()+frc.Height() * 2);
		  pDC->FillSolidRect(rc1, crBackGroundColor);

		  if (pWnd2) 
		  {
			  CPoint ovpt = pDC->SetViewportOrg(0, frc.Height());
			  BOOL bPrev = pWnd2->ShowWindow(SW_SHOW);
			  pWnd2->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  if (!bPrev) pWnd2->ShowWindow(SW_HIDE);
			  pDC->SetViewportOrg(ovpt);
		  }
		  else PaintItems(pDC, iTo, rc1);
		  DrawFolder(pDC, iTo, frc, FALSE);
	  }
	  else
	  {
		  frc.SetRect(0,0,frc.Width(),frc.Height());
		  rc1.top += frc.Height();
		  rc1.bottom += frc.Height() * 2;
		  pDC->FillSolidRect(rc1, crBackGroundColor);
		  if (pWnd1) 
		  {
			  CPoint ovpt = pDC->SetViewportOrg(0, frc.Height());
			  BOOL bPrev = pWnd1->ShowWindow(SW_SHOW);
			  pWnd1->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  pWnd1->SendMessage(WM_PAINT, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
			  pDC->SetViewportOrg(ovpt);
		  }
		  else PaintItems(pDC, iFrom, rc1);

		  DrawFolder(pDC, iFrom, frc, FALSE);

		  pDC->SelectBitmap(bmpTo);
		  rc1.SetRect(0,0,rc.Width(), rc.Height() + frc.Height() * 2);
		  pDC->FillSolidRect(rc1, crBackGroundColor);

		  if (pWnd2) 
		  {
			  BOOL bPrev = pWnd2->ShowWindow(SW_SHOW);
			  pWnd2->SendMessage(WM_ERASEBKGND, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->m_hDC, (LPARAM) 0);
			  if (!bPrev) pWnd2->ShowWindow(SW_HIDE);
		  }
		  else PaintItems(pDC, iTo, rc1);
	  }

	  if (iTo > iFrom)
	  {
		  CRect rcFrom, rcTo;
		  GetFolderRect(iFrom, rcFrom);
		  GetFolderRect(iTo, rcTo);
		  int fh = rcFrom.Height();
		  for (int y = rcTo.top - fh; y > rcFrom.bottom; y -= fh)
		  {
			  pDC->SelectBitmap(bmpFrom);
			  dc.BitBlt(rc.left, rcFrom.bottom + 1, rc.Width(), y - rcFrom.bottom - 1, pDC->m_hDC, 0,fh, SRCCOPY);
			  pDC->SelectBitmap(bmpTo);
			  dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y + fh, pDC->m_hDC, 0,0, SRCCOPY);
			  Sleep(lAnimationTickCount);
		  }
	  }
	  else
	  {
		  CRect rcFrom, rcTo;
		  GetFolderRect(iFrom, rcFrom);
		  int fh = rcFrom.Height();
		  rcTo.SetRect(rc.left, rc.bottom, rc.right, rc.bottom - fh);
		  for (int y = rcFrom.top + 1; y < rcTo.top - fh; y += fh)
		  {
			  pDC->SelectBitmap(bmpTo);
			  dc.BitBlt(rc.left, rcFrom.top, rc.Width(), y - rcFrom.top - 1, pDC->m_hDC, 0, fh*2, SRCCOPY);
			  pDC->SelectBitmap(bmpFrom);
			  dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y, pDC->m_hDC, 0,0, SRCCOPY);
			  Sleep(lAnimationTickCount);
		  }
	  }

	  // put back the original bitmap
    pDC->SelectBitmap(obmp);
	  
	  memDC.DeleteDC();
	  bmpFrom.DeleteObject();
	  bmpTo.DeleteObject();
  }

  int GetItemCount()
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  return 	pbf->GetItemCount();
  }

  int GetDragItemRect(const int index, CRect &rect)
  {
	  CRect rc, crc;
	  GetInsideRect(crc);
	  crc.InflateRect(-2, 0);

	  GetItemRect(iSelFolder, index < GetItemCount() ? index : index - 1, rc);
	  int line = 0;
	  if (index < GetItemCount())
	  {
		  line = rc.top - 4;
	  }
	  else
	  {
		  line = rc.bottom + 6;
	  }
	  int tpe;
	  if (index == 0)
	  {
		  rect.SetRect(crc.left, line+2, crc.right, line + 7);
		  tpe = 0;
	  }
	  else if (index < GetItemCount())
	  {
		  rect.SetRect(crc.left, line - 9, crc.right, line);
		  tpe = 1;
		  if (IsSmallIconView()) 
		  {
			  rect.top += 8;
			  rect.bottom += 8;
		  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -