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

📄 mylabel.cpp

📁 一个多方面查询的系统,也是很辛苦找到,并且做管理系统很多方面都用到的
💻 CPP
📖 第 1 页 / 共 2 页
字号:

				if(!bIsFile)pImageList->Draw(pDC,iImageIndex,ImageStartPoint,ILD_NORMAL);
				else 
				{
					CBitmap *OldBmp;
					CDC DCMem;
					DCMem.CreateCompatibleDC(pDC);
					OldBmp=DCMem.SelectObject(bmpIcon);
				
					BITMAP *bmp=new BITMAP;
					bmpIcon->GetBitmap(bmp);

					pDC->StretchBlt(ImageStartPoint.x-StretchWidth,ImageStartPoint.y-StretchWidth,bmpWidth+2*StretchWidth,bmpWidth+2*StretchWidth,&DCMem,0,0,bmp->bmWidth,bmp->bmHeight,SRCCOPY);
					DCMem.SelectObject(OldBmp);
					DCMem.DeleteDC();

					delete bmp;
				}
			}
		}



		if(iShape==3) //只有图标和文字无边框
		{
			CPoint ImageStartPoint=CPoint(LabelRect.left,LabelRect.CenterPoint().y-bmpWidth/2);
			if(pImageList&&bImage)  //有图片
			{
				//rc为图像框Rect
				CRect rc;
				rc.SetRect(ImageStartPoint.x-StretchWidth,ImageStartPoint.y-StretchWidth,ImageStartPoint.x-StretchWidth+bmpWidth+2*StretchWidth,bmpWidth+2*StretchWidth+ImageStartPoint.y-StretchWidth);
				rcImage=rc;

				if(bAnimate)
				{
					if(iAnimate==2)  //左斜下
					{
						rc.left-=iAnimateStep;
						rc.top+=iAnimateStep;
						rc.right-=iAnimateStep;
						rc.bottom+=iAnimateStep;

						iDirect=-1;
						iAnimate=0;
					} 
					else
					if(iAnimate==-2)   //右斜下
					{
						rc.left+=iAnimateStep;
						rc.top+=iAnimateStep;
						rc.right+=iAnimateStep;
						rc.bottom+=iAnimateStep;

						iDirect=1;
						iAnimate=0;
					}
					else
					if(iAnimate==0)   //中间
					{
						if(iDirect==-1)
						{
							rc.left+=iAnimateStep;
							rc.top-=iAnimateStep;
							rc.right+=iAnimateStep;
							rc.bottom-=iAnimateStep;
						
							iAnimate=-2;
						}

						if(iDirect==1)
						{
							rc.left-=iAnimateStep;
							rc.top-=iAnimateStep;
							rc.right-=iAnimateStep;
							rc.bottom-=iAnimateStep;
						
							iAnimate=2;
						}
					}
				}


				rcLabel.SetRect(LabelRect.left+22,LabelRect.top+2,LabelRect.right-2,LabelRect.bottom-2);

				if(!bIsFile)pImageList->Draw(pDC,iImageIndex,ImageStartPoint,ILD_NORMAL);
				else 
				{
					CBitmap *OldBmp;
					CDC DCMem;
					DCMem.CreateCompatibleDC(pDC);
					OldBmp=DCMem.SelectObject(bmpIcon);

					BITMAP *bmp=new BITMAP;
					bmpIcon->GetBitmap(bmp);
					
					if(false==pDC->StretchBlt(rc.left,rc.top,rc.Width(),rc.Height(),&DCMem,0,0,bmp->bmWidth,bmp->bmHeight,SRCCOPY))
						pDC->DrawText("这还有一个", rcLabel, DT_VCENTER|DT_SINGLELINE);
					DCMem.SelectObject(OldBmp);
					DCMem.DeleteDC();

					delete bmp;
				}

			
				if(bPass)pDC->Draw3dRect(rc, crHilightBorder, crBackGroundColor1);
				if(bPressed)pDC->Draw3dRect(rc, crDkShadowBorder, crHilightBorder);
				
			}
			else  //无图片
			{
				if(bPass)
				{
					CBrush brush;
					brush.CreateSolidBrush(RGB(196, 236, 245));
					pDC->FillRect(LabelRect,&brush);
				}
				rcLabel.SetRect(LabelRect.left+2,LabelRect.top+2,LabelRect.right-2,LabelRect.bottom-2);
			}
			
			pDC->DrawText(CString(cName), rcLabel, DT_VCENTER|DT_SINGLELINE);
		}

		if(iShape==4) //只有文字无边框
		{
			pDC->DrawText(CString(cName), LabelRect, DT_VCENTER|DT_SINGLELINE);
		}

		if(iShape==5) //输入框
		{
			if(!bEditShow)  //如果没有则画
			{
				pEdit->setPos(LabelRect);
				pEdit->Create(dwEditStyle,pParentWnd,this,PID);
				pEdit->setAlwaysShow(true);
			}
		}

		if(iShape==6) //标签变输入框
		{
			CBrush *pOldBrush,brush;
			CPen *pOldPen,pen;

			pen.CreatePen(PS_SOLID | PS_COSMETIC, 1, crTextColor);

//			if(!bPass)
//			{
				brush.CreateSolidBrush(crBackcol);
//			}
//			else  
//			{
//				brush.CreateSolidBrush(crPass);
//			}
//		
			pOldBrush = pDC->SelectObject(&brush);
			pOldPen = pDC->SelectObject(&pen);

	//		pDC->RoundRect(CRect(LabelRect.left,LabelRect.CenterPoint().y-5,LabelRect.right,LabelRect.CenterPoint().y+5),CPoint(18,18));

			pDC->MoveTo(LabelRect.left,LabelRect.bottom-2);
			pDC->LineTo(LabelRect.right-2,LabelRect.bottom-2);

			pDC->SelectObject(pOldBrush);
			pDC->SelectObject(pOldPen);

			pDC->DrawText(CString(cName), LabelRect, DT_VCENTER|DT_SINGLELINE);
		}
	
			
	pDC->SetTextColor(RGB(0,0,0));
	pDC->SelectObject(of);
}



void CMyLabel::OnLButtonDown(CPoint point)
{
	if(bEditShow)return;

	if(iShape==4)return;

	if(bEnable)
	if(LabelRect.PtInRect(point))
	{
		if(iShape==6&&bRename)  //产生输入框
		{
			pEdit=new CMyEdit;
			pEdit->setPos(LabelRect);
			pEdit->Create(dwEditStyle,pParentWnd,this,PID);
			pEdit->SetFocus();

//			return;
		} 

		bPressed=true;

		if(iShape==2)
		{
			CMyMsg *msg=new CMyMsg;
			msg->id=MID;
			msg->act=iAct;
			msg->skip=0;
			msg->label=this;
			pParentWnd->SendMessage(WM_ACCEPT,PID,(LPARAM)msg);
		}
	}
}

void CMyLabel::OnLButtonUp(CPoint point)
{
//	if(bEditShow)return;

	if(iShape==4)return;

	if(bEnable)
	if((bPressed&&iShape!=2))
	{
		bPressed=false;//属性框标题无弹起

		CMyMsg *msg=new CMyMsg;
		msg->id=MID;
		msg->act=iAct;
		msg->skip=0;
		msg->label=this;
		pParentWnd->SendMessage(WM_ACCEPT,PID,(LPARAM)msg);
	}
}

void CMyLabel::OnMouseMove(CPoint point)
{
	if(iShape==4)return;

	if(!LabelRect.PtInRect(point))
	{
		if(iShape!=2)bPressed=false;
		bPass=false;
	}
	else
	if(bPass==false)
	{
		bPass=true;

		if(bEditShow)return;

		//发生移入事件
		if(iShape==3&&bImage==true&&rcImage.PtInRect(point))
		{
			CMyMsg *msg=new CMyMsg;
			msg->id=MID;
			msg->act=iAct;
			msg->skip=1;
			msg->label=this;
			pParentWnd->SendMessage(WM_ACCEPT,PID,(LPARAM)msg);
		}
	}
}

void CMyLabel::setPos(int left, int top, int right, int bottom)
{
	LabelRect.SetRect(left,top,right,bottom);
	rcLabel.SetRect(LabelRect.left+2,LabelRect.top+2,LabelRect.right-2,LabelRect.bottom-2);  //决定输入框
}

void CMyLabel::setName(char *name)
{
	if (name)delete cName;
	cName = new char[lstrlen(name)+1];
	ASSERT(cName);
	lstrcpy(cName, name);

	if(iShape==5)
		pEdit->SetWindowText(name);

}

void CMyLabel::OnRButtonDown(CPoint point)
{
}

void CMyLabel::SetEnable(bool enable)
{
	bEnable=enable;
	if(iShape==5)pEdit->setEnable(enable);
}


void CMyLabel::OutRect()
{
	if(iShape==4||iShape==5)return;

	bPass=false;
	bPressed=false;
}


bool CMyLabel::OpenBitmap(char *filename)
{
	HBITMAP hImage = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP,0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);

	if (!hImage)
		return FALSE;

	if(bmpIcon)bmpIcon->DeleteObject();
	//构造位图对象
	if (!bmpIcon->Attach(hImage)) {
		AfxMessageBox("Bitmap could not be attached");
		return FALSE;
	}

	bIsFile=true;

	return true;
}

void CMyLabel::SetTextCol(COLORREF col)
{
	crTextColor=col;
}

void CMyLabel::setVisible(bool visible)
{
	bVisible=visible;
	bEnable=visible;
}

void CMyLabel::setShape3Animate(bool animate)
{
	bAnimate=animate;
}

void CMyLabel::setFont(CFont *f)
{
	font=f;
}

⌨️ 快捷键说明

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