//界面绘画函数 void CSkinButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //定义变量 CRect ClientRect; GetClientRect(&ClientRect); bool bDisable=((lpDrawItemStruct->itemState&ODS_DISABLED)!=0); bool bButtonDown=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0); //设置 DC HDC hDC=lpDrawItemStruct->hDC; //获取文字 CString strText; GetWindowText(strText); //加载背景图 CImageHandle ImageHandle; if (m_ImageBack.IsSetLoadInfo()) ImageHandle.AttachResource(&m_ImageBack); else ImageHandle.AttachResource(&m_SkinAttribute.m_ImageBack); if (ImageHandle.IsResourceValid()) { //计算位图位置 int iPartWidth=ImageHandle->GetWidth()/5,iDrawPos=0; if (bDisable) iDrawPos=iPartWidth*4; else if (bButtonDown) iDrawPos=iPartWidth; else if (m_bHovering) iDrawPos=iPartWidth*3; else if (lpDrawItemStruct->itemState&ODS_FOCUS) iDrawPos=iPartWidth*2; //绘画背景图 if (m_bExpand==false) ImageHandle->BitBlt(hDC,0,0,ClientRect.Width(),ClientRect.Height(),iDrawPos,0,SRCCOPY); else ImageHandle->StretchBlt(hDC,0,0,ClientRect.Width(),ClientRect.Height(),iDrawPos,0,iPartWidth,ImageHandle->GetHeight(),SRCCOPY); } else { //绘画默认界面 CDC * pDC=CDC::FromHandle(hDC); pDC->FillSolidRect(&ClientRect,GetSysColor(COLOR_BTNFACE)); if (bButtonDown) pDC->Draw3dRect(&ClientRect,GetSysColor(COLOR_WINDOWFRAME),GetSysColor(COLOR_3DHILIGHT)); else pDC->Draw3dRect(&ClientRect,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_WINDOWFRAME)); } //绘画图标 if (bButtonDown) ClientRect.top+=2; if (m_hIcon) { DrawIconEx(hDC,ClientRect.left+6,ClientRect.top+(ClientRect.Height()-16)/2+1,m_hIcon,16,16,0,NULL,DI_NORMAL); ClientRect.left+=22; } //绘画字体 ClientRect.top+=1; ::SetBkMode(hDC,TRANSPARENT); if (bDisable) ::SetTextColor(hDC,GetSysColor(COLOR_GRAYTEXT)); else ::SetTextColor(hDC,m_crTextColor); DrawText(hDC,strText,strText.GetLength(),ClientRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); return; }
//界面绘画函数 void CSkinButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //加载背景图 CImageHandle ImageHandle; if (m_ImageBack.IsSetLoadInfo()) ImageHandle.AttachResource(&m_ImageBack); else { CRect ClientRect1; GetClientRect(&ClientRect1); ImageHandle.AttachResource(&m_SkinAttribute.m_ImageBack); SetWindowPos(NULL,0,0,ClientRect1.Width(),ImageHandle->GetHeight(),SWP_NOMOVE); } //定义变量 CRect ClientRect; GetClientRect(&ClientRect); bool bDisable=((lpDrawItemStruct->itemState&ODS_DISABLED)!=0); bool bButtonDown=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0); bool bFocus = ((lpDrawItemStruct->itemState & ODS_FOCUS)!=0); //设置 DC HDC hDC=lpDrawItemStruct->hDC; //获取文字 CString strText; GetWindowText(strText); if (ImageHandle.IsResourceValid()) { //计算位图位置 int iPartWidth=ImageHandle->GetWidth()/5; int iPartHeight=ImageHandle->GetHeight(); int iDrawPos=0; if (bDisable) iDrawPos = iPartWidth * 4; else if (bButtonDown) iDrawPos = iPartWidth; else if (m_bHovering) iDrawPos = iPartWidth * 3; else if( bFocus ) iDrawPos = iPartWidth * 2; //绘画背景图 if (m_bExpand==false) ImageHandle->BitBlt(hDC,0,0,ClientRect.Width(),ClientRect.Height(),iDrawPos,0,SRCCOPY); else ImageHandle->DrawSkin(CDC::FromHandle(hDC), &ClientRect, iDrawPos, 0, iPartWidth, iPartHeight, DS_STRETCH_ALL, 3, 3, 3, 3); } else { //绘画默认界面 CDC * pDC=CDC::FromHandle(hDC); pDC->FillSolidRect(&ClientRect,GetSysColor(COLOR_BTNFACE)); if (bButtonDown) pDC->Draw3dRect(&ClientRect,GetSysColor(COLOR_WINDOWFRAME),GetSysColor(COLOR_3DHILIGHT)); else pDC->Draw3dRect(&ClientRect,GetSysColor(COLOR_3DHILIGHT),GetSysColor(COLOR_WINDOWFRAME)); } //绘画图标 if (bButtonDown) { ClientRect.top+=2; // ClientRect1.top+=2; } if (m_hIcon) { DrawIconEx(hDC,ClientRect.left+6,ClientRect.top+(ClientRect.Height()-16)/2+1,m_hIcon,16,16,0,NULL,DI_NORMAL); ClientRect.left+=22; } //绘画字体 ClientRect.top+=1; // ClientRect1.top+=2; //ClientRect1.left+=2; ::SetBkMode(hDC,TRANSPARENT); // CFont InfoFont; // InfoFont.CreateFont(-24,0,0,0,700,0,0,0,134,3,2,1,1,TEXT("楷体_GB2312")); CFont Font; Font.CreateFontIndirect(&m_BtnFont); ////////////////////////////////////////////////////////////////////////// CDC* dc = CDC::FromHandle(hDC); CFont* pOldFont = dc->SelectObject (&Font); if(!m_bShowTextFrame) { if (bDisable) ::SetTextColor(hDC,m_crTextColor/*RGB(0,0,0)*/); else ::SetTextColor(hDC,m_crTextColor/*RGB(0,0,0)*/); DrawText(hDC,strText,strText.GetLength(),ClientRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); } //艺术字体 else { if(bDisable) ::SetTextColor(hDC,m_crTextColor/*RGB(0,0,0)*/); else ::SetTextColor(hDC,m_crTextColor/*RGB(0,0,0)*/); //DrawText(hDC,strText,strText.GetLength(),ClientRect1,DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); DrawTextString(CDC::FromHandle(hDC), strText, m_crTextColor, m_crTextFrameColor, ClientRect); } // Select old font in dc->SelectObject(pOldFont); return; }