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

📄 barwnd.cpp

📁 我自己整理的一些VC源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			{
				iItem=i+ivstartItem;
				break;
			}
			else
				iItem=-1;
		}
		GetArrowRect(index,rcUp,rcDown);
		if(cx>=rcUp.left && cx<=rcUp.right && cy>=rcUp.top && cy<=rcUp.bottom)
			arrow=pointup;
		else if(cx>=rcDown.left && cx<=rcDown.right && cy>=rcDown.top && cy<=rcDown.bottom)
			arrow=pointdown;
		else
			arrow=non;
	}
}

void CBarWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CClientDC dc(this);

	if(preindex>=0)
		DrawForder(preindex,&dc,false);

	KillTimer(1);

	ReleaseCapture();
	mouseDown=false;
	preindex=-1;

	CForderBar *pForder;
	int iCount,ivisible=-1;
	iCount=arForderbar.GetSize();
	for(int index=0;index<iCount;index++)
	{
		pForder=(CForderBar *)arForderbar.GetAt(index);
		if(pForder->visible==true)
		{
			ivisible=index;
		}
	}
/////////////////////////////////////////////////////////////////////////////////
	int iForder,iItem;
	HitOnPosEx(point.x,point.y,iForder,iItem);
	if(iForder>=0&&iItem>=0&&iItem!=preiItem)
	{
		DrawItem(preiForder,preiItem,&dc,normal);
		preiForder=iForder;
		preiItem=iItem;
	}
	else if(iForder>=0&&iItem>=0)
	{
		DrawItem(preiForder,preiItem,&dc,mouse_on);
	}

	//////////////////////////////////////////////////////////////////////
	//鼠标单击在项目上 触发相关事件
	if(iForder>=0&&iItem>=0)
	{
		OnItem(iForder,iItem,point);
	}
////////////////////////////////////////////////////////////////////////////////////
	if(iForder>=0)
	{
		DrawArrow(iForder,&dc,normal);
		if(arrow==pointup)
			OnUpArrow(iForder);
		else if(arrow)
			OnDownArrow(iForder);
	}

	int iBar;
	HitOnPos(point.x,point.y,iBar);
	if(iBar>=0)
		DrawArrow(iBar,&dc);
	if(iBar>=0&&ivisible!=iBar)
	{
		pForder=(CForderBar *)arForderbar.GetAt(ivisible);
		pForder->visible=false;
		ivisible=iBar;
		pForder=(CForderBar *)arForderbar.GetAt(iBar);
		pForder->visible=true;
	}
	else
		return;

	CRect rcWnd,rcForder,rcFC,rcFill;
	int tmp;
	GetClientRect(&rcWnd);

	for(index=0;index<iCount;index++)
	{
		pForder=(CForderBar *)arForderbar.GetAt(index);
		if(index<iBar)
		{
			rcForder=CRect(rcWnd.left,rcWnd.top+index*20,rcWnd.right,rcWnd.top+index*20+20);
			pForder->SetForderRect(rcForder);
		}
		else if(index==iBar)
		{
			if(rcWnd.Height()-iCount*20<0)
				tmp=0;
			else
				tmp=rcWnd.Height()-iCount*20;
			rcForder=CRect(rcWnd.left,rcWnd.top+index*20,rcWnd.right,rcWnd.top+index*20+20+tmp);
			pForder->SetForderRect(rcForder);
			if(pForder->pSon)
			{
				GetForderClientRect(index,rcFC);
				pForder->pSon->SetWindowPos(0,rcFC.left,rcFC.top,rcFC.right,rcFC.Height(),SWP_NOZORDER);
			}
		}
		else
		{
			rcForder=CRect(rcWnd.left,rcWnd.bottom-(iCount-index)*20,rcWnd.right,rcWnd.bottom-(iCount-index)*20+20);
			pForder->SetForderRect(rcForder);
		}
	}

	GetForderClientRect(ivisible,rcFill);
	CBrush brush(GetSysColor(COLOR_3DSHADOW));
	dc.FillRect(&rcFill,&brush);
	ivstartItem=0;
	downarrow=false;
	uparrow=false;

	for(int i=0;i<iCount;i++)
	{
		DrawForder(i,&dc,false);
	}

	CWnd::OnLButtonUp(nFlags, point);
}

void CBarWnd::OnMouseMove(UINT nFlags, CPoint point) 
{
	int index;

	CClientDC dc(this);

	HitOnPos(point.x,point.y,index);
	if(index>=0&&index!=preindex&&preindex>=0)
	{
		DrawForder(preindex,&dc,false);
		DrawForder(index,&dc,true);
		preindex=index;
	}
	else if(index<0&&preindex>=0)
	{
		DrawForder(preindex,&dc,false);
	}

	int iForder=-1,iItem=-1;
	HitOnPosEx(point.x,point.y,iForder,iItem);
	if(iForder>=0 && iItem>=0 && iItem!=preiItem && preiForder>=0 && preiItem>=0)
	{
		DrawItem(preiForder,preiItem,&dc,normal);
		preiForder=iForder;
		preiItem=iItem;
	}
	else if(iForder>=0 && iItem>=0 && mouseDown)
	{
		DrawItem(iForder,iItem,&dc,mouse_down);
		preiForder=iForder;
		preiItem=iItem;
	}
	else if(iForder>=0 && iItem>=0 && !mouseDown)
	{
		DrawItem(iForder,iItem,&dc,mouse_on);
		preiForder=iForder;
		preiItem=iItem;
	}
	else if(preiForder>=0 && preiItem>=0)
	{
		DrawItem(preiForder,preiItem,&dc,normal);
		preiForder=-1;
		preiItem=-1;
	}

	if(iForder>=0 && !mouseDown)
	{
		DrawArrow(iForder,&dc,mouse_on);
		prearrow=arrow;
	}
	else if(iForder>=0 && prearrow)
	{
		DrawArrow(iForder,&dc,normal);
		prearrow=non;
	}
	if(!arrow)
		KillTimer(1);

	CWnd::OnMouseMove(nFlags, point);
}

//	获取抽屉框数
int CBarWnd::GetForderCount()
{
	return arForderbar.GetSize();
}

//	获取抽屉框子条件数
int CBarWnd::CForderBar::GetItemCount()
{
	return arItem.GetSize();
}

void CBarWnd::SetForderImageList(int iForder,CImageList *pImage,int iImagesize)
{
	CForderBar * pForder=(CForderBar *)arForderbar.GetAt(iForder);
	if(iImagesize)
	{
		pForder->nricon=pImage;
		pForder->smallicon=NULL;
	}
	else
	{
		pForder->smallicon=pImage;
		pForder->nricon=NULL;
	}
}

CBarWnd::CBarItem::CBarItem(const char *name,int iImage,DWORD ExData)
{
	itemName=NULL;
	imageIndex=iImage;
	exData = ExData;
	if(name)
	{
		itemName=new char[lstrlen(name)+1];
		ASSERT(itemName);
		lstrcpy(itemName,name);
	}
}

CBarWnd::CBarItem::~CBarItem()
{
	if(itemName)
		delete [] itemName;
}

void CBarWnd::CForderBar::AddItem(const char *name,int iImage,DWORD ExData)
{
	CBarItem * pItem=new CBarItem(name,iImage,ExData);
	if(pItem)
		arItem.Add((void *)pItem);
}

int CBarWnd::GetForderImageListSize(int iForder)
{
	CForderBar * pForder=(CForderBar *) arForderbar.GetAt(iForder);
	if(pForder->nricon!=NULL)
		return 1;
	else if(pForder->smallicon!=NULL)
		return 0;
	else
		return -1;
}

//	获取一个抽屉框的子条件的矩形信息
void CBarWnd::GetForderItemRect(int iForder,int iItem,CRect &rect)
{
	CForderBar * pForder=(CForderBar *) arForderbar.GetAt(iForder);
	CRect rcClient;
	GetForderClientRect(iForder,rcClient);
	if(GetForderImageListSize(iForder)>0)
		rect=CRect(rcClient.left,rcClient.top+iItem*55+6,rcClient.right,rcClient.top+iItem*55+55);
	else if(GetForderImageListSize(iForder)==0)
		rect=CRect(rcClient.left,rcClient.top+iItem*26+10,rcClient.right,rcClient.top+iItem*26+26);
}

//	获取一个抽屉框的子条件的实际矩形信息
void CBarWnd::GetForderItemActiveRect(int iForder,int iItem,CRect &rcImage,CRect &rcText)
{
	CRect rcItem;
	int tw=6;
	int txtWid=0,imaWid=0;
	CForderBar * pForder=(CForderBar *)arForderbar.GetAt(iForder);
	CBarItem * pItem=(CBarItem *)pForder->arItem.GetAt(iItem+ivstartItem);
	GetForderItemRect(iForder,iItem,rcItem);
	if(!GetForderImageListSize(iForder))
	{
		if(rcItem.Width()<=22)
		{
			rcImage=CRect(rcItem.left+3,rcItem.top,rcItem.Width(),rcItem.bottom);
			rcText=CRect(rcItem.Width()+1,rcItem.top,rcItem.Width()+1,rcItem.bottom);
		}
		else
		{
			txtWid=strlen(pItem->itemName)*tw;
			rcImage=CRect(rcItem.left+3,rcItem.top,rcItem.left+19,rcItem.bottom);
			rcText=CRect(rcItem.left+30,rcItem.top,rcItem.left+30+txtWid,rcItem.bottom);
		}
	}
	else if(GetForderImageListSize(iForder)>0)
	{
		if(rcItem.Width()<=32)
		{
			imaWid=(32-rcItem.Width())/2;
			rcImage=CRect(rcItem.left-imaWid,rcItem.top,rcItem.left-imaWid+32,rcItem.bottom-16);
			if(rcItem.Width()<(int)strlen(pItem->itemName)*tw)
			{
				txtWid=(strlen(pItem->itemName)*tw-rcItem.Width())/2;
				rcText=CRect(rcItem.left-txtWid,rcItem.bottom-14,rcItem.left-txtWid+strlen(pItem->itemName)*tw,rcItem.bottom);
			}
			else
			{
				txtWid=(rcItem.Width()-strlen(pItem->itemName)*tw)/2;
				rcText=CRect(rcItem.left+txtWid,rcItem.bottom-14,rcItem.left+txtWid+strlen(pItem->itemName)*tw,rcItem.bottom);
			}
		}
		else
		{
			imaWid=(rcItem.Width()-32)/2;
			rcImage=CRect(rcItem.left+imaWid,rcItem.top,rcItem.left+imaWid+32,rcItem.bottom-16);
			if(rcItem.Width()<(int)strlen(pItem->itemName)*tw)
			{
				txtWid=(strlen(pItem->itemName)*tw-rcItem.Width())/2;
				rcText=CRect(rcItem.left-txtWid,rcItem.bottom-14,rcItem.left-txtWid+strlen(pItem->itemName)*tw,rcItem.bottom);
			}
			else
			{
				txtWid=(rcItem.Width()-strlen(pItem->itemName)*tw)/2;
				rcText=CRect(rcItem.left+txtWid,rcItem.bottom-14,rcItem.left+txtWid+strlen(pItem->itemName)*tw,rcItem.bottom);
			}
		}
	}
}

void CBarWnd::DrawItem(int iForder,int iItem,CDC *pDC,DrawStyle nStyle)
{
	int item=iItem-ivstartItem;
	CForderBar * pForder=(CForderBar *)arForderbar.GetAt(iForder);
	CBarItem * pItem=(CBarItem *) pForder->arItem.GetAt(iItem);
	CImageList * pImageList;
	CPtrArray * arIcon;
	int obk=pDC->SetBkMode(TRANSPARENT);
	CFont * oft=(CFont *)pDC->SelectObject(&font);
	COLORREF txtColor,otc;
	if(nStyle==mouse_on)
		txtColor=RGB(255,255,0);
	else if(nStyle==normal)
		txtColor=RGB(255,255,255);
	else if(nStyle==mouse_down)
		txtColor=RGB(0,0,255);
	else
		txtColor=RGB(255,255,255);
	otc=pDC->SetTextColor(txtColor);
	CRect rcItem,rcItemtext;
	GetForderItemRect(iForder,item,rcItem);
	rcItemtext=rcItem;
	int textPos=0;
	if(GetForderImageListSize(iForder)>0)
	{
		pImageList=pForder->nricon;
		arIcon=&arNrIcon;
		textPos=1;
	}
	else
	{
		pImageList=pForder->smallicon;
		arIcon=&arSmIcon;
		textPos=0;
	}
	if(pItem!=NULL)
	{
		IMAGEINFO ii;
		pImageList->GetImageInfo(pItem->imageIndex,&ii);
		CSize szImage = CRect(ii.rcImage).Size();
		CPoint pt;
		if (textPos)
		{
			if(rcItem.Width()>32)
				pt.x = rcItem.left+(rcItem.Width()-32)/2;
			else
				pt.x = rcItem.left-(32-rcItem.Width())/2;
			pt.y = rcItem.top;
			rcItemtext.top=rcItem.bottom-14;
			pDC->DrawText(CString(pItem->itemName),&rcItemtext,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}
		else
		{
			pt.x = rcItem.left+3;
			pt.y = rcItem.top;
			rcItemtext.left+=32;
		//	rcItemtext.bottom+=3;
			pDC->DrawText(CString(pItem->itemName),&rcItemtext,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
		}
		if(nStyle==redraw)
		{
			if( GetForderImageListSize(iForder)>0 )
			{
				HICON m_hIcon;
				if(pItem->imageIndex < arIcon->GetSize())
				{
					m_hIcon=(HICON)arIcon->GetAt(pItem->imageIndex);
					pDC->DrawIcon(pt.x,pt.y,m_hIcon);
				}
			}
			else pImageList->Draw(pDC, pItem->imageIndex, pt, ILD_NORMAL);
		}
	}
	CRect rcIma,rcTxt;
	GetForderItemActiveRect(iForder,item,rcIma,rcTxt);
	if(nStyle==mouse_on)
		pDC->Draw3dRect(&rcIma,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));
	else if(nStyle==mouse_down)
		pDC->Draw3dRect(&rcIma,GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DHILIGHT));
	else
		pDC->Draw3dRect(&rcIma,GetSysColor(COLOR_3DSHADOW),GetSysColor(COLOR_3DSHADOW));
	pDC->SetTextColor(otc);
	pDC->SelectObject(oft);
	pDC->SetBkMode(obk);
}

void CBarWnd::DrawForderItem(int iForder,CDC *pDC)
{
	CForderBar * pForder=(CForderBar *) arForderbar.GetAt(iForder);
	int iCount,iItemCount=pForder->GetItemCount();
	CRect rcClient;

⌨️ 快捷键说明

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