Ejemplo n.º 1
0
//绘画背景
BOOL CWndUserInfoCtrl::OnEraseBkgnd(CDC * pDC)
{
	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//建立缓冲
	CImage ImageBuffer;
	ImageBuffer.Create(rcClient.Width(),rcClient.Height(),32);

	//创建 DC
	CImageDC BufferDC(ImageBuffer);
	CDC * pBufferDC=CDC::FromHandle(BufferDC);

	//变量定义
	HINSTANCE hInstance=AfxGetInstanceHandle();
	CSkinRenderManager * pSkinRenderManager=CSkinRenderManager::GetInstance();

	//加载资源
	CBitImage ImageTitleL;
	CBitImage ImageTitleM;
	CBitImage ImageTitleR;
	ImageTitleL.LoadFromResource(hInstance,IDB_USER_INFO_L);
	ImageTitleM.LoadFromResource(hInstance,IDB_USER_INFO_M);
	ImageTitleR.LoadFromResource(hInstance,IDB_USER_INFO_R);

	//渲染资源
	pSkinRenderManager->RenderImage(ImageTitleL);
	pSkinRenderManager->RenderImage(ImageTitleM);
	pSkinRenderManager->RenderImage(ImageTitleR);

	//绘画背景
	ImageTitleL.BitBlt(BufferDC,0,0);

	//填充中间
	for (INT nXPos=ImageTitleL.GetWidth();nXPos<rcClient.Width();nXPos+=ImageTitleM.GetWidth())
	{
		ImageTitleM.BitBlt(BufferDC,nXPos,0);
	}

	//绘画背景
	ImageTitleR.BitBlt(BufferDC,rcClient.Width()-ImageTitleR.GetWidth(),0);

	//设置环境
	pBufferDC->SetBkMode(TRANSPARENT);
	pBufferDC->SelectObject(CSkinResourceManager::GetInstance()->GetDefaultFont());

	//用户信息
	CGlobalUserInfo * pGlobalUserInfo=CGlobalUserInfo::GetInstance();
	tagGlobalUserData * pGlobalUserData=pGlobalUserInfo->GetGlobalUserData();

	//绘画用户
	if (pGlobalUserData->dwUserID!=0L)
	{
		//绘画底框
		if ((m_bHoverUnderWrite==true)||((m_EditUnderWrite.m_hWnd!=NULL)&&(m_EditUnderWrite.IsWindowVisible()==TRUE)))
		{
			//加载资源
			CPngImage ImageUnderWriteL;
			CPngImage ImageUnderWriteM;
			CPngImage ImageUnderWriteR;
			ImageUnderWriteL.LoadImage(AfxGetInstanceHandle(),TEXT("UNDER_WRITE_L"));
			ImageUnderWriteM.LoadImage(AfxGetInstanceHandle(),TEXT("UNDER_WRITE_M"));
			ImageUnderWriteR.LoadImage(AfxGetInstanceHandle(),TEXT("UNDER_WRITE_R"));

			//绘画两边
			ImageUnderWriteL.DrawImage(pBufferDC,m_rcUnderWrite.left,m_rcUnderWrite.top);
			ImageUnderWriteR.DrawImage(pBufferDC,m_rcUnderWrite.right-ImageUnderWriteR.GetWidth(),m_rcUnderWrite.top);

			//绘画中间
			INT nXStart=m_rcUnderWrite.left+ImageUnderWriteL.GetWidth();
			INT nXTerminate=m_rcUnderWrite.right-ImageUnderWriteR.GetWidth();
			for (INT nXPos=nXStart;nXPos<nXTerminate;nXPos+=ImageUnderWriteM.GetWidth())
			{
				ImageUnderWriteM.DrawImage(pBufferDC,nXPos,m_rcUnderWrite.top,__min(nXTerminate-nXPos,ImageUnderWriteM.GetWidth()),ImageUnderWriteM.GetHeight(),0,0);
			}
		}

		//绘画边框
		if (m_bHoverFace==true)
		{
			theApp.m_FaceItemControlModule->DrawFaceItemFrame(pBufferDC,17,18,ITEM_FRAME_HOVER);
		}

		//绘画头像
		if (pGlobalUserData->CustomFaceInfo.dwDataSize!=0)
		{
			DWORD * pdwCustomFace=pGlobalUserData->CustomFaceInfo.dwCustomFace;
			theApp.m_FaceItemControlModule->DrawFaceNormal(pBufferDC,16,17,pdwCustomFace);
		}
		else
		{
			theApp.m_FaceItemControlModule->DrawFaceNormal(pBufferDC,16,17,pGlobalUserData->wFaceID);
		}

		//绘画标题
		pBufferDC->SetTextColor(RGB(0,0,0));
		pBufferDC->TextOut(88,16,TEXT("昵 称:"));
		pBufferDC->TextOut(88,36,TEXT("奖 牌:"));
		pBufferDC->TextOut(88,56,TEXT("签 名:"));

		//构造奖牌
		TCHAR szUserMedal[64]=TEXT("");
		_sntprintf(szUserMedal,CountArray(szUserMedal),TEXT("%ld"),pGlobalUserData->dwUserMedal);

		//输出奖牌
		CRect rcUserMedal;
		rcUserMedal.SetRect(130,36,rcClient.Width()-15,48);
		pBufferDC->DrawText(szUserMedal,lstrlen(szUserMedal),&rcUserMedal,DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);

		//输出帐号
		CRect rcNickName;
		rcNickName.SetRect(130,16,rcClient.Width()-15,28);
		pBufferDC->DrawText(pGlobalUserData->szNickName,lstrlen(pGlobalUserData->szNickName),&rcNickName,DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);

		//变量定义
		LPCTSTR pszUnderWrite=NULL;
		COLORREF crUnderWrite=RGB(0,0,0);

		//签名位置
		CRect rcUnderWrite;
		rcUnderWrite.SetRect(130,56,rcClient.Width()-15,68);

		//常规状态
		if ((m_EditUnderWrite.IsModifyStatus()==false)&&(pGlobalUserData->szUnderWrite[0]!=0))
		{
			crUnderWrite=RGB(0,0,0);
			pszUnderWrite=pGlobalUserData->szUnderWrite;
		}

		//修改状态
		if ((m_EditUnderWrite.IsModifyStatus()==true)&&(m_EditUnderWrite.m_szUnderWrite[0]!=0))
		{
			crUnderWrite=RGB(100,100,100);
			pszUnderWrite=m_EditUnderWrite.m_szUnderWrite;
		}

		//提示状态
		if (pszUnderWrite==NULL)
		{
			crUnderWrite=RGB(150,150,150);
			pszUnderWrite=TEXT("编辑个性签名");
		}

		//输出签名
		pBufferDC->SetTextColor(crUnderWrite);
		pBufferDC->DrawText(pszUnderWrite,lstrlen(pszUnderWrite),&rcUnderWrite,DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);
	}

	//绘画界面
	pDC->BitBlt(0,0,rcClient.Width(),rcClient.Height(),pBufferDC,0,0,SRCCOPY);

	return TRUE;
}
Ejemplo n.º 2
0
//绘画函数
VOID CSkinMenuKernel::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	//效验参数
	ASSERT(lpDrawItemStruct->CtlType==ODT_MENU);
	if (lpDrawItemStruct->CtlType!=ODT_MENU) return;

	//变量定义
	CRect rcItem=lpDrawItemStruct->rcItem;
	CDC * pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
	CSkinMenuItem * pSkinMenuItem=(CSkinMenuItem *)lpDrawItemStruct->itemData;

	//自绘框架
	if(m_bRemoveBorder==TRUE)
	{
		//区域偏移
		rcItem.OffsetRect(FRAME_OUT_CX+FRAME_IN_CX,FRAME_OUT_CY+FRAME_IN_CY);

		//变量定义
		CRect rcClient(0,0,0,0);		
		GetClientRect(m_hWnd,rcClient);

		//绘制外框
		pDC->FillSolidRect(0,0,rcClient.Width(),FRAME_OUT_CY,m_SkinAttribute.m_crOutFrame);
		pDC->FillSolidRect(rcClient.right-FRAME_OUT_CX,FRAME_OUT_CY,FRAME_OUT_CX,rcClient.Height()-FRAME_OUT_CY,m_SkinAttribute.m_crOutFrame);
		pDC->FillSolidRect(0,rcClient.Height()-FRAME_OUT_CY,rcClient.Width()-FRAME_OUT_CX,FRAME_OUT_CY,m_SkinAttribute.m_crOutFrame);
		pDC->FillSolidRect(0,FRAME_OUT_CY,FRAME_OUT_CX,rcClient.Height()-FRAME_OUT_CY,m_SkinAttribute.m_crOutFrame);

		//绘制内框
		pDC->FillSolidRect(FRAME_OUT_CX,FRAME_OUT_CY,rcClient.Width()-2*FRAME_OUT_CX,FRAME_IN_CY,m_SkinAttribute.m_crInFrame);
		pDC->FillSolidRect(rcClient.right-FRAME_OUT_CX-FRAME_IN_CX,FRAME_OUT_CY,FRAME_IN_CX,rcClient.Height()-2*FRAME_OUT_CY,m_SkinAttribute.m_crInFrame);
		pDC->FillSolidRect(FRAME_OUT_CX,rcClient.Height()-FRAME_OUT_CY-FRAME_IN_CY,rcClient.Width()-2*FRAME_OUT_CX,FRAME_IN_CY,m_SkinAttribute.m_crInFrame);
		pDC->FillSolidRect(FRAME_OUT_CX,FRAME_OUT_CY,FRAME_IN_CX,rcClient.Height()-2*FRAME_OUT_CY,m_SkinAttribute.m_crInFrame);
	}

	//状态变量
	bool bChecked=((lpDrawItemStruct->itemState&ODS_CHECKED)!=0);
	bool bSelected=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0);
	bool bGrayed=((lpDrawItemStruct->itemState&ODS_DISABLED)||(lpDrawItemStruct->itemState&ODS_GRAYED));

	//绘画背景
	COLORREF crMenuBar=m_SkinAttribute.m_crMenuBar;
	COLORREF crBorder=m_SkinAttribute.m_crSelectBorder;
	COLORREF crNormalBack=m_SkinAttribute.m_crNormalBack;
	pDC->FillSolidRect(rcItem.left,rcItem.top,MENU_BAR_CX,rcItem.Height(),m_SkinAttribute.m_crMenuBar);
	pDC->FillSolidRect(rcItem.left+MENU_BAR_CX,rcItem.top,rcItem.Width()-MENU_BAR_CX,rcItem.Height(),m_SkinAttribute.m_crNormalBack);	

	//焦点边框
	if ((bSelected==true)&&(bGrayed==false)&&(pSkinMenuItem!=NULL)&&(pSkinMenuItem->m_MenuItemType!=MenuItemType_Separator))
	{
		pDC->Draw3dRect(rcItem.left+1,rcItem.top+1,rcItem.Width()-2,rcItem.Height()-2,crBorder,crBorder);
		pDC->FillSolidRect(rcItem.left+2,rcItem.top+2,rcItem.Width()-4,rcItem.Height()-4,m_SkinAttribute.m_crSelectBack);
	}

	//选择标志
	if (bChecked==true)
	{
		//加载资源
		CBitImage ImageMenuFlags;
		ImageMenuFlags.LoadFromResource(GetModuleHandle(SKIN_CONTROL_DLL_NAME),IDB_SKIN_MENU_FLAGS);

		//渲染资源
		CSkinRenderManager * pSkinRenderManager=CSkinRenderManager::GetInstance();
		if (pSkinRenderManager!=NULL) pSkinRenderManager->RenderImage(ImageMenuFlags);

		//绘画界面
		ImageMenuFlags.BitBlt(pDC->m_hDC,rcItem.left+1,rcItem.top+1,ImageMenuFlags.GetWidth()/2,
			ImageMenuFlags.GetHeight(),((bSelected==true)&&(bGrayed==false))?ImageMenuFlags.GetWidth()/2:0,0);
	}

	//其他菜单
	if (pSkinMenuItem==NULL)
	{
		//获取信息
		MENUITEMINFO MenuItemInfo;
		MenuItemInfo.cbSize=sizeof(MenuItemInfo);
		MenuItemInfo.fMask=MIIM_FTYPE|MIIM_BITMAP;
		GetMenuItemInfo(lpDrawItemStruct->itemID,&MenuItemInfo);

		return;
	}

	//界面菜单
	switch (pSkinMenuItem->m_MenuItemType)
	{
	case MenuItemType_Image:		//图形菜单
		{
			//变量定义
			CSkinMenuImage * pSkinMenuImage=(CSkinMenuImage *)pSkinMenuItem;

			//创建 DC
			CDC ImageDC;
			ImageDC.CreateCompatibleDC(pDC);
			ImageDC.SelectObject(pSkinMenuImage->m_hBitmap);

			//获取信息
			BITMAP BitmapInfo;
			GetObject(pSkinMenuImage->m_hBitmap,sizeof(BitmapInfo),&BitmapInfo);

			//绘画位图
			INT nYPos=rcItem.top+3;
			INT nXPos=rcItem.left+MENU_BAR_CX+SPACE_LEFT;
			pDC->BitBlt(nXPos,nYPos,BitmapInfo.bmWidth,BitmapInfo.bmHeight,&ImageDC,0,0,SRCCOPY);

			//释放 DC
			ImageDC.DeleteDC();

			break;
		}
	case MenuItemType_String:		//字符菜单
		{
			//变量定义
			CSkinMenuString * pSkinMenuString=(CSkinMenuString *)pSkinMenuItem;

			//设置颜色
			pDC->SetBkMode(TRANSPARENT);
			pDC->SelectObject(CSkinResourceManager::GetInstance()->GetDefaultFont());

			//设置颜色
			if (bGrayed==true) pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
			else if (bSelected==true) pDC->SetTextColor(m_SkinAttribute.m_crSelectText);
			else pDC->SetTextColor(m_SkinAttribute.m_crNormalText);

			//绘画字符
			CRect rcString;
			rcString.top=rcItem.top;
			rcString.bottom=rcItem.bottom;
			rcString.right=rcItem.right-SPACE_RIGHT;
			rcString.left=rcItem.left+MENU_BAR_CX+SPACE_LEFT;
			pDC->DrawText(pSkinMenuString->m_strString,pSkinMenuString->m_strString.GetLength(),&rcString,DT_SINGLELINE|DT_VCENTER|DT_NOCLIP);

			break;
		}
	case MenuItemType_Separator:	//拆分菜单
		{
			//绘画拆分
			pDC->FillSolidRect(rcItem.left+MENU_BAR_CX+SPACE_LEFT,rcItem.top+1,rcItem.Width()-MENU_BAR_CX-SPACE_LEFT-SPACE_RIGHT,
				rcItem.Height()-2,m_SkinAttribute.m_crSeparator);

			break;
		}
	}

	return;
}