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

📄 gfxoutbarctrl.cpp

📁 仿QQ的聊天程序vc++/mfc来学习的简易聊天室代码功能较全
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	ClientToScreen(&pt);
	cMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this);

	cMenu.DestroyMenu();
	
	CWnd::OnRButtonDown(nFlags, point);
}

void CGfxOutBarCtrl::OnGfxLargeicon() 
{
	SetSmallIconView(false);
	Invalidate();	
}

void CGfxOutBarCtrl::OnUpdateGfxLargeicon(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(IsSmallIconView());
}

void CGfxOutBarCtrl::OnGfxSmallicon() 
{
	SetSmallIconView(true);	
	Invalidate();	
}

void CGfxOutBarCtrl::OnUpdateGfxSmallicon(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(!IsSmallIconView());
}

void CGfxOutBarCtrl::OnGfxRemoveitem() 
{
	if (iHitInternal1 == htFolder)
	{
		RemoveFolder(iHitInternal2);
	}
	else if (iHitInternal1 == htItem)
	{
		RemoveItem(iHitInternal2);
	}
}

void CGfxOutBarCtrl::OnUpdateGfxRemoveitem(CCmdUI* pCmdUI) 
{
	BOOL enable=TRUE;
	if(iHitInternal1==htFolder&&iHitInternal2<3)
		enable=FALSE;
	pCmdUI->Enable(enable);
}

void CGfxOutBarCtrl::OnGfxRenameitem() 
{
	if (iHitInternal1 == htFolder)
	{
		StartGroupEdit(iHitInternal2);
	}
	else if (iHitInternal1 == htItem)
	{
		StartItemEdit(iHitInternal2);
	}
}

void CGfxOutBarCtrl::OnUpdateGfxRenameitem(CCmdUI* pCmdUI) 
{
	BOOL enable=TRUE;
	if(iHitInternal1==htFolder&&iHitInternal2<3)
		enable=FALSE;
	pCmdUI->Enable(enable);
}

void CGfxOutBarCtrl::RemoveItem(const int index)
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	ASSERT(index >= 0 && index < pbf->GetItemCount());
	if (IsValidItem(index))
	{
		CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
		delete i;

		pbf->arItems.RemoveAt(index);
		CRect rc;
		GetInsideRect(rc);
		InvalidateRect(rc);
	}
}

bool CGfxOutBarCtrl::IsValidItem(const int index) const
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	return (index >= 0 && index < pbf->GetItemCount());
}

DWORD CGfxOutBarCtrl::GetItemData(const int index) const
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	if (IsValidItem(index))
	{
		CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
		return i->dwData;
	}
	return 0;
}

int CGfxOutBarCtrl::GetItemImage(const int index) const
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	if (IsValidItem(index))
	{
		CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
		return i->iImageIndex;
	}
	return 0;
}

void CGfxOutBarCtrl::SetItemData(const int index, const DWORD dwData)
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	if (IsValidItem(index))
	{
		CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
		i->dwData = dwData;
	}
}

void CGfxOutBarCtrl::SetItemImage(const int index, const int iImage)
{
	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	if (IsValidItem(index))
	{
		CBarItem * i = (CBarItem *) pbf->arItems.GetAt(index);
		i->iImageIndex = iImage;
	}
}

void CGfxOutBarCtrl::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);

		CPen * op = pDC->SelectObject(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->SelectObject(op);
	}
}

int CGfxOutBarCtrl::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;
		}
	}
	else
	{
		rect.SetRect(crc.left, line, crc.right, line + 5);
		tpe = 2;
	}
	return tpe;
}


void CGfxOutBarCtrl::AnimateFolderScroll(const int iFrom, const int iTo)
{
	ASSERT(iFrom >= 0 && iFrom < GetFolderCount());
	ASSERT(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(this);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	CBitmap bmpFrom, bmpTo;
	bmpFrom.CreateCompatibleBitmap(&dc, rc1.Width(), rc1.Height() + frc.Height() * 2);
	bmpTo.CreateCompatibleBitmap(&dc, rc1.Width(), rc1.Height() + frc.Height() * 2);
	CDC * pDC = &memDC;

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


	CBitmap * obmp = pDC->SelectObject(&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) pDC->GetSafeHdc(), (LPARAM) 0);
			pWnd1->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
			if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
		}
		else PaintItems(pDC, iFrom, rc1);

		pDC->SelectObject(&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->GetSafeHdc(), (LPARAM) 0);
			pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (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->GetSafeHdc(), (LPARAM) 0);
			pWnd1->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (LPARAM) 0);
			if (!bPrev) pWnd1->ShowWindow(SW_HIDE);
			pDC->SetViewportOrg(ovpt);
		}
		else PaintItems(pDC, iFrom, rc1);

		DrawFolder(pDC, iFrom, frc, false);

		pDC->SelectObject(&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->GetSafeHdc(), (LPARAM) 0);
			pWnd2->SendMessage(WM_PAINT, (WPARAM) pDC->GetSafeHdc(), (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->SelectObject(&bmpFrom);
			dc.BitBlt(rc.left, rcFrom.bottom + 1, rc.Width(), y - rcFrom.bottom - 1, pDC, 0,fh, SRCCOPY);
			pDC->SelectObject(&bmpTo);
			dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y + fh, pDC, 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->SelectObject(&bmpTo);
			dc.BitBlt(rc.left, rcFrom.top, rc.Width(), y - rcFrom.top - 1, pDC, 0, fh*2, SRCCOPY);
			pDC->SelectObject(&bmpFrom);
			dc.BitBlt(rc.left, y, rc.Width(), rc.bottom - y, pDC, 0,0, SRCCOPY);
			Sleep(lAnimationTickCount);
		}
	}

	pDC->SelectObject(obmp);
}




CString CGfxOutBarCtrl::GetItemText(const int index)
{
	CString item;

	ASSERT(iSelFolder >= 0 && iSelFolder < GetFolderCount());
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iSelFolder);
	if (IsValidItem(index))
	{
		CBarItem * pi = (CBarItem *) pbf->arItems.GetAt(index);
		if (pi->cItem) item = pi->cItem;
	}
	return item;
}

int CGfxOutBarCtrl::AddFolderBar(const char * pFolder, CWnd * pSon, const DWORD exData)
{
	CBarFolder * pbf = new CBarFolder(pFolder, exData);
	ASSERT(pbf);
	pbf->pChild = pSon;

	arFolder.Add((void *)pbf);

	return arFolder.GetSize() - 1;
}

CWnd * CGfxOutBarCtrl::GetFolderChild(int iFolder)
{
	if (GetFolderCount())
	{
		if (iFolder < 0) iFolder = iSelFolder;

		CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
		return pbf->pChild;
	}
	return NULL;
}

DWORD CGfxOutBarCtrl::GetFolderData(int iFolder)
{
	if (iFolder < 0) iFolder = iSelFolder;
	CBarFolder * pbf = (CBarFolder *) arFolder.GetAt(iFolder);
	return pbf->dwData;
}

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

void CGfxOutBarCtrl::OnGfxGroupicon() 
{
	int index=GetFolderCount();
	AddFolder("",index);
	Invalidate();
	StartGroupEdit(index);	
}

void CGfxOutBarCtrl::OnGfxBackcicon() 
{
	CColorDialog dlg;
	if(dlg.DoModal()==IDCANCEL)return;
	crBackGroundColor=dlg.GetColor();
	Invalidate();
}

void CGfxOutBarCtrl::OnGfxFontcicon() 
{
	CColorDialog dlg;
	if(dlg.DoModal()==IDCANCEL)return;
	crTextColor=dlg.GetColor();
	Invalidate();			
}

BOOL CGfxOutBarCtrl::CBarFolder::MoveToHead(int index)
{
	if(index==0)return TRUE;
	if(index>=GetItemCount())return FALSE;
	void * pbf=arItems.GetAt(index);
	arItems.RemoveAt(index);
	arItems.InsertAt(0,pbf);
	return TRUE;
}

BOOL CGfxOutBarCtrl::CBarFolder::MoveToTail(int index)
{
	if(index==GetItemCount()-1)return TRUE;
	if(index>=GetItemCount()||index<0)return FALSE;
	void * pbf=arItems.GetAt(index);
	arItems.RemoveAt(index);
	arItems.Add(pbf);
	return TRUE;	
}

BOOL CGfxOutBarCtrl::MoveToHead(int folder,int index)
{
	if(folder<0||folder>=GetFolderCount())return FALSE;
	CBarFolder * pbf=(CBarFolder*)arFolder.GetAt(folder);
	return pbf->MoveToHead(index);
}

BOOL CGfxOutBarCtrl::MoveToTail(int folder,int index)
{
	if(folder<0||folder>=GetFolderCount())return FALSE;
	CBarFolder* pbf=(CBarFolder*)arFolder.GetAt(folder);
	return pbf->MoveToTail(index);
}

//DEL BOOL CGfxOutBarCtrl::ModifyItem(DWORD dwID, int image,LPCTSTR lpszText)
//DEL {
//DEL 	if(image<0&&lpszText==NULL)return FALSE;
//DEL 	for(int i=0;i<arFolder.GetSize();i++)
//DEL 	{		
//DEL 		CBarFolder* pbf=(CBarFolder*)arFolder.GetAt(i);
//DEL 		if(pbf->ModifyItem(dwID,image,lpszText)) return TRUE;
//DEL 	}
//DEL 	return FALSE;
//DEL }

//DEL BOOL CGfxOutBarCtrl::CBarFolder::ModifyItem(DWORD dwID, int image, LPCTSTR lpszText)
//DEL {
//DEL /*	for(int i=0;i<arItems.GetSize();i++)
//DEL 	{
//DEL 		CBarItem* pItem=(CBarItem*)arItems.GetAt(i);
//DEL 		if(pItem->dwData==dwID)
//DEL 		{
//DEL 			if(image>=0)
//DEL 			{
//DEL 				if(pItem->iImageIndex%2)
//DEL 					pItem->iImageIndex=image*2+1;
//DEL 				else
//DEL 					pItem->iImageIndex=image*2;
//DEL 			}
//DEL 			if(lpszText!=NULL)
//DEL 			{
//DEL 				if(pItem->cItem!=NULL)
//DEL 				{
//DEL 					delete [] pItem->cItem;
//DEL 				}
//DEL 				pItem->cItem=new char[lstrlen(lpszText)+1];
//DEL 				lstrcpy(pItem->cItem,lpszText);
//DEL 			}
//DEL 			return TRUE;
//DEL 		}
//DEL 	}	 */
//DEL 	return FALSE;
//DEL }

BOOL CGfxOutBarCtrl::SetOnlineImage(DWORD dwID, BOOL bTrue)
{
	for(int i=0;i<arFolder.GetSize();i++)
	{		
		CBarFolder* pbf=(CBarFolder*)arFolder.GetAt(i);
		if(pbf->SetOnlineImage(dwID,bTrue)) return TRUE;
	}
	return FALSE;
}

BOOL CGfxOutBarCtrl::CBarFolder::SetOnlineImage(DWORD dwID, BOOL bTrue)
{
	for(int i=0;i<arItems.GetSize();i++)
	{
		CBarItem* pItem=(CBarItem*)arItems.GetAt(i);
		if(pItem->dwData==dwID)
		{
			if(pItem->iImageIndex%2&&bTrue)
			{
				pItem->iImageIndex--;
				MoveToHead(i);
				return TRUE;
			}
			if(pItem->iImageIndex%2==0&&!bTrue)
			{
				pItem->iImageIndex++;
				MoveToTail(i);
				return TRUE;
			}
		}
	}
	return FALSE;
}

int CGfxOutBarCtrl::AddItem(int folder, LPCTSTR lpszText, int image, DWORD exData)
{
	ASSERT(folder>=0&&folder<arFolder.GetSize());
	
	CBarFolder* pbf=(CBarFolder*)arFolder.GetAt(folder);
	ASSERT(pbf!=NULL);
	return pbf->AddItem(lpszText,image,exData);	
}

int CGfxOutBarCtrl::CBarFolder::AddItem(LPCTSTR lpszText, int image, DWORD exData)
{
	CBarItem * pbf = new CBarItem(lpszText, image*2+1, exData);
	ASSERT(pbf);	
	return arItems.Add((void *) pbf);
}

void CGfxOutBarCtrl::Serialize(CArchive& ar) 
{
	if (ar.IsStoring())
	{	

	}
	else
	{	// loading code
	}
}

void CGfxOutBarCtrl::SetOfflineState()
{
	for(int i=0;i<arFolder.GetSize();i++)
	{
		CBarFolder * pbf=(CBarFolder*)arFolder.GetAt(i);
		pbf->SetOfflineState();
	}
	Invalidate();
}

void CGfxOutBarCtrl::CBarFolder::SetOfflineState()
{
	for(int i=0;i<arItems.GetSize();i++)
	{
		CBarItem* pItem=(CBarItem*)arItems.GetAt(i);
		if(pItem->iImageIndex%2==0)pItem->iImageIndex++;
		else break;
	}
}

BOOL CGfxOutBarCtrl::RemoveAItem(int folder, DWORD dwID,BOOL bRefresh)
{
	CBarFolder * pbf =(CBarFolder*)arFolder.GetAt(folder);
	ASSERT(pbf);
	if(pbf==NULL)return FALSE;
	
	BOOL bSuccess=FALSE;
	for(int i=0;i<pbf->arItems.GetSize();i++)
	{
		CBarItem* pItem=(CBarItem*)pbf->arItems.GetAt(i);
		if(pItem->dwData==dwID)
		{
			pbf->arItems.RemoveAt(i);
			bSuccess=TRUE;
			break;
		}
	}
	if(bRefresh)Invalidate();
	return bSuccess;
}

⌨️ 快捷键说明

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