void nGraphics::DrawCornerRect(const nRect& rect,float size,float width,const nColor& color,unsigned char flags) { // Don't draw if fully transparent if(color.a <= 0.0f) return; // Horizontal lines if(flags & RectFlagTop) { this->DrawFillRect(nRect(rect.left-width,rect.top-width,rect.left+size+width,rect.top),color); this->DrawFillRect(nRect(rect.right-width-size,rect.top-width,rect.right+width,rect.top),color); } if(flags & RectFlagBottom) { this->DrawFillRect(nRect(rect.left-width,rect.bottom,rect.left+size+width,rect.bottom+width),color); this->DrawFillRect(nRect(rect.right-width-size,rect.bottom,rect.right+width,rect.bottom+width),color); } // Vertical lines if(flags & RectFlagLeft) { this->DrawFillRect(nRect(rect.left-width,rect.top,rect.left,rect.top+size),color); this->DrawFillRect(nRect(rect.left-width,rect.bottom-size,rect.left,rect.bottom),color); } if(flags & RectFlagRight) { this->DrawFillRect(nRect(rect.right,rect.top,rect.right+width,rect.top+size),color); this->DrawFillRect(nRect(rect.right,rect.bottom-size,rect.right+width,rect.bottom),color); } }
void insertRect(TY** ppY,const TRect& rect){ TY* pY=*ppY; if (rect.y1 <= pY->y0){ //之前 insertAtFront(ppY,rect); }else if (rect.y0 >= pY->y1){ //之后 insertRectNext(pY,rect); }else if (getIsCover(pY,rect)){ //包含 return; }else{ //相交 TRect nRect(rect); if (nRect.y1 > pY->y1){ //长出一截的部分交给下一个Y TRect backRect(nRect.x0,pY->y1,nRect.x1,nRect.y1); nRect.y1=pY->y1; insertRectNext(pY,backRect); }else if (nRect.y1< pY->y1){ //短一截,分裂Y clipY(pY,nRect.y1); } //nRect.y1==pY->y1 if (nRect.y0 < pY->y0){ TRect frontRect(nRect.x0,nRect.y0,nRect.x1,pY->y0); nRect.y0=pY->y0; YAddAX(pY,nRect.x0,nRect.x1); insertAtFront(ppY,frontRect); }else if (nRect.y0< pY->y0){ clipY(pY,nRect.y0); YAddAX(pY->nextY,nRect.x0,nRect.x1); }else{ //nRect.y0== pY->y0 YAddAX(pY,nRect.x0,nRect.x1); } } }
void nGraphics::DrawStatusText() { // Out text buffers char buffer[256]; // Keep track of the frame count static double lasttime = 0.0; static bool blink = false; // Update the fps stats every second if(nGetInstance()->GetAbsoluteTime() - lasttime > 1.0f) { m_Fps = SETTINGS_DESIREDFRAMERATE/nGetInstance()->GetElapsedTime(); lasttime = nGetInstance()->GetAbsoluteTime(); blink = !blink; } // Draw the fps stats if(m_DrawFps) { _snprintf(buffer,sizeof(buffer),"Fps %06.2f",m_Fps); DrawShadowText(GetBoldFont(),nRect(5,5,0,0),buffer,DT_NOCLIP|DT_SINGLELINE,COLOR_TEXT); } }
void nGraphics::DrawCenterRect(const nRect& rect,float size,float width,const nColor& color,unsigned char flags) { // Don't draw if fully transparent if(color.a <= 0.0f) return; // Horizontal lines if(flags & RectFlagTop) this->DrawFillRect(nRect(rect.left-width+(rect.GetWidth()-size)/2,rect.top-width,rect.right+width-(rect.GetWidth()-size)/2,rect.top),color); if(flags & RectFlagBottom) this->DrawFillRect(nRect(rect.left-width+(rect.GetWidth()-size)/2,rect.bottom,rect.right+width-(rect.GetWidth()-size)/2,rect.bottom+width),color); // Vertical lines if(flags & RectFlagLeft) this->DrawFillRect(nRect(rect.left-width,rect.top+(rect.GetHeight()-size)/2,rect.left,rect.bottom-(rect.GetHeight()-size)/2),color); if(flags & RectFlagRight) this->DrawFillRect(nRect(rect.right,rect.top+(rect.GetHeight()-size)/2,rect.right+width,rect.bottom-(rect.GetHeight()-size)/2),color); }
void nGraphics::DrawTexture(IDirect3DTexture9* texture,const nPoint& point,const nColor& color) { // Don't draw if fully transparent if(color.a <= 0.0f) return; D3DSURFACE_DESC desc; texture->GetLevelDesc(0,&desc); DrawTexture(texture,nRect(point.x,point.y,point.x+desc.Width,point.y+desc.Height),color); }
void nGraphics::DrawFillRect(const nRect& rect,const nColor& color) { // Don't draw if fully transparent if(color.a <= 0.0f) return; // Since we are not using per-vertex color modulation (all vertices have the same // color) we can safely clip the rect to the screen rect nRect localRect = rect; localRect.Intersect(nRect(m_PresentParameters.BackBufferWidth,m_PresentParameters.BackBufferHeight)); if(localRect.IsEmpty()) return; // Have to flush any currently buffered sprite data or we won't have proper // Z positioning this->SpriteFlush(); n2DVertex vertices[4] = { (float) rect.left -0.5f, (float) rect.top -0.5f, 0.5f, 1.0f, color, (float) rect.right -0.5f, (float) rect.top -0.5f, 0.5f, 1.0f, color, (float) rect.right -0.5f, (float) rect.bottom -0.5f, 0.5f, 1.0f, color, (float) rect.left -0.5f, (float) rect.bottom -0.5f, 0.5f, 1.0f, color, }; m_pSprite->Flush(); IDirect3DVertexDeclaration9 *pDecl = NULL; m_pDevice->GetVertexDeclaration(&pDecl); // Preserve the sprite's current vertex decl m_pDevice->SetFVF(n2DVertex::FVF); m_pDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2); m_pDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG2); m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,vertices,sizeof(n2DVertex)); m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); // Restore the vertex decl m_pDevice->SetVertexDeclaration(pDecl); nSafeRelease(pDecl); }
void nGraphics::DrawPrintShadowLine(ID3DXFont* font,const nRect& rect,const char* text,float delta,unsigned long flags,const nColor& color) { nAssert(font); // Don't draw if fully transparent if(color.a <= 0.0f) return; nString textString(text); nColor color2(color); if(delta < 0.0f) color2.a = 0.0f; else if(delta < 1.0f) color2.a *= cubicf(0.0f,1.0f,delta); else if(delta > textString.size()) color2.a = 0.0f; else if(delta > textString.size() - 1.0f) color2.a *= cubicf(0.0f,1.0f,textString.size() - min(delta,textString.size())); unsigned long numChars = min(max(0.0f,delta),textString.size()); numChars = textString.size() * cubicf(0.0f,1.0f,(float)numChars/(float)textString.size()); // Comment-out for no cubic interpolation textString.erase(textString.end() - textString.size() + numChars,textString.end()); nSize size; GetTextSize(font,textString.c_str(),&size,NULL); nSize space; GetTextSize(font," ",&space,NULL); space.cx = 8; // Draw the text DrawShadowText(font,rect,textString.c_str(),flags,color); // Draw block DrawShadowFillRect(nRect(rect.left + size.cx,rect.top,rect.left + size.cx + space.cx,rect.top + space.cy),color2); }
void nGame::Render() { // Draw silos for(unsigned long i = 0; i < m_Silos.size(); i++) RenderSilo(m_Silos[i]); // Draw missle data for(unsigned long i = 0; i < m_Missles.size(); i++) RenderMissle(m_Missles[i]); // Draw explosion data for(unsigned long i = 0; i < m_Explosions.size(); i++) RenderExplosion(m_Explosions[i]); // Draw particle data for(unsigned long i = 0; i < m_Particles.size(); i++) RenderParticle(m_Particles[i]); // Draw the cursor if(nGetInstance()->GetInput()->GetMouse()->GetButton(nMouse::ButtonLeft) || nGetInstance()->GetInput()->GetMouse()->GetButton(nMouse::ButtonRight)) nGetInstance()->GetGraphics()->DrawCursor(nGetInstance()->GetInput()->GetMouse()->GetPosition(),2,4,nGetInstance()->GetAbsoluteTime() * 10.0f,nColor(1.0f,1.0f,1.0f)); else nGetInstance()->GetGraphics()->DrawCursor(nGetInstance()->GetInput()->GetMouse()->GetPosition(),2,6,0.0f,nColor(1.0f,1.0f,1.0f)); // Draw the players score char buffer[512],buffer2[512]; _snprintf(buffer,sizeof(buffer),"Score %d\nHealth %d\nLevel %d",m_Score,m_Health,(unsigned long)(30 - m_MissleTime)); nGetInstance()->GetGraphics()->DrawText(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(5,5,nGetInstance()->GetGraphics()->GetDisplaySize().cx - 5,0),buffer,DT_NOCLIP|DT_RIGHT,COLOR_TEXT); if(m_Pause) { unsigned long y = nGetInstance()->GetGraphics()->GetDisplaySize().cy / 3; nRect rect,rect2; _snprintf(buffer,sizeof(buffer),"Paused"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() / 2,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(abs(sinf(nGetInstance()->GetAbsoluteTime())),COLOR_TEXT)); y += rect.GetHeight(); y += rect.GetHeight(); static char time[100]; GetTimeFormat(LOCALE_USER_DEFAULT,NULL,NULL,NULL,time,100); static char date[100]; GetDateFormat(LOCALE_USER_DEFAULT,DATE_LONGDATE,NULL,NULL,date,100); _snprintf(buffer,sizeof(buffer),"Current time is"); _snprintf(buffer2,sizeof(buffer2)," %s %s",time,date); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer2,&rect2,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() / 2 - rect2.GetWidth() / 2,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.25f,COLOR_TEXT)); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + rect.GetWidth() / 2 - rect2.GetWidth() / 2,y,0,0),buffer2,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.5f,COLOR_TEXT)); y += rect.GetHeight(); y += rect.GetHeight(); // Draw the hiscores if any if(m_HiScores.size()) { _snprintf(buffer,sizeof(buffer),"Time"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,COLOR_TEXT); _snprintf(buffer,sizeof(buffer),"Score"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,COLOR_TEXT); y += rect.GetHeight(); y += rect.GetHeight(); for(unsigned long i = 0; i < m_HiScores.size(); i++) { _snprintf(buffer,sizeof(buffer),"%s",m_HiScores[i].time.c_str()); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.25f,COLOR_TEXT)); _snprintf(buffer,sizeof(buffer),"%d",m_HiScores[i].score); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.5f,COLOR_TEXT)); y += rect.GetHeight(); } y += rect.GetHeight(); } _snprintf(buffer,sizeof(buffer),"Command"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,COLOR_TEXT); _snprintf(buffer,sizeof(buffer),"Button"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,COLOR_TEXT); y += rect.GetHeight(); y += rect.GetHeight(); nString keyboard = nGetInstance()->GetInput()->GetKeyboard()->GetDeviceName(); nString mouse = nGetInstance()->GetInput()->GetMouse()->GetDeviceName(); _snprintf(buffer,sizeof(buffer),"Pause/Unpause"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.25f,COLOR_TEXT)); _snprintf(buffer,sizeof(buffer),"%s %s or %s %s",keyboard.c_str(),nGetInstance()->GetInput()->GetKeyboard()->GetKeyName(DIK_PAUSE).c_str(),keyboard.c_str(),nGetInstance()->GetInput()->GetKeyboard()->GetKeyName(DIK_P).c_str()); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.5f,COLOR_TEXT)); y += rect.GetHeight(); _snprintf(buffer,sizeof(buffer),"Fire missle"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.25f,COLOR_TEXT)); _snprintf(buffer,sizeof(buffer),"%s %s",mouse.c_str(),nGetInstance()->GetInput()->GetMouse()->GetButtonName(nMouse::ButtonLeft).c_str()); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.5f,COLOR_TEXT)); y += rect.GetHeight(); _snprintf(buffer,sizeof(buffer),"Fire cannon"); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 - rect.GetWidth() - 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.25f,COLOR_TEXT)); _snprintf(buffer,sizeof(buffer),"%s %s",mouse.c_str(),nGetInstance()->GetInput()->GetMouse()->GetButtonName(nMouse::ButtonRight).c_str()); nGetInstance()->GetGraphics()->GetTextRect(nGetInstance()->GetGraphics()->GetBoldFont(),buffer,&rect,NULL); nGetInstance()->GetGraphics()->DrawPrintLine(nGetInstance()->GetGraphics()->GetBoldFont(),nRect(nGetInstance()->GetGraphics()->GetDisplaySize().cx / 2 + 10,y,0,0),buffer,100.0f * (nGetInstance()->GetAbsoluteTime() - m_PauseTime),DT_NOCLIP,nColor(0.5f,COLOR_TEXT)); y += rect.GetHeight(); } }
void CHeaderCtrlCl::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CHeaderCtrl::OnPaint() int nItem; nItem = GetItemCount();//得到有几个单元 for(int i = 0; i<nItem;i ++) { CRect tRect; GetItemRect(i,&tRect);//得到Item的尺寸 int R = m_R,G = m_G,B = m_B; CRect nRect(tRect);//拷贝尺寸到新的容器中 nRect.left++;//留出分割线的地方 //绘制立体背景 for(int j = tRect.top;j<=tRect.bottom;j++) { nRect.bottom = nRect.top+1; CBrush _brush; _brush.CreateSolidBrush(RGB(R,G,B));//创建画刷 dc.FillRect(&nRect,&_brush); //填充背景 _brush.DeleteObject(); //释放画刷 R-=m_Gradient;G-=m_Gradient;B-=m_Gradient; if (R<0)R = 0; if (G<0)G = 0; if (B<0)B= 0; nRect.top = nRect.bottom; } dc.SetBkMode(TRANSPARENT); CFont nFont ,* nOldFont; //dc.SetTextColor(RGB(250,50,50)); dc.SetTextColor(m_color); nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体 nOldFont = dc.SelectObject(&nFont); UINT nFormat = 1; if (m_Format[i]=='0') { nFormat = DT_LEFT; tRect.left+=3; } else if (m_Format[i]=='1') { nFormat = DT_CENTER; } else if (m_Format[i]=='2') { nFormat = DT_RIGHT; tRect.right-=3; } TEXTMETRIC metric; dc.GetTextMetrics(&metric); int ofst = 0; ofst = tRect.Height() - metric.tmHeight; tRect.OffsetRect(0,ofst/2); dc.DrawText(m_HChar[i],&tRect,nFormat); dc.SelectObject(nOldFont); nFont.DeleteObject(); //释放字体 } //画头部剩余部分 CRect rtRect; CRect clientRect; GetItemRect(nItem - 1,rtRect); GetClientRect(clientRect); rtRect.left = rtRect.right+1; rtRect.right = clientRect.right; int R = m_R,G = m_G,B = m_B; CRect nRect(rtRect); //绘制立体背景 for(int j = rtRect.top;j<=rtRect.bottom;j++) { nRect.bottom = nRect.top+1; CBrush _brush; _brush.CreateSolidBrush(RGB(R,G,B));//创建画刷 dc.FillRect(&nRect,&_brush); //填充背景 _brush.DeleteObject(); //释放画刷 R-=m_Gradient;G-=m_Gradient;B-=m_Gradient; if (R<0)R = 0; if (G<0)G = 0; if (B<0)B= 0; nRect.top = nRect.bottom; } }
void CTBHeaderCtrl::DrawHeader(CDC* pDC) { bool bGet = false; if (NULL == pDC) { pDC = GetDC(); bGet = true; } CDC dc; dc.CreateCompatibleDC(pDC); CBitmap memBmp; CRect memRect; GetClientRect(&memRect); memBmp.CreateCompatibleBitmap(pDC, memRect.Width(), memRect.Height()); CBitmap* pOldBmp = dc.SelectObject(&memBmp); dc.FillSolidRect(0, 0, memRect.Width(), memRect.Height(), RGB(m_R, m_G, m_B)); int nItem; nItem = GetItemCount(); for(int i = 0; i<nItem;i ++) { CRect tRect; GetItemRect(i,&tRect); int R = m_R,G = m_G,B = m_B; CRect nRect(tRect); nRect.left++; for(int j = tRect.top;j<=tRect.bottom;j++) { nRect.bottom = nRect.top+1; CBrush _brush; _brush.CreateSolidBrush(RGB(R,G,B)); dc.FillRect(&nRect,&_brush); _brush.DeleteObject(); R-=m_Gradient;G-=m_Gradient;B-=m_Gradient; if (R<0)R = 0; if (G<0)G = 0; if (B<0)B= 0; nRect.top = nRect.bottom; } dc.SetBkMode(TRANSPARENT); CFont nFont ,* nOldFont; //dc.SetTextColor(RGB(250,50,50)); dc.SetTextColor(m_color); HDITEM hdItem; ZeroMemory(&hdItem, sizeof(hdItem)); hdItem.mask = HDI_TEXT; hdItem.pszText = new TCHAR[256]; ZeroMemory(hdItem.pszText, 256); hdItem.cchTextMax = 256; if (GetItem(i, &hdItem)) { nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("SimSun")); nOldFont = dc.SelectObject(&nFont); TEXTMETRIC metric; dc.GetTextMetrics(&metric); int ofst = 0; ofst = tRect.Height() - metric.tmHeight; tRect.OffsetRect(0,ofst/2); dc.DrawText(hdItem.pszText,&tRect,DT_CENTER); dc.SelectObject(nOldFont); nFont.DeleteObject(); } delete []hdItem.pszText; } CRect rtRect; CRect clientRect; GetItemRect(nItem - 1,rtRect); GetClientRect(clientRect); rtRect.left = rtRect.right+1; rtRect.right = clientRect.right; int R = m_R,G = m_G,B = m_B; CRect nRect(rtRect); for(int j = rtRect.top;j<=rtRect.bottom;j++) { nRect.bottom = nRect.top+1; CBrush _brush; _brush.CreateSolidBrush(RGB(R,G,B)); dc.FillRect(&nRect,&_brush); _brush.DeleteObject(); R-=m_Gradient;G-=m_Gradient;B-=m_Gradient; if (R<0)R = 0; if (G<0)G = 0; if (B<0)B= 0; nRect.top = nRect.bottom; } pDC->BitBlt(0, 0, memRect.Width(), memRect.Height(), &dc, 0, 0, SRCCOPY); dc.SelectObject(pOldBmp); memBmp.DeleteObject(); dc.DeleteDC(); if (bGet) { ReleaseDC(pDC); } }