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

📄 atloutbarctrl.h

📁 这是一本学习 window编程的很好的参考教材
💻 H
📖 第 1 页 / 共 5 页
字号:
	  }
	  else
	  {
		  rect.SetRect(crc.left, line, crc.right, line + 5);
		  tpe = 2;
	  }
	  return tpe;
  }

	void DrawDragArrow(CDC * pDC, const int iFrom, const int iTo)
  {
	  if (iTo == iLastDragItemDraw) return;
	  CRect rc1;
	  if (iLastDragItemDraw >= 0)
	  {
		  GetDragItemRect(iLastDragItemDraw, rc1);
		  if (iLastDragItemDrawType == 0) rc1.bottom = rc1.top + 5;
		  else if (iLastDragItemDrawType == 1) { rc1.top -= 4; rc1.bottom = rc1.top + 9; }
		  else if (iLastDragItemDrawType == 2) { rc1.top -= 4; rc1.bottom = rc1.top + 5; }
		  InvalidateRect(rc1, TRUE);
		  UpdateWindow();
	  }
	  iLastDragItemDraw = iTo;

	  if (iLastDragItemDraw >= 0)
	  {
		  iLastDragItemDrawType = GetDragItemRect(iLastDragItemDraw, rc1);

		  HPEN op = pDC->SelectPen(*pBlackPen);

		  pDC->MoveTo(rc1.left, rc1.top);
		  pDC->LineTo(rc1.right, rc1.top);

		  if (iLastDragItemDrawType != 2)
		  {
			  pDC->MoveTo(rc1.left, rc1.top+1);
			  pDC->LineTo(rc1.left + 7, rc1.top+1);
			  pDC->MoveTo(rc1.left, rc1.top+2);
			  pDC->LineTo(rc1.left + 5, rc1.top+2);
			  pDC->MoveTo(rc1.left, rc1.top+3);
			  pDC->LineTo(rc1.left + 3, rc1.top+3);
			  pDC->MoveTo(rc1.left, rc1.top+4);
			  pDC->LineTo(rc1.left + 1, rc1.top+4);

			  pDC->MoveTo(rc1.right-1, rc1.top+1);
			  pDC->LineTo(rc1.right - 7, rc1.top+1);
			  pDC->MoveTo(rc1.right-1, rc1.top+2);
			  pDC->LineTo(rc1.right - 5, rc1.top+2);
			  pDC->MoveTo(rc1.right-1, rc1.top+3);
			  pDC->LineTo(rc1.right - 3, rc1.top+3);
		  }
		  if (iLastDragItemDrawType != 0)
		  {
			  pDC->MoveTo(rc1.left, rc1.top-1);
			  pDC->LineTo(rc1.left + 7, rc1.top-1);
			  pDC->MoveTo(rc1.left, rc1.top-2);
			  pDC->LineTo(rc1.left + 5, rc1.top-2);
			  pDC->MoveTo(rc1.left, rc1.top-3);
			  pDC->LineTo(rc1.left + 3, rc1.top-3);
			  pDC->MoveTo(rc1.left, rc1.top-4);
			  pDC->LineTo(rc1.left + 1, rc1.top-4);

			  pDC->MoveTo(rc1.right-1, rc1.top-1);
			  pDC->LineTo(rc1.right - 7, rc1.top-1);
			  pDC->MoveTo(rc1.right-1, rc1.top-2);
			  pDC->LineTo(rc1.right - 5, rc1.top-2);
			  pDC->MoveTo(rc1.right-1, rc1.top-3);
			  pDC->LineTo(rc1.right - 3, rc1.top-3);
			  pDC->MoveTo(rc1.right-1, rc1.top-4);
			  pDC->LineTo(rc1.right - 1, rc1.top-4);
		  }

		  pDC->SelectPen(op);
	  }
  }

  void SetItemImage(const int index, const int iImage)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  if (IsValidItem(index))
	  {
      CBarItem* i = GetBarItemListItem(pbf, index);
		  i->iImageIndex = iImage;
	  }
  }

	void SetItemData(const int index, const DWORD dwData)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  if (IsValidItem(index))
	  {
      CBarItem* i = GetBarItemListItem(pbf, index);
		  i->dwData = dwData;
	  }
  }

  DWORD GetItemData(const int index)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  if (IsValidItem(index))
	  {
      CBarItem* i = GetBarItemListItem(pbf, index);
		  return i->dwData;
	  }
	  return 0;
  }

  int GetItemImage(const int index)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  if (IsValidItem(index))
	  {
      CBarItem* i = GetBarItemListItem(pbf, index);
		  return i->iImageIndex;
	  }
	  return 0;
  }

	void RemoveItem(const int index)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  ATLASSERT(index >= 0 && index < pbf->GetItemCount());
	  if (IsValidItem(index))
	  {
	    int nIndex = 0;
      CBarItemList::iterator ListIterator;	
	    for (ListIterator = pbf->arItems.begin(); ListIterator != pbf->arItems.end(); ++ListIterator)        
	    {
        if (nIndex == index)
        {
          CBarItem* pItem = *ListIterator;
        
	        if (pItem)
          {
            delete pItem;
            pItem = NULL;
          }
          if (ListIterator != pbf->arItems.end())
            pbf->arItems.erase(ListIterator);
  
          break;
        }
        nIndex++;
      }

		  CRect rc;
		  GetInsideRect(rc);
		  InvalidateRect(rc);
	  }
  }

	void SetItemText(const int index, const char * text)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
    CBarItem* pi = GetBarItemListItem(pbf, index);
	if(pi!=NULL){
	  if (pi->cItem) 
	  {
		  delete [] pi->cItem;
		  pi->cItem = NULL;
	  }
	  pi->cItem = new char [lstrlen(text)+1];
	  lstrcpy(pi->cItem, text);
	}
    Invalidate();
  }
	void SetItemText(const int nSelFolder,const int index, const char * text)
  {
	  ATLASSERT(nSelFolder >= 0 && nSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(nSelFolder);
    CBarItem* pi = GetBarItemListItem(pbf, index);
	if(pi!=NULL){
	  if (pi->cItem) 
	  {
		  delete [] pi->cItem;
		  pi->cItem = NULL;
	  }
	  pi->cItem = new char [lstrlen(text)+1];
	  lstrcpy(pi->cItem, text);
	}
    Invalidate();
  }

  void GetLabelRect(const int iFolder, const int iIndex, CRect & rect)
  {
		//ATLTRACE2(atlTraceUI, 0, "GetLabelRect\n");
	  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, ircAll);

	  CSize szLabel = GetItemSize(iFolder, iIndex, ircLabel);

	  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 - 5;
		  rect.bottom += yTopMargin - 5;
	  }
	  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;

		  rect.bottom -=  yLargeIconSpacing;
		  rect.top    = rect.bottom - szLabel.cy;
	  }
  }

  void StartItemEdit(const int index)
  {
	  ATLASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(iSelFolder);
	  ATLASSERT(index >= 0 && index < pbf->GetItemCount());
    CBarItem* pi = GetBarItemListItem(pbf, index);

	  if (m_pGroupEdit != NULL)
      delete m_pGroupEdit;
    
    m_pGroupEdit = new CGroupEdit;
	  m_pGroupEdit->iIndex = index;
	  CRect rc, crc;
	  GetLabelRect(iSelFolder, index, rc);
	  GetInsideRect(crc);
	  
	  DWORD dwFlag = WS_CHILD|WS_VISIBLE|WS_BORDER;

	  if (!IsSmallIconView())
	  {
		  rc.left = crc.left + 5;
		  rc.right = crc.right - 5;
		  rc.bottom += 5;
		  dwFlag |= ES_CENTER|ES_MULTILINE;
	  }
	  else 
	  {
		  CRect irc;
		  GetIconRect(iSelFolder, index, irc);
		  dwFlag |= ES_AUTOHSCROLL;
		  rc.OffsetRect(irc.Width()+1, -6);
		  m_pGroupEdit->bNoDown = TRUE;
	  }

	  m_pGroupEdit->Create(m_hWnd, rc, NULL, dwFlag);
	  m_pGroupEdit->msgSend = NM_OB_ONLABELENDEDIT;
    m_pGroupEdit->SetFont((HFONT)GetStockObject(DEFAULT_GUI_FONT),TRUE);
	  
	  m_pGroupEdit->SetWindowText(pi->cItem);
	  m_pGroupEdit->SetFocus();
  }

  void SetFolderText(const int index, const char * text)
  {
	  ATLASSERT(index >= 0 && index < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(index);
	  if (pbf->cName) 
	  {
		  delete [] pbf->cName;
		  pbf->cName = NULL;
	  }
	  pbf->cName = new char [lstrlen(text)+1];
	  lstrcpy(pbf->cName, text);
  }

  void StartGroupEdit(const int index)
  {
	  if (m_pGroupEdit != NULL)
      delete m_pGroupEdit;
    
    m_pGroupEdit = new CGroupEdit;
	  m_pGroupEdit->iIndex = index;
	  CRect rc;
	  GetFolderRect(index, rc);
	  rc.InflateRect(-2,-2);
	  m_pGroupEdit->Create(m_hWnd, rc, NULL, WS_CHILD|WS_VISIBLE|ES_CENTER|ES_MULTILINE, 0, 1);
	  m_pGroupEdit->msgSend = NM_OB_ONGROUPENDEDIT;
    m_pGroupEdit->SetFont((HFONT)GetStockObject(DEFAULT_GUI_FONT),TRUE);
	  ATLASSERT(index >= 0 && index < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(index);
	  m_pGroupEdit->SetWindowText(pbf->cName);
	  m_pGroupEdit->SetFocus();
  }

  void HighlightItem(const int index, const BOOL bPressed = FALSE)
  {
	  HWND hFocusedWindow = GetFocus();
    CWindow pf(hFocusedWindow);
	  if (hFocusedWindow != NULL && hFocusedWindow != m_hWnd && pf.IsChild(hFocusedWindow)) return;

	  static BOOL bOldPressed = FALSE;
	  if (iLastItemHighlighted == index && bOldPressed == bPressed) return;

	  bOldPressed = bPressed;

	  CClientDC dc(m_hWnd);

	  CRect irc;
	  GetInsideRect(irc);
	  int isdc = dc.SaveDC();
	  CRgn itemRegion;
	  itemRegion.CreateRectRgnIndirect(irc);
	  dc.SelectClipRgn(itemRegion);
	  itemRegion.DeleteObject();


	  if (iLastItemHighlighted >= 0 && IsValidItem(iLastItemHighlighted))
	  {
		  CRect rc;
		  GetIconRect(iSelFolder, iLastItemHighlighted, rc);
		  rc.InflateRect(1,1);
		  dc.Draw3dRect(rc, crBackGroundColor, crBackGroundColor);
	  }
	  if (iSelAnimTiming > 0 && index == iLastSel)
	  {
		  iLastItemHighlighted = -1;
		  return;
	  }
	  if (dwFlags&fSelHighlight && iLastSel == index)
	  {
		  iLastItemHighlighted = -1;
		  return;
	  }

	  iLastItemHighlighted = index;
	  if (iLastItemHighlighted >= 0 && IsValidItem(iLastItemHighlighted))
	  {
		  CRect rc;
		  GetIconRect(iSelFolder, iLastItemHighlighted, rc);
		  rc.InflateRect(1,1);
		  if (bPressed)
			  dc.Draw3dRect(rc, crDkShadowBorder, cr3dFace);
		  else
			  dc.Draw3dRect(rc, cr3dFace, crDkShadowBorder);
	  }
	  dc.RestoreDC(isdc);
  }

  void GetVisibleRange(const int iFolder, int & first, int & last)
  {
	  first = iFirstItem;
	  CRect rc;
	  GetInsideRect(rc);

	  CBarFolder* pbf = GetBarFolderListItem(iFolder);
	  int max = pbf->GetItemCount(), t;
	  for (t = iFirstItem; t < max; t++)
	  {
      CBarItem* pi = GetBarItemListItem(pbf, t);
		  CRect itemRc;
		  GetItemRect(iFolder, t, itemRc);
		  if (itemRc.bottom > rc.bottom) 
		  {
			  last = t - 1;
			  break;
		  }
		  else last = t;
	  }
  }
	
	CImageList* GetImageList(CImageList * pImageList, int nImageList)
  {
	  if (nImageList == fSmallIcon) return pSmallImageList;
	  else if (nImageList == fLargeIcon) return pLargeImageList;
	  return NULL;
  }

	CImageList * SetFolderImageList(const int folder, CImageList * pImageList, int nImageList)
  {
	  ATLASSERT(folder >= 0 && folder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(folder);
	  CImageList* o = NULL;
	  if (nImageList == fSmallIcon)
	  {
		  o = pbf->pSmallImageList;
		  pbf->pSmallImageList = pImageList;
	  }
	  else if (nImageList == fLargeIcon)
	  {
		  o = pbf->pLargeImageList;
		  pbf->pLargeImageList = pImageList;
	  }
	  return o;
  }

	CImageList * SetImageList(CImageList * pImageList, int nImageList)
  {
	  CImageList * o = NULL;
	  if (nImageList == fSmallIcon)
	  {
		  o = pSmallImageList;
		  pSmallImageList = pImageList;
	  }
	  else if (nImageList == fLargeIcon)
	  {
		  o = pLargeImageList;
		  pLargeImageList = pImageList;
	  }
	  return o;
  }

  int GetCountPerPage() {return 0;}

	void RemoveFolder(const int index)
  {
	  ATLASSERT(index >= 0 && index < GetFolderCount());

	  CBarFolder* pbf = GetBarFolderListItem(index);
	  int nIndex = 0;
    CBarFolderList::iterator ListIterator;	
	  for (ListIterator = arFolder.begin(); ListIterator != arFolder.end(); ++ListIterator)        
	  {
      if (nIndex == index)
      {
        CBarFolder* pItem = *ListIterator;
      
	      if (pItem)
        {
		      if (pItem->pChild)
          {
            pItem->pChild->DestroyWindow() ;
		        pItem->pChild = NULL;
          }
          delete pItem;
        }

        if (ListIterator != arFolder.end())
          arFolder.erase(ListIterator);

        break;
      }
      nIndex++;
    }

	  if (iSelFolder >= index) iSelFolder = index - 1;
	  if (iSelFolder < 0 && GetFolderCount() > 0)
      iSelFolder = 0;
	  if (iSelFolder >= 0)	
      SetSelFolder(iSelFolder); 
	  Invalidate();
  }

  int GetSelFolder() {return iSelFolder;}

	void SetSelFolder(const int index)
  {
	  ATLASSERT(index >= 0 && index < GetFolderCount());

	  CWindow* pc = GetFolderChild();
	  if (pc) pc->ShowWindow(SW_HIDE);

	  if (index != iSelFolder)
	  {
		  if (dwFlags&fAnimation && lAnimationTickCount >= 0) AnimateFolderScroll(iSelFolder, index);
	  }

	  iSelFolder = index;
	  iFirstItem = 0;
	  iLastSel = -1;

	  pc = GetFolderChild();
	  if (pc)
	  {
		  CRect rc;
		  GetInsideRect(rc);
		  pc->MoveWindow(rc);
		  pc->ShowWindow(SW_SHOW);
	  }	
		
    CWindow wnd(m_hOwnerWindow);
    wnd.SendMessage(WM_OUTBAR_NOTIFY, NM_FOLDERCHANGE, (LPARAM) iSelFolder);

	  Invalidate();
  }


	int InsertItem(const int folder, const int index, const char * text, const int image = -1, const DWORD exData = 0)
  {
	  ATLASSERT(folder >= 0 && folder < GetFolderCount());
	  CBarFolder* pbf = GetBarFolderListItem(folder);
	  return pbf->InsertItem(index, text, image, exData);
  }

⌨️ 快捷键说明

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