void CJPWordWnd::OnPaint() { #define JP_PAINT_X_ 5 CPaintDC dc(this); CDC dcMemory; CBitmap bitmap; if (!dc.IsPrinting()) { if (dcMemory.CreateCompatibleDC(&dc)) { if (bitmap.CreateCompatibleBitmap(&dc,clientRect.right,clientRect.bottom)) { dcMemory.SelectObject(&bitmap); /*CBrush br; br.CreateSysColorBrush(CSCB); br.CreateSolidBrush(RGB(200,200,200)); dcMemory.FillRect(&clientRect,&br);*/ //设置画笔 CPen pen; pen.CreatePen(PS_SOLID, 0, RGB(255, 0, 0)); CPen *pOldPen = dcMemory.SelectObject(&pen); //设置画刷 CBrush brush; brush.CreateSolidBrush( RGB(200,255,000) ); CBrush* pOldBrush = dcMemory.SelectObject(&brush); //填充圆角矩形 dcMemory.RoundRect(clientRect.left+4, clientRect.top+4, clientRect.right-4, clientRect.bottom-4, 20, 20); // 将字体选进DC CFont* pOldFont = dcMemory.SelectObject(&fontZhuYin); //设置字体背景色 COLORREF oldBkColor = dcMemory.SetBkColor(RGB(200,255,0)); COLORREF oldTextColor = dcMemory.SetTextColor(RGB(0,0,0)); //设置裁剪区域 CRgn rgn ; rgn.CreateRoundRectRgn(clientRect.left+6, clientRect.top+6, clientRect.right-8, clientRect.bottom-8, 20, 20); dcMemory.SelectClipRgn(&rgn); if(bInit) { //cout<<"paint^"<<endl; allBaseX = JP_PAINT_X_; allBaseY = 0; //一行总体高度,换行时使用 int rowHeight = -1; //单个注音字符的绘制宽度,绘制声调线时用 int charZhuYinWidth = -1; // 注音字符高度 int charZhuYinHeight = -1; // 单词字符高度 int charWordHeight = -1; //声调线高度 int toneHeight = 0;//10 ; //绘制声调线的纵向基准 int toneBaseY = allBaseY + 5 ; //绘制注音的纵向基准 int zhuYinBaseY = toneBaseY + toneHeight + 2 ; //绘制单词的纵向基准 int wordBaseY = -1 ; //循环绘制各个单词和注音 for(int i=0 ; i< jpword.wordCount ; i++ ) { //取得当前单词 CString currentWord = CString( jpword.getWordAt(i).c_str()); //取得当前注音 CString currentZhuYin = CString( jpword.getZhuYinAt(i).c_str()); //取得单词长度(字符数) int wordLen = jpword.getWordLengthAt(i); //取得注音长度(字符数) int zhuYinLen = jpword.getZhuYinLengthAt(i); //将注音字体选进DC dcMemory.SelectObject(&fontZhuYin); //计算注音占据的矩形区域 CRect rcZhuYin = CRect(0,0,0,0); dcMemory.DrawText( currentZhuYin, &rcZhuYin, DT_CALCRECT); // 计算字符的宽度和高度 if(zhuYinLen > 0) { //获取注音字符的绘制宽度 charZhuYinWidth = rcZhuYin.Width() / zhuYinLen; //获取注音字符的绘制高度 charZhuYinHeight = rcZhuYin.Height(); } //当前注音为空 else { //用字符わ来计算 dcMemory.DrawText( _T("わ"), &rcZhuYin, DT_CALCRECT); //获取注音字符的绘制宽度 charZhuYinWidth = rcZhuYin.Width(); //获取注音字符的绘制高度 charZhuYinHeight = rcZhuYin.Height(); } //获取单词纵向绘制基准位置(只有第一次需要计算) } if(wordBaseY==-1) { wordBaseY = zhuYinBaseY + charZhuYinHeight +3; } //选择单词绘制字体 dcMemory.SelectObject(&fontWord); //计算单词占据的矩形区域 CRect rcWord = CRect(0,0,0,0); dcMemory.DrawText( currentWord , &rcWord, DT_CALCRECT); //获取单词字体绘制高度 if(charWordHeight==-1) { //获取注音字符的绘制高度 charWordHeight = rcWord.Height(); } //计算一行单词的高度(包括声调,注音和单词)(只有第一次需要计算) if(rowHeight==-1) { rowHeight = toneHeight + charZhuYinHeight + charWordHeight +10 ; } //取出两个矩形中的较大宽度 int finalWidth = rcWord.Width(); if(rcWord.Width()<rcZhuYin.Width()) { finalWidth = rcZhuYin.Width(); } //如果横向基准+绘制区域宽度 大于窗口宽度则折行显示 if( finalWidth + allBaseX > clientRect.Width() ) { //横向位置从头开始 allBaseX = JP_PAINT_X_; //纵向位置 = 字体高度+ allBaseY += rowHeight ; } //当前显示模式为单词模式 if( showMode==sm_show_word ) { //选择单词字体 dcMemory.SelectObject( fontWord ); //移动新矩形至单词基准位置 CPoint pos(allBaseX, wordBaseY + allBaseY); CSize size(finalWidth , rcWord.Height()); CRect rc( pos,size ); //绘制单词 dcMemory.DrawText( currentWord, rc, DT_CENTER ); } //注音模式 else if( showMode==sm_show_zhuyin ) { //选择注音字体 dcMemory.SelectObject( fontZhuYin ); CPoint pos(allBaseX, zhuYinBaseY + allBaseY); CSize size(finalWidth , rcZhuYin.Height()); CRect rc( pos,size ); //移动新矩形至注音基准位置 //如果当前词没有注音则绘制单词,否则绘制注音 if( currentZhuYin.IsEmpty() ) { //绘制单词 dcMemory.DrawText( currentWord, rc, DT_CENTER ); } else { //绘制注音 dcMemory.DrawText( currentZhuYin,rc, DT_CENTER ); } /* //声调信息必须为3的倍数,否则不绘制 if( jpword.tone.size()%3 == 0 ) { //绘制声调线 for( size_t i=0; i<jpword.tone.size(); i+=3 ) { //声调类型 int style = jpword.tone[i]; //划横线 dcMemory.MoveTo( jpword.tone[i+1]*charZhuYinWidth ,toneBaseY + allBaseY ); dcMemory.LineTo( jpword.tone[i+2]*charZhuYinWidth ,toneBaseY + allBaseY ); //画下降线 if( style == CJPWordInfoEx::jp_tone_down ) { dcMemory.LineTo( jpword.tone[i+2]*charZhuYinWidth-6 ,toneBaseY + 5 + allBaseY ); } } }*/ } //正常模式 else { //选择单词字体 dcMemory.SelectObject( fontWord ); CPoint pos(allBaseX, wordBaseY + allBaseY); CSize size(finalWidth , rcWord.Height()); CRect rc( pos,size ); //移动新矩形至单词基准位置 //绘制单词 dcMemory.DrawText( currentWord, rc, DT_CENTER ); //选择注音字体 dcMemory.SelectObject( fontZhuYin ); //移动新矩形至注音基准位置 pos = CPoint(allBaseX, zhuYinBaseY + allBaseY); size = CSize(finalWidth , rcZhuYin.Height()); rc = CRect( pos,size ); //绘制注音 dcMemory.DrawText( currentZhuYin,rc, DT_CENTER ); /* //声调信息必须为3的倍数,否则不绘制 if( jpword.tone.size()%3 == 0 ) { //绘制声调线 for( size_t i=0; i<jpword.tone.size(); i+=3 ) { //声调类型 int style = jpword.tone[i]; //划横线 dcMemory.MoveTo( jpword.tone[i+1]*charZhuYinWidth +6 ,toneBaseY + allBaseY ); dcMemory.LineTo( jpword.tone[i+2]*charZhuYinWidth -6 ,toneBaseY + allBaseY ); //画下降线 if( style == CJPWordInfoEx::jp_tone_down ) { dcMemory.LineTo( jpword.tone[i+2]*charZhuYinWidth-6 ,toneBaseY + 5 + allBaseY ); } } } */ } //计算下一个横向基准位置 allBaseX += finalWidth+2; } } //恢复画笔 dcMemory.SelectObject( pOldPen); pen.DeleteObject(); //恢复画刷 dcMemory.SelectObject( pOldBrush ); brush.DeleteObject(); //释放裁剪区域 dcMemory.SelectClipRgn(NULL); // 恢复旧字体 dcMemory.SelectObject( pOldFont ); dcMemory.SetTextColor( oldTextColor ); dcMemory.SetBkColor( oldBkColor ); dc.BitBlt(clientRect.left,clientRect.top,clientRect.right,clientRect.bottom,&dcMemory,0,0,SRCCOPY); bitmap.DeleteObject(); } } } }
void CProgressCtrlX::DrawGradient(const CDrawInfo& info, const CRect &rcGrad, const CRect &rcClip, COLORREF clrStart, COLORREF clrEnd) { // Split colors to RGB chanels, find chanel with maximum difference // between the start and end colors. This distance will determine // number of steps of gradient int r = (GetRValue(clrEnd) - GetRValue(clrStart)); int g = (GetGValue(clrEnd) - GetGValue(clrStart)); int b = (GetBValue(clrEnd) - GetBValue(clrStart)); int nSteps = max(abs(r), max(abs(g), abs(b))); // if number of pixels in gradient less than number of steps - // use it as numberof steps int nPixels = rcGrad.Width(); nSteps = min(nPixels, nSteps); if(nSteps == 0) nSteps = 1; float rStep = (float)r/nSteps; float gStep = (float)g/nSteps; float bStep = (float)b/nSteps; r = GetRValue(clrStart); g = GetGValue(clrStart); b = GetBValue(clrStart); BOOL fLowColor = info.pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE; if(!fLowColor && nSteps > 1) if(info.pDC->GetDeviceCaps(BITSPIXEL)*info.pDC->GetDeviceCaps(PLANES) < 8) nSteps = 1; // for 16 colors no gradient float nWidthPerStep = (float)rcGrad.Width() / nSteps; CRect rcFill(rcGrad); CBrush br; // Start filling for (int i = 0; i < nSteps; i++) { rcFill.left = rcGrad.left + (int)(nWidthPerStep * i); rcFill.right = rcGrad.left + (int)(nWidthPerStep * (i+1)); if(i == nSteps-1) //last step (because of problems with float) rcFill.right = rcGrad.right; if(rcFill.right < rcClip.left) continue; // skip - band before cliping rect // clip it if(rcFill.left < rcClip.left) rcFill.left = rcClip.left; if(rcFill.right > rcClip.right) rcFill.right = rcClip.right; COLORREF clrFill = RGB(r + (int)(i * rStep), g + (int)(i * gStep), b + (int)(i * bStep)); if(fLowColor) { br.CreateSolidBrush(clrFill); // CDC::FillSolidRect is faster, but it does not handle 8-bit color depth info.pDC->FillRect(&ConvertToReal(info, rcFill), &br); br.DeleteObject(); } else info.pDC->FillSolidRect(&ConvertToReal(info, rcFill), clrFill); if(rcFill.right >= rcClip.right) break; // stop filling if we reach current position } }
void CHyperLink::OnPaint() { if (m_bMovingWindow) { return; } CBufferDC dc(this); // device context for painting dc.SaveDC(); dc.SetMapMode(MM_TEXT); dc.SetBkMode(TRANSPARENT); dc.SelectObject(m_hFont); dc.SetBkColor(m_crBackGround); CRect rc; GetClientRect(&rc); CBrush cb; cb.CreateSolidBrush(m_crBackGround); dc.SelectObject(&cb); CBrush cb2; cb2.CreateSysColorBrush(COLOR_BTNFACE); dc.FillRect(&rc,&cb2); cb2.DeleteObject(); CPen p; BOOL bWndTxt = FALSE; if (m_lpLinkText == NULL) { bWndTxt = TRUE; int nlen = GetWindowTextLength(); m_lpLinkText = new TCHAR[nlen+1]; m_lpLinkText[nlen] = (TCHAR)0; GetWindowText(m_lpLinkText,nlen+1); } GetWindowRect(rc); GetParent()->ScreenToClient(&rc); SIZE iconSz = GetFirstIcon(); SIZE iconSpace = { 0 }; iconSpace.cx = iconSz.cx; iconSpace.cy = iconSz.cy; if (m_bMouseIn) { int i = 0; i++; } if (m_bLockInPosition) { iconSpace = GetBiggestIcon(); } CSize sz = dc.GetTextExtent(m_lpLinkText,(int)_tcslen(m_lpLinkText)); int x = rc.left; int y = sz.cy + 2; int* nlOff = NULL; int* nlXl = NULL; int nlXlM = sz.cx; int nlc = 0; size_t len = _tcslen(m_lpLinkText); if (m_bMultiline) { while (len > 0 && m_lpLinkText[len-1] == _T('\n')) { len--; } if (len > 0) { while (len--) { if (m_lpLinkText[len] == _T('\n')) { nlc++; } } } if (nlc > 0) { nlc++; len = _tcslen(m_lpLinkText); nlOff = new int[nlc]; nlXl = new int[nlc]; nlXlM = 0; int nlc2 = nlc; while (len > 0 && m_lpLinkText[len-1] == _T('\n')) { len--; } if (len > 0) { size_t len2 = len; nlOff[--nlc2] = (int)len; while (len--) { if (m_lpLinkText[len] == _T('\n')) { nlXl[nlc2] = dc.GetTextExtent(&m_lpLinkText[len+1],(int)(len2 - len - 1)).cx; nlXlM = nlXl[nlc2] > nlXlM ? nlXl[nlc2] : nlXlM; len2 = len; y += sz.cy + 2; nlOff[--nlc2] = (int)len; } } if (len == -1) { nlXl[0] = dc.GetTextExtent(m_lpLinkText,(int)(len2)).cx; nlXlM = nlXl[0] > nlXlM ? nlXl[0] : nlXlM; len2 = len; } } } } if (nlc == 0 && len > 0) { len = _tcslen(m_lpLinkText); while (len > 0 && m_lpLinkText[len-1] == _T('\n')) { len--; } if (len > 0) { if (nlOff != NULL) { delete [] nlOff; } nlc = 1; nlOff = new int[nlc]; nlXl = new int[nlc]; nlOff[0] = (int)len; nlXl[0] = nlXlM; } } y += nlc; if (y < iconSpace.cy + 2) { y = iconSpace.cy + 2; } y += (m_nBorderSize * 2); y = rc.Height() - y; rc.bottom = rc.bottom - (y); x += (1 + nlXlM + (m_nBorderSize * 2) + 2); if ((!m_bDisabled && ((m_uShowIcon & SI_ICONUP_LEFT && !m_bMouseIn) || (m_uShowIcon & SI_ICONHOVER_LEFT && m_bMouseIn && !m_bMouseDown) || (m_uShowIcon & SI_ICONDOWN_LEFT && m_bMouseDown && m_bMouseIn)) ) || (m_uShowIcon & SI_ICONDISABLED_LEFT && m_bDisabled) || m_bLockInPosition) { x = x + iconSpace.cx + 3; } if ((!m_bDisabled && ((m_uShowIcon & SI_ICONUP_RIGHT && !m_bMouseIn) || (m_uShowIcon & SI_ICONHOVER_RIGHT && m_bMouseIn && !m_bMouseDown) || (m_uShowIcon & SI_ICONDOWN_RIGHT && m_bMouseDown && m_bMouseIn)) ) || (m_uShowIcon & SI_ICONDISABLED_RIGHT && m_bDisabled) || m_bLockInPosition) { x = x + 2 + iconSpace.cx + 1; } rc.right = x; m_bMovingWindow = TRUE; MoveWindow(rc.left,rc.top,rc.Width(),rc.Height(),FALSE); m_bMovingWindow = FALSE; GetClientRect(rc); dc.SetBoundsRect(&rc, DCB_DISABLE); dc.FillRect(&rc,&cb); //draw border if (m_nBorderSize > 0) { CRect brect = rc; CPen pen, *oldPen; if (!m_bDisabled) { pen.CreatePen(m_nBorderStyle, m_nBorderSize, m_crBorder); } else { pen.CreatePen(m_nBorderStyle, m_nBorderSize, ::GetSysColor(COLOR_BTNSHADOW)); } oldPen = dc.SelectObject(&pen); int bspacer = (m_nBorderSize - (m_nBorderSize % 2)) / 2; brect.DeflateRect(bspacer, bspacer); if (m_nBorderSize % 2 == 0) { brect.right++; brect.bottom++; } dc.Rectangle(&brect); dc.SelectObject(oldPen); } int yTxt = ((sz.cy * nlc) + (nlc * 3) - (nlc - 1)); y = rc.Height() - iconSz.cy; y = (y - (y % 2)) / 2; x = 1 + m_nBorderSize; if (m_bLockInPosition) { x += ((iconSpace.cx - iconSz.cx) / 2); } if (m_bDisabled) { if (m_hIconDisabled != NULL) { if ((m_uShowIcon & SI_ICONDISABLED_ON && m_uShowIcon & SI_ICONDISABLED_LEFT)) { DrawIconEx(dc.m_hDC,x,y,m_hIconDisabled,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); x = iconSpace.cx + 4 + m_nBorderSize; if (m_bLockInPosition) { x += ((iconSpace.cx - iconSz.cx) / 2); } } else if (m_bLockInPosition) { x = iconSpace.cx + 4 + m_nBorderSize; x += ((iconSpace.cx - iconSz.cx) / 2); } if ((m_uShowIcon & SI_ICONDISABLED_ON && m_uShowIcon & SI_ICONDISABLED_RIGHT)) { DrawIconEx(dc.m_hDC,x + nlXlM + 3,y,m_hIconDisabled,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); } } dc.SetTextColor(::GetSysColor(COLOR_BTNSHADOW)); } else if (!m_bDisabled && m_bMouseIn && !m_bMouseDown) { if ((m_uShowIcon & SI_ICONHOVER_ON && m_uShowIcon & SI_ICONHOVER_LEFT) && m_hIconHover != NULL) { DrawIconEx(dc.m_hDC,x,y,m_hIconHover,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); x = iconSpace.cx + 4 + m_nBorderSize; if (m_bLockInPosition) { x += ((iconSpace.cx - iconSz.cx) / 2); } } else if (m_bLockInPosition) { x = iconSpace.cx + 4 + m_nBorderSize; x += ((iconSpace.cx - iconSz.cx) / 2); } if ((m_uShowIcon & SI_ICONHOVER_ON && m_uShowIcon & SI_ICONHOVER_RIGHT) && m_hIconHover != NULL) { DrawIconEx(dc.m_hDC,x + nlXlM + 3,y,m_hIconHover,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); } p.CreatePen(PS_SOLID,1,m_crLinkHover); dc.SetTextColor(m_crLinkHover); } else if (!m_bDisabled && m_bMouseIn && m_bMouseDown) { p.CreatePen(PS_SOLID,1,m_crLinkDown); if ((m_uShowIcon & SI_ICONDOWN_ON && m_uShowIcon & SI_ICONDOWN_LEFT) && m_hIconDown != NULL) { DrawIconEx(dc.m_hDC,x,y,m_hIconDown,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); x = iconSpace.cx + 4 + m_nBorderSize; if (m_bLockInPosition) { x += ((iconSpace.cx - iconSz.cx) / 2); } } else if (m_bLockInPosition) { x = iconSpace.cx + 4 + m_nBorderSize; x += ((iconSpace.cx - iconSz.cx) / 2); } if ((m_uShowIcon & SI_ICONDOWN_ON && m_uShowIcon & SI_ICONDOWN_RIGHT) && m_hIconDown != NULL) { DrawIconEx(dc.m_hDC,x + nlXlM + 3,y,m_hIconDown,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); } dc.SetTextColor(m_crLinkDown); } else if (!m_bDisabled && !m_bMouseIn) { if (m_bUnderlineAlways) p.CreatePen(PS_SOLID,1,m_crLinkUp); else p.CreatePen(PS_SOLID,1,m_crBackGround); if ((m_uShowIcon & SI_ICONUP_ON && m_uShowIcon & SI_ICONUP_LEFT) && m_hIconUp != NULL) { DrawIconEx(dc.m_hDC,x,y,m_hIconUp,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); x = iconSpace.cx + 4 + m_nBorderSize; if (m_bLockInPosition) { x += ((iconSpace.cx - iconSz.cx) / 2); } } else if (m_bLockInPosition) { x = iconSpace.cx + 4 + m_nBorderSize; x += ((iconSpace.cx - iconSz.cx) / 2); } if ((m_uShowIcon & SI_ICONUP_ON && m_uShowIcon & SI_ICONUP_RIGHT) && m_hIconUp != NULL) { DrawIconEx(dc.m_hDC,x + nlXlM + 3,y,m_hIconUp,iconSz.cx,iconSz.cy,0,NULL,DI_IMAGE | DI_MASK); } dc.SetTextColor(m_crLinkUp); } if (m_bLockInPosition) { x = iconSpace.cx + 4 + m_nBorderSize; } y = rc.Height() - ((sz.cy * nlc) + (nlc * 3) - (nlc - 1)); if (y < 0) { y = 0; } y = (y - (y % 2)) / 2; if (nlc > 0) { dc.TextOut(x,y,m_lpLinkText,(int)nlOff[0]); dc.MoveTo(x,y+sz.cy); dc.SelectObject(&p); dc.LineTo(x+nlXl[0],y+sz.cy); for (int i = 1; i < nlc; i++) { y += sz.cy + 2; dc.TextOut(x,y,&m_lpLinkText[nlOff[i-1]+1],(int)(nlOff[i] - nlOff[i-1] - 1)); dc.MoveTo(x,y+sz.cy); dc.SelectObject(&p); dc.LineTo(x+nlXl[i],y+sz.cy); } } if (bWndTxt) { delete [] m_lpLinkText; m_lpLinkText = NULL; } if (nlOff != NULL) { delete [] nlOff; } if (nlXl != NULL) { delete [] nlXl; } dc.RestoreDC(-1); }
void CGuiGroupBox::OnPaint() { CPaintDC dc(this); // device context for painting CRect rc; GetClientRect(rc); CBrush cb; CFont m_cfont; CString m_caption; CPen cpshadow(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow()); cb.CreateSolidBrush(m_clrface); GetWindowText(m_caption); if ((m_style == ALING_LEFT) || (m_style == ALING_RIGHT)) m_cfont.CreateFont( -11,0,0,0,400,0,0,0,0,1,2,1,34,"Verdana"); else m_cfont.CreateFont(-11,0,900,900,400,0,0,0,0,1,2,1,34,"Verdana"); //******************************************************** CFont* m_fontOld=dc.SelectObject(&m_cfont); CSize SizeCad=dc.GetTextExtent(m_caption); SizeCad.cx+=2; CRect rCText=rc; rc.DeflateRect(1,1); rc.top+=6; //orientar la cadena************************************* if (m_style == ALING_LEFT) { rCText.left+=6; rCText.bottom=rCText.top+SizeCad.cy+1; rCText.right=rCText.left+SizeCad.cx+1; } else if (m_style == ALING_RIGHT) { rCText.right-=6; rCText.left=rCText.right-SizeCad.cx+1; rCText.bottom=rCText.top+SizeCad.cy+1; } else if (m_style == ALING_DOWN) { rCText.bottom-=6; rCText.left=-7; rCText.top=rCText.bottom-SizeCad.cx; rCText.right=rCText.left+SizeCad.cy+1; } else if (m_style == ALING_UP) { rCText.top+=10; rCText.left=-7; rCText.right=rCText.left+SizeCad.cy+1; rCText.bottom=rCText.top+SizeCad.cx+7; } //******************************************************** CPen* pOld=dc.SelectObject(&cpshadow); //linea superior dc.MoveTo(rc.left+2,rc.top); dc.LineTo(rc.right-2,rc.top); //linea vertical izquierda dc.MoveTo(rc.left,rc.top+2); dc.LineTo(rc.left,rc.bottom-2); //linea vertical derecha dc.MoveTo(rc.right,rc.top+2); dc.LineTo(rc.right,rc.bottom-2); //linea horizontal inferior dc.MoveTo(rc.left+2,rc.bottom); dc.LineTo(rc.right-2,rc.bottom); //ahora se dibujan los vertices //l,t dc.MoveTo(rc.left+2,rc.top); dc.LineTo(rc.left,rc.top+2); //r,t dc.MoveTo(rc.right-2,rc.top); dc.LineTo(rc.right,rc.top+2); //l,b dc.MoveTo(rc.left,rc.bottom-2); dc.LineTo(rc.left+2,rc.bottom); //r,b dc.MoveTo(rc.right-2,rc.bottom); dc.LineTo(rc.right,rc.bottom-2); //sentido del mensaje int nMode = dc.SetBkMode(TRANSPARENT); dc.FillRect(rCText,&cb); dc.SetTextColor(GuiDrawLayer::GetRGBCaptionXP()); int cont=SizeCad.cx; if (m_style == ALING_DOWN || m_style == ALING_UP) dc.TextOut(rCText.left,rCText.bottom-2,m_caption); else dc.TextOut(rCText.left,rCText.top,m_caption); dc.SetBkMode(nMode); // Modified By SunZhenyu dc.SelectObject(m_fontOld); dc.SelectObject(pOld); }
void CGradientProgressCtrl::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here if(m_nCurrentPosition<=m_nLower||m_nCurrentPosition>=m_nUpper) { CRect rect; GetClientRect(rect); CBrush brush; brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE)); dc.FillRect(&rect,&brush); VERIFY(brush.DeleteObject()); return; } CRect rectClient; GetClientRect(rectClient); float maxWidth((float)m_nCurrentPosition/(float)m_nUpper*(float)rectClient.right); /* //绘制 DrawGradient(&dc,rectClient,(int)maxWidth); //显示进程条进度文字 if(m_bShowPercent) { CString percent; percent.Format("%d%%",(int)(100*(float)m_nCurrentPosition/m_nUpper)); dc.SetTextColor(m_clrText); dc.SetBkMode(TRANSPARENT); dc.DrawText(percent,&rectClient,DT_VCENTER|DT_CENTER|DT_SINGLELINE); } */ // Do not call CProgressCtrl::OnPaint() for painting messages ///////////////////////////// CPen * pWhitePen=CPen::FromHandle((HPEN)GetStockObject(WHITE_PEN)); // CPen * pBlackPen=CPen::FromHandle((HPEN)GetStockObject(BLACK_PEN)); dc.SelectObject(pWhitePen); //创建笔画 CPen BorderPen1(PS_SOLID,1, RGB( 0xff, 0xcf, 0xa7) ); CPen * pOldPen1= dc.SelectObject(&BorderPen1); CBrush brush,*oldbrush; CBrush brush1; brush1.CreateSolidBrush(RGB( 0xff, 0xcf, 0xa7)); oldbrush=dc.SelectObject(&brush1); dc.Rectangle( 0, 0, rectClient.right, rectClient.bottom); dc.SelectObject(oldbrush); dc.SelectObject(pOldPen1); BorderPen1.DeleteObject(); brush.CreateSolidBrush(RGB(255,255,255)); // 白色 oldbrush=dc.SelectObject(&brush); dc.Ellipse( 0, 0, rectClient.bottom, rectClient.bottom); dc.Ellipse( rectClient.right - rectClient.Height(), 0, rectClient.right, rectClient.bottom); dc.Rectangle( rectClient.Height()/2, 0, rectClient.right - rectClient.Height()/2, rectClient.bottom); dc.SelectObject(oldbrush); // CBrush brush2; //-------------------------------------- if ( maxWidth > rectClient.Height()) { // CPen * pRedPen=CPen::FromHandle((HPEN)GetStockObject(DKGRAY_BRUSH)); //创建笔画 CPen BorderPen(PS_SOLID,1, RGB(128, 0, 0) ); CPen * pOldPen= dc.SelectObject(&BorderPen); // dc.SelectObject(pRedPen); CBrush brush2; brush2.CreateSolidBrush(RGB(128, 0, 0)); oldbrush=dc.SelectObject(&brush2); dc.Ellipse( 0, 0, rectClient.bottom, rectClient.bottom); dc.Rectangle( rectClient.Height()/2, 0, maxWidth, rectClient.bottom); dc.SelectObject(oldbrush); //清理资源 VERIFY(brush2.DeleteObject()); dc.SelectObject(pOldPen); BorderPen.DeleteObject(); } //-------------------------------------- VERIFY(brush1.DeleteObject()); VERIFY(brush.DeleteObject()); }
void CGuiToolButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pdc= CDC::FromHandle(lpDrawItemStruct->hDC); CRect rc=lpDrawItemStruct->rcItem; UINT uState=lpDrawItemStruct->itemState; CBrush cb; if( uState & ODS_SELECTED) //the button is pressed { if(m_StyleDisplay==GUISTYLE_2003 || m_StyleDisplay == GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::m_Theme? RGB(249,200,102):GuiDrawLayer::GetRGBPressBXP()); else cb.CreateSolidBrush(GuiDrawLayer::GetRGBPressBXP()); } else if (m_bMouserOver) { if(m_StyleDisplay==GUISTYLE_2003 || m_StyleDisplay== GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::m_Theme? RGB(252,230,186):GuiDrawLayer::GetRGBFondoXP()); else cb.CreateSolidBrush(GuiDrawLayer::GetRGBFondoXP()); } else { if(m_StyleDisplay==GUISTYLE_2003) { if (m_Transparent && m_StyleDisplay ) cb.CreateStockObject(NULL_BRUSH); else { CGradient M(CSize(rc.Width(),rc.Height()+1)); M.PrepareReverseVertTab(pdc,m_StyleDisplay); M.Draw(pdc,rc.left,rc.top,0,0,rc.Width(),rc.Height(),SRCCOPY); } } else if (m_StyleDisplay== GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace(m_StyleDisplay)); else cb.CreateSolidBrush(m_clColor); } if (( uState & ODS_SELECTED) || m_bMouserOver ) { pdc->Draw3dRect(rc,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP()); rc.DeflateRect(1,1); } else if(m_ScrollButton || m_bSimple) { pdc->Draw3dRect(rc,GuiDrawLayer::GetRGBColorShadow(),GuiDrawLayer::GetRGBColorShadow()); rc.DeflateRect(1,1); } if (m_Transparent ) pdc->FillRect(rc,&cb); int calculodify; calculodify=rc.Height()-(m_SizeImage.cy); calculodify/=2; int nHeigh=calculodify+(m_bShowDark?1:0); int nWidth=m_ScrollButton?rc.Width()/2 :2; CPoint m_point=CPoint(nWidth,nHeigh); if (m_SizeImage.cx > 2) { if(m_bMouserOver == 1 && !(uState & ODS_DISABLED) && !(uState & ODS_SELECTED) && m_bShowDark) { CPoint p(m_point.x+1,m_point.y+1); pdc->DrawState(p,m_SizeImage,m_Icon,DSS_MONO,CBrush (GuiDrawLayer::GetRGBColorShadow())); m_point.x-=1; m_point.y-=1; } pdc->DrawState (m_point, m_SizeImage,m_Icon, (uState==ODS_DISABLED?DSS_DISABLED:DSS_NORMAL),(CBrush*)NULL); } if (m_SizeText.cx > 2) { int nMode = pdc->SetBkMode(TRANSPARENT); CRect rectletra=rc; int nt=m_ScrollButton?0:8; rectletra.left+=m_SizeImage.cx+nt; CPoint pt=CSize(rectletra.top,rectletra.left); if (uState & ODS_DISABLED) pdc->DrawState(pt, m_SizeText, m_szText, DSS_DISABLED, TRUE, 0, (CBrush*)NULL); else { if(m_bMouserOver != 1) pdc->SetTextColor(m_clrFont); pdc->DrawText(m_szText,rectletra,DT_SINGLELINE|DT_LEFT|DT_VCENTER); } pdc->SetBkMode(nMode); } // TODO: Add your code to draw the specified item }
void CLogGraph::drawHeader(CDC& dc) { XTPPaintManager()->GradientFill(&dc, m_rectHeader,m_crHeaderBack, RGB(0,0,0), FALSE); CPen* pOldPen, pen; CFont* pOldFont; CString fmt, s; int i; if (m_nScaleIndex != -1) drawScale(dc, m_nScaleIndex, m_rectScale, DT_RIGHT); if (m_nScaleIndex2 != -1) drawScale(dc, m_nScaleIndex2, m_rectScale2, DT_LEFT); // draw Header (로그 시작점, 로그 끝점 표시) CString tmp; pOldFont = dc.SelectObject(&m_fontHeader); dc.SetTextColor(m_crHeader); if (!m_bLoad)return; //short* a = new short [lib->mque_reclen(m_hQue)]; ////////////// tdata* tp = getTptr(m_nCurrentPos); // read date // lib->mque_getn(m_hQue, m_nCurrentPos+1, a); m_tStart = tp->time; s = tformat("%Y-%m-%d\r\n%H:%M:%S", m_tStart); tmp.Format("%s\r\n%d", s, m_nCurrentPos); dc.DrawText(tmp, &m_rectHeader, DT_LEFT); // lib->mque_getn(m_hQue, getWndQueLastPos()-1, a); tp = getTptr(getWndQueLastPos()-1); // m_tEnd = lib->mque_time(m_hQue); // s = tformat("%Y-%m-%d\r\n%H:%M:%S", (int)m_tEnd); tmp.Format("%s\r\n%d", s, getWndQueLastPos()); dc.DrawText(tmp, &m_rectHeader, DT_RIGHT); // delete a; // draw Header (nav button, zoom) int nav[4][20] = { // 20x20 짜리 nav button { 1,1, 4,1, 4,8, 18,1, 18,19, 4,12, 4,19, 1,19, 1,1, 0,0 }, // home { 1,10, 10,1, 10,8, 19,1, 19,19, 10,12, 10,19, 1,10, 0,0 }, // pgup { 1,1, 10,8, 10,1, 19,10, 10,19, 10,12, 1,19, 1,1, 0,0 }, // pgdn { 1,1, 16,8, 16,1, 19,1, 19,19, 16,19, 16,12, 1,19, 1,1, 0,0 } // end }; CRect r = m_rectHeader; int w = 20; // button width & height int iw = w - 4; // icon size CBrush brush; CRgn rgn; CPoint pt[20]; brush.CreateSolidBrush(RGB(255, 100, 100)); pen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255)); pOldPen = dc.SelectObject(&pen); r.left = r.Width() / 2 - (w * 4) / 2; r.right = r.left + w * 4; r.bottom = r.top + w; int x = r.left; for (i = 0; i < 4; i++) { CRect rect = r; rect.left = x + 1; rect.right = x + w - 1; rect.top++; rect.bottom--; switch (i) { case 0 : m_rectHome = rect; break; case 1 : m_rectPgUp = rect; break; case 2 : m_rectPgDn = rect; break; case 3 : m_rectEnd = rect; break; } XTPPaintManager()->GradientFill(&dc, &rect, RGB(100,100,100), RGB(0,0,0), FALSE); int j; for (j = 0; nav[i][j] !=0; j+=2) { pt[j/2].x = int(double(nav[i][j]) * iw / 20.0) + x + 2; pt[j/2].y = int(double(nav[i][j+1]) * iw / 20.0) + r.top + 2; } VERIFY(rgn.CreatePolygonRgn(pt, j/2, WINDING)); dc.FillRgn(&rgn, &brush); rgn.DeleteObject(); x += w; } dc.SelectObject(pOldPen); r.top = r.top + w; r.DeflateRect(2, 2); r.bottom = m_rectHeader.bottom; m_rectZoom = r; XTPPaintManager()->GradientFill(&dc, &r, RGB(100,50,50), RGB(0,0,0), FALSE); s.Format("Zoom %.0f:1", m_fZoomFactor); dc.DrawText(s, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE); dc.SelectObject(pOldFont); }
BOOL CContainer::OnPaint(HDC hDC) { CRect rcClient; CPaintDC dc(GetSafeHwnd()); // device context for painting CBrush cbr; CRect m_rectDraw; cbr.CreateSolidBrush(CDrawLayer::GetRGBColorFace()); GetClientRect(rcClient); CGDI MemDC; CBitmap m_BitmapMemDC; MemDC.CreateCompatibleDC(dc.m_hDC); m_BitmapMemDC.CreateCompatibleBitmap(dc.m_hDC,rcClient.Width(),rcClient.Height()); CBitmap *m_bitmapOld=new CBitmap(MemDC.SelectObject(&m_BitmapMemDC)); MemDC.FillRect(&rcClient,&cbr); m_rectTab=m_rectCliente; m_rectDraw=m_rectCliente; if (m_alnTab==ALN_BOTTOM) { if (m_Numtabs > 1) m_rectDraw.bottom=rcClient.bottom-(m_sizeImag.cy+SPACE_TAB+2); } else m_rectDraw.top=rcClient.top+(m_sizeImag.cy+SPACE_TAB+2); if (m_style != S3D) //si son carpetas estilo excel o tabbed como devstudio 7 { if (m_alnTab==ALN_BOTTOM) { m_rectCliente.bottom=rcClient.bottom-(DEFAULT_FLAT); m_rectTab.top=rcClient.bottom+2; } else { m_rectTab.bottom=rcClient.top+(DEFAULT_FLAT)+3; } } int nVal=0; if (m_alnTab!=ALN_TOP) { MemDC.FillRect(m_rectTab,&cbr); CRect mrc=m_rectDraw; } else { CRect rc=m_rectDraw; for (int i=0; i< 2; i++) { MemDC.Draw3dRect(rc,CDrawLayer::GetRGBColorFace(),CDrawLayer::GetRGBColorFace()); rc.DeflateRect(1,1); } rc.InflateRect(3,3); if (m_bDrawFrame) MemDC.Draw3dRect(rc,GetSysColor(COLOR_BTNSHADOW),GetSysColor(COLOR_BTNSHADOW)); else { CRect mrc=m_rectDraw; mrc.top+=nVal; MemDC.Draw3dRect(mrc,GetSysColor(COLOR_BTNSHADOW),GetSysColor(COLOR_BTNSHADOW)); } rc=m_rectDraw; rc.bottom=rc.top+3; MemDC.FillRect(rc,&cbr); } Drawtabs(&MemDC); dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),MemDC.m_hDC, rcClient.left,rcClient.top,SRCCOPY); MemDC.SelectObject(m_bitmapOld); m_BitmapMemDC.DeleteObject(); MemDC.DeleteDC(); cbr.DeleteObject(); m_bitmapOld->DeleteObject(); dc.DeleteDC(); delete m_bitmapOld; return TRUE; }
void CContainer::DrawGripper(CGDI* dc,CRect rcWin) { CRect rc=rcWin; rc.bottom=rc.top+18; CBrush cb; cb.CreateSolidBrush(CDrawLayer::GetRGBPressBXP()); dc->FillRect(rc, &cb); cb.DeleteObject (); dc->Draw3dRect(rc,CDrawLayer::GetRGBMenu(),CDrawLayer::GetRGBMenu()); //CGradient M(CSize(rc.Width(),rc.Height()+4)); //M.PrepareVertical(dc); //M.Draw(dc,rc.left,rc.top+1,0,0,rc.Width(),rc.Height()+4,SRCCOPY); int OldMode=dc->SetBkMode(TRANSPARENT); CFont cf; COLORREF clrtext; clrtext=dc->SetTextColor(::GetSysColor (COLOR_MENUTEXT)); cf.CreateFont(-11,2,0,0,FW_NORMAL,0,0,0,0,1,2,1,34,"MS Sans Serif"); HFONT cff=dc->SelectObject(cf); //guardar espacio para la imagen CTab* ct=(CTab*) m_pArray[m_iSelectTab]; TCHAR m_cadBreak[126]; memset(m_cadBreak,0x00,126); lstrcpy(m_cadBreak,ct->lpMsg); int contt; int cont =contt=strlen(m_cadBreak); CSize coor=dc->GetTextExtent(m_cadBreak,cont); rc.left+=3; if ( coor.cx > (rc.Width()-35)) { rc.left+=1; while(cont > 1 ) { TCHAR m_scadtemp[64]; memset(m_scadtemp,0x00,64); lstrcpy(m_scadtemp,m_cadBreak); lstrcat(m_scadtemp,_T("...")); CSize coor=dc->GetTextExtent(m_scadtemp,lstrlen(m_scadtemp)); if(coor.cx > (rc.Width()-35)) *(m_cadBreak+cont)=NULL; else break; cont--; } lstrcat(m_cadBreak,_T("...")); rc.right+=3; dc->DrawText(m_cadBreak,rc,DT_SINGLELINE|DT_LEFT|DT_VCENTER); } else dc->DrawText(ct->lpMsg,rc,DT_SINGLELINE|DT_LEFT|DT_VCENTER); //------------------------- //No Client Button //------------------------- rc=rcWin; rc.left=rcWin.right-18; rc.bottom=rc.top+18; rc.right-=7; rc.top+=3; rc.bottom-=3; if (m_DOCKFLOAT !=BS_FLOATING) { m_rcAutoHideBtn=rc; m_rcAutoHideBtn.right-=12; m_rcAutoHideBtn.left-=12; } m_rcCloseBtn=rc; if (m_bCaption) { m_CloseBtn.Paint(dc,m_stateBtn,m_rcCloseBtn,CDrawLayer::GetRGBPressBXP(),TRUE ); //if (m_DOCKFLOAT !=BS_FLOATING) // m_AutoHideBtn.Paint(dc,m_stateAHBtn,m_rcAutoHideBtn,CDrawLayer::GetRGBGray(),TRUE); } dc->SelectObject(cff); cf.DeleteObject(); }
BOOL CFavUrlMenuDlg::OnEraseBkgnd(CDC* pDC) { CRect rctWnd; GetWindowRect(&rctWnd); ScreenToClient(rctWnd); CBrush brush; brush.CreateSolidBrush(m_rgbBackGnd); CBrush *pOldBrush = pDC->SelectObject(&brush); CPen pen; pen.CreatePen(PS_SOLID, m_nBorderWidth, m_rgbBorder); CPen *pOldPen = pDC->SelectObject(&pen); // 画圆角矩形 rctWnd.left += m_nBorderWidth/2; rctWnd.top += m_nBorderWidth/2; rctWnd.right -= m_nBorderWidth/2; rctWnd.bottom -= m_nBorderWidth/2; if ((m_nBorderWidth % 2) ) { rctWnd.right -= 1; rctWnd.bottom -= 1; } pDC->RoundRect(rctWnd, CPoint(m_nBorderWidth, m_nBorderWidth)); pDC->SelectObject(pOldPen); pen.DeleteObject(); pDC->SelectObject(pOldBrush); brush.DeleteObject(); pDC->SelectObject(m_font); pDC->SetTextColor(m_rgbText); pDC->SetBkMode(TRANSPARENT); CRect rctItem( m_rctFirsItem); rctItem.left += m_nSpacingHeigth; for (INT_PTR i=0; i<m_arrItems.GetSize(); i++) { ITEM item = m_arrItems.GetAt(i); if (item.type != ITEM_TYPE_SEPARATOR) { pDC->DrawText(item.strName, rctItem, DT_VCENTER|DT_SINGLELINE); if (item.type == ITEM_TYPE_DIRECTORY) { // 画小三角 int y = rctItem.top + rctItem.Height()/2; int x = rctItem.right - m_nSpacingHeigth; CPoint ptA(x, y); y = y - rctItem.Height()/2 + m_nSpacingHeigth/2; x -= rctItem.Height()/2; CPoint ptB(x, y); CPoint ptC(x, y+rctItem.Height() - m_nSpacingHeigth); CBrush brush; brush.CreateSolidBrush(m_rgbBorder); CBrush* pOld = pDC->SelectObject(&brush); pDC->BeginPath(); pDC->MoveTo(ptA.x,ptA.y); pDC->LineTo(ptB.x,ptB.y); pDC->LineTo(ptC.x,ptC.y); pDC->LineTo(ptA.x,ptA.y); pDC->EndPath(); pDC->FillPath(); pDC->SelectObject(&pOld); brush.DeleteObject(); } } else { CPen pen; pen.CreatePen(PS_SOLID, 1, m_rgbBorder); CPen *pOld = pDC->SelectObject(&pen); int y = rctItem.top + rctItem.Height()/5; int x = rctItem.left; rctItem.top += rctItem.Height()/5; rctItem.top -= rctItem.Height(); LineAtoB(pDC, CPoint(x,y), CPoint(x+rctItem.Width()-m_nSpacingHeigth, y)); pDC->SelectObject(pOld); pen.DeleteObject(); } rctItem.top += m_rctFirsItem.Height(); rctItem.bottom = rctItem.top + m_rctFirsItem.Height(); } pDC->SelectObject(pOldPen); pen.DeleteObject(); return TRUE; }
void CWindowsMetaFileControl::DrawShape(CDC* pDC, int nShape, CRect* pcrBounds, COLORREF clColor, COLORREF clStrokeColor /*=COLORREF(-1)*/, int nStrokeWidth /*=0*/) { CBrush cbColor; CPen cpColor; pDC->SaveDC(); if (clStrokeColor == COLORREF(-1)) { clStrokeColor = clColor; } TRY { int nWidth = pcrBounds->Width(); int nHeight = pcrBounds->Height(); if ((nWidth > 0) && (nHeight > 0)) { if (cbColor.CreateSolidBrush(clColor)) { if (cpColor.CreatePen(PS_INSIDEFRAME, nStrokeWidth, clStrokeColor)) { pDC->SelectObject(&cbColor); pDC->SelectObject(&cpColor); if (nShape == SHAPE_CIRCLE) { pDC->Ellipse(pcrBounds); } else if (nShape == SHAPE_SQUARE) { pDC->Rectangle(pcrBounds); } else { int x0, y0; int x1, y1; int x2, y2; switch (nShape) { case SHAPE_TRIANGLEUP: { x0 = pcrBounds->left; x1 = pcrBounds->right-1; x2 = (x0+x1)/2; y0 = pcrBounds->bottom-1; y1 = y0; y2 = pcrBounds->top; if ((nWidth%2) == 0) { x1--; } break; } case SHAPE_TRIANGLEDOWN: { x0 = pcrBounds->left; x1 = pcrBounds->right-1; x2 = (x0+x1)/2; y0 = pcrBounds->top; y1 = y0; y2 = pcrBounds->bottom-1; if ((nWidth%2) == 0) { x1--; } break; } case SHAPE_TRIANGLELEFT: { x0 = pcrBounds->right-1; x1 = x0; x2 = pcrBounds->left; y0 = pcrBounds->top; y1 = pcrBounds->bottom-1; y2 = (y0+y1)/2; if ((nHeight%2) == 0) { y1--; } break; } case SHAPE_TRIANGLERIGHT: { x0 = pcrBounds->left; x1 = x0; x2 = pcrBounds->right-1; y0 = pcrBounds->top; y1 = pcrBounds->bottom-1; y2 = (y0+y1)/2; if ((nHeight%2) == 0) { y1--; } break; } default: { ASSERT(FALSE); break; } } POINT Points[4]; Points[0].x = x0; Points[0].y = y0; Points[1].x = x1; Points[1].y = y1; Points[2].x = x2; Points[2].y = y2; Points[3].x = x0; Points[3].y = y0; pDC->Polygon(&Points[0], 4); } } } } } END_TRY pDC->RestoreDC(-1); }
void CCheckerCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default SetFocus(); DWORD dwPos = GetMessagePos(); CPoint clickedPoint((int)(short)LOWORD(dwPos), (int)(short)HIWORD(dwPos)); ScreenToClient(&clickedPoint); { CRect cRect; GetWindowRect(&cRect); ScreenToClient(&cRect); UINT nY = UINT(((float)clickedPoint.y / (float(cRect.Height())/float(m_nBlocksPerColumn)))+.3); UINT nX = UINT(((float)clickedPoint.x / (float(cRect.Width())/float(m_nBlocksPerRow)))+.3); UINT nIndex = nY * m_nBlocksPerRow + nX + m_nyPos * m_nBlocksPerRow; if(nIndex < m_nNumberofBlocks && nX < m_nBlocksPerRow) { CString strNumber; // strNumber.Format("%d", nIndex + m_nStartIndex+1); strNumber = (m_crText.GetAt(nIndex + m_nStartIndex)); if (strNumber.GetLength()) { SetCapture(); CreateSafeTooltipRect(clickedPoint.x, clickedPoint.y, strNumber); GetParent()->PostMessage(9876,(WPARAM)(nIndex+m_nStartIndex+1), 0); CClientDC dc(this); CBrush brush; brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK)); dc.Rectangle(tooltipRect); tooltipRect.left++; tooltipRect.top++; tooltipRect.bottom--; tooltipRect.right--; dc.FillRect(tooltipRect, &brush); CFont font; LOGFONT logFont; strcpy(logFont.lfFaceName, "Verdana"); logFont.lfHeight = -MulDiv(12, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), 72); logFont.lfWidth = 0; logFont.lfEscapement = 0; logFont.lfItalic = FALSE; logFont.lfStrikeOut = FALSE; logFont.lfUnderline = FALSE; logFont.lfWeight = FW_BOLD; font.CreateFontIndirect(&logFont); dc.SelectObject(font); dc.SetTextColor(GetSysColor(COLOR_INFOTEXT)); dc.SetBkColor(GetSysColor(COLOR_INFOBK)); dc.DrawText(strNumber, tooltipRect, DT_VCENTER | DT_CENTER | DT_SINGLELINE); tooltipRect.left--; tooltipRect.top--; tooltipRect.bottom++; tooltipRect.right++; m_bShouldUpdated = TRUE; } } } CWnd::OnLButtonDown(nFlags, point); }
void CDockButton::OnPaint() { CPaintDC dc(this); // device context for painting CBrush cb; COLORREF m_clrBorder=GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style); COLORREF m_clrFace=GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Style); CPen cp(PS_SOLID,1,m_clrFace); CPen* cpold=dc.SelectObject(&cp); CRect m_rect; GetClientRect(m_rect); cb.CreateSolidBrush(m_clrFace); if (GuiDrawLayer::m_Style== GUISTYLE_XP) dc.FillRect(m_rect,&cb); else { CGradient M(CSize(m_rect.Width(),m_rect.Height())); if (m_nDockBarAling ==AFX_IDW_DOCKBAR_LEFT || m_nDockBarAling ==AFX_IDW_DOCKBAR_RIGHT) M.PrepareCaptionVert(&dc,GuiDrawLayer::m_Style); else M.PrepareCaption(&dc,GuiDrawLayer::m_Style); M.Draw(&dc,m_rect.left,m_rect.top,0,0,m_rect.Width(),m_rect.Height(),SRCCOPY); } dc.Draw3dRect(m_rect,m_clrBorder,m_clrBorder); GuiDrawLayer::DrawIcon(&dc,CPoint(m_rect.left+2,m_rect.top+2),m_szBtn,m_hIcon); switch(m_nDockBarAling) { case AFX_IDW_DOCKBAR_TOP: dc.MoveTo(m_rect.left,m_rect.top); dc.LineTo(m_rect.right,m_rect.top); if(m_hIcon != NULL) m_rect.left+=m_szBtn.cx+4; DrawTextHorz(&dc,m_rect); break; case AFX_IDW_DOCKBAR_LEFT: dc.MoveTo(m_rect.left,m_rect.top); dc.LineTo(m_rect.left,m_rect.bottom); if(m_hIcon != NULL) m_rect.top+=m_szBtn.cy+4; DrawTextVert(&dc,m_rect); break; case AFX_IDW_DOCKBAR_RIGHT: dc.MoveTo(m_rect.right-1,m_rect.top); dc.LineTo(m_rect.right-1,m_rect.bottom); if(m_hIcon != NULL) m_rect.top+=m_szBtn.cy+4; DrawTextVert(&dc,m_rect); break; case AFX_IDW_DOCKBAR_BOTTOM: dc.MoveTo(m_rect.left,m_rect.bottom-1); dc.LineTo(m_rect.right,m_rect.bottom-1); if(m_hIcon != NULL) m_rect.left+=m_szBtn.cx+4; DrawTextHorz(&dc,m_rect); break; } dc.SelectObject(cpold); }
void CDiceView::OnDraw(CDC* pDC) { CDiceDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here //initialize CRect viewRect; CWnd::GetClientRect(&viewRect); cellx = viewRect.right/(6+1); celly = viewRect.bottom/(5+1); radius = celly/3; //draw vs CRect vsRect; vsRect.left = viewRect.right/2 - radius*2; vsRect.top = 0; vsRect.right = viewRect.right/2 + radius*2; vsRect.bottom = celly; pDC->DrawText("VS", vsRect, DT_VCENTER|DT_CENTER|DT_SINGLELINE); //draw fight info for(int j = 0; j<2; j++) { if(ftInfo[j].country < 0) break; ftInfo[j].fightRect.left = (j+3)*cellx; ftInfo[j].fightRect.top = celly/4; ftInfo[j].fightRect.right = (j+3)*cellx + radius; ftInfo[j].fightRect.bottom = celly/4 + radius; CBrush brush; switch(ftInfo[j].country) { case 0: brush.CreateSolidBrush(RGB(128,128,128)); pDC->SetBkColor(RGB(128,128,128)); break; case 1: brush.CreateSolidBrush(RGB(255,0,0)); pDC->SetBkColor(RGB(255,0,0)); break; case 2: brush.CreateSolidBrush(RGB(0,255,0)); pDC->SetBkColor(RGB(0,255,0)); break; case 3: brush.CreateSolidBrush(RGB(0,0,255)); pDC->SetBkColor(RGB(0,0,255)); break; case 4: brush.CreateSolidBrush(RGB(255,255,0)); pDC->SetBkColor(RGB(255,255,0)); break; case 5: brush.CreateSolidBrush(RGB(255,0,255)); pDC->SetBkColor(RGB(255,0,255)); break; case 6: brush.CreateSolidBrush(RGB(0,255,255)); pDC->SetBkColor(RGB(0,255,255)); break; case 7: brush.CreateSolidBrush(RGB(0,128,128)); pDC->SetBkColor(RGB(0,128,128)); break; default:break; } pDC->FillRect(ftInfo[j].fightRect,&brush); char text[1] = {0}; pDC->SetTextColor(RGB(255,255,255)); itoa(ftInfo[j].fightPts,text,10); pDC->DrawText(text,ftInfo[j].fightRect,DT_VCENTER|DT_CENTER|DT_SINGLELINE); } //draw button buttonRect.left = viewRect.right-100; buttonRect.top = viewRect.bottom-50; buttonRect.right = viewRect.right-5; buttonRect.bottom = viewRect.bottom-5; CBrush brush; brush.CreateSolidBrush(RGB(160,160,160)); pDC->FillRect(buttonRect,&brush); pDC->SetBkColor(RGB(160,160,160)); if(btnClicked) pDC->DrawEdge(buttonRect,EDGE_SUNKEN,BF_BOTTOMRIGHT | BF_TOPLEFT); else pDC->DrawEdge(buttonRect,EDGE_RAISED,BF_BOTTOMRIGHT | BF_TOPLEFT); pDC->DrawText("End Turn",buttonRect,DT_VCENTER|DT_CENTER|DT_SINGLELINE); //draw maxConnection for(int i = 0; i<8; i++) { CBrush brush; CRect maxConnectionRect; maxConnectionRect.left = (i+1)*cellx/1.5 + cellx/2.25 - radius/1.5; maxConnectionRect.top = (5+0.75)*celly - radius/1.5; maxConnectionRect.right = (i+1)*cellx/1.5 +cellx/2.25 + radius/1.5; maxConnectionRect.bottom = (5+0.75)*celly + radius/1.5; players[i].maxConnectionRect = CRect(maxConnectionRect.left - 5, maxConnectionRect.top - 5, maxConnectionRect.right +5, maxConnectionRect.bottom+5); switch(i) { case 0: brush.CreateSolidBrush(RGB(128,128,128)); pDC->SetBkColor(RGB(128,128,128)); break; case 1: brush.CreateSolidBrush(RGB(255,0,0)); pDC->SetBkColor(RGB(255,0,0)); break; case 2: brush.CreateSolidBrush(RGB(0,255,0)); pDC->SetBkColor(RGB(0,255,0)); break; case 3: brush.CreateSolidBrush(RGB(0,0,255)); pDC->SetBkColor(RGB(0,0,255)); break; case 4: brush.CreateSolidBrush(RGB(255,255,0)); pDC->SetBkColor(RGB(255,255,0)); break; case 5: brush.CreateSolidBrush(RGB(255,0,255)); pDC->SetBkColor(RGB(255,0,255)); break; case 6: brush.CreateSolidBrush(RGB(0,255,255)); pDC->SetBkColor(RGB(0,255,255)); break; case 7: brush.CreateSolidBrush(RGB(0,128,128)); pDC->SetBkColor(RGB(0,128,128)); break; default:break; } pDC->FillRect(maxConnectionRect,&brush); char text[1] = {0}; pDC->SetTextColor(RGB(255,255,255)); itoa(players[i].maxConnection,text,10); pDC->DrawText(text,maxConnectionRect,DT_VCENTER|DT_CENTER|DT_SINGLELINE); pDC->DrawEdge(maxConnectionRect,EDGE_RAISED,BF_BOTTOMRIGHT | BF_TOPLEFT); if(players[i].isMyTurn) { CPen pen,*oldPen; oldPen = pDC->GetCurrentPen(); pen.CreatePen(PS_SOLID,4,RGB(0,0,0)); pDC->SelectObject(pen); pDC->MoveTo(maxConnectionRect.left, maxConnectionRect.top); pDC->LineTo(maxConnectionRect.right, maxConnectionRect.top); pDC->MoveTo(maxConnectionRect.right, maxConnectionRect.top); pDC->LineTo(maxConnectionRect.right, maxConnectionRect.bottom); pDC->MoveTo(maxConnectionRect.right, maxConnectionRect.bottom); pDC->LineTo(maxConnectionRect.left, maxConnectionRect.bottom); pDC->MoveTo(maxConnectionRect.left, maxConnectionRect.bottom); pDC->LineTo(maxConnectionRect.left, maxConnectionRect.top); pDC->SelectObject(oldPen); } } //draw Nodes & draw path int visited = 0; CPoint from,to; for(int num = 0; num<5*6; num++) { from.x = (num%6 + 1)*cellx; from.y = (num/(5+1) + 1)*celly; for(set<int>::iterator iter = path[num].begin(); iter!=path[num].end(); iter++) { if(*iter<visited) continue; to.x = (*iter%6 + 1)*cellx; to.y = (*iter/(5+1) + 1)*celly; pDC->MoveTo(from); pDC->LineTo(to); } visited++; CBrush brush; CRect rect(from.x-radius,from.y-radius,from.x+radius,from.y+radius); nodes[num].nodeRect = CRect(from.x-radius-5,from.y-radius-5,from.x+radius+5,from.y+radius+5); //chooseColor switch(nodes[num].country) { case 0: brush.CreateSolidBrush(RGB(128,128,128)); pDC->SetBkColor(RGB(128,128,128)); break; case 1: brush.CreateSolidBrush(RGB(255,0,0)); pDC->SetBkColor(RGB(255,0,0)); break; case 2: brush.CreateSolidBrush(RGB(0,255,0)); pDC->SetBkColor(RGB(0,255,0)); break; case 3: brush.CreateSolidBrush(RGB(0,0,255)); pDC->SetBkColor(RGB(0,0,255)); break; case 4: brush.CreateSolidBrush(RGB(255,255,0)); pDC->SetBkColor(RGB(255,255,0)); break; case 5: brush.CreateSolidBrush(RGB(255,0,255)); pDC->SetBkColor(RGB(255,0,255)); break; case 6: brush.CreateSolidBrush(RGB(0,255,255)); pDC->SetBkColor(RGB(0,255,255)); break; case 7: brush.CreateSolidBrush(RGB(0,128,128)); pDC->SetBkColor(RGB(0,128,128)); break; default:break; } if(nodes[num].isChosen) { CPen pen,*oldPen; oldPen = pDC->GetCurrentPen(); pen.CreatePen(PS_SOLID,7,RGB(0,0,0)); pDC->SelectObject(pen); pDC->Ellipse(rect); pDC->SelectObject(oldPen); } pDC->SelectObject(brush); pDC->Ellipse(rect); CFont font; font.CreateFont( radius*1.2, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily "Arial"); pDC->SelectObject(&font); char text[1] = {0}; pDC->SetTextColor(RGB(255,255,255)); itoa(nodes[num].diceNum,text,10); pDC->DrawText(text,rect,DT_VCENTER|DT_CENTER|DT_SINGLELINE); } }
void CButtonST::DrawItem(UINT ctrlID, LPDRAWITEMSTRUCT lpDIS) { CDCHandle pDC = lpDIS->hDC; CPenHandle pOldPen; // Checkbox or Radiobutton style ? if (m_bIsCheckBox) { m_bIsPressed = (lpDIS->itemState & ODS_SELECTED) || m_nCheck; } // Normal button OR other button style ... else { m_bIsPressed = (lpDIS->itemState & ODS_SELECTED); } m_bIsFocused = (lpDIS->itemState & ODS_FOCUS) != 0; m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED) != 0; CRect itemRect = lpDIS->rcItem; pDC.SetBkMode(TRANSPARENT); if (!m_bIsFlat) { if (m_bIsFocused || GetDefault()) { CBrush br; br.CreateSolidBrush(RGB(0,0,0)); pDC.FrameRect(&itemRect, br); itemRect.DeflateRect(1, 1); } } // Prepare draw... paint button background // Draw transparent? if (m_bDrawTransparent) { PaintBk(pDC); } else { OnDrawBackground(pDC, &itemRect); } // Draw pressed button if (m_bIsPressed) { if (m_bIsFlat) { if (m_bDrawBorder) { OnDrawBorder(pDC, &itemRect); } } else { CBrush brBtnShadow; brBtnShadow.CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW)); pDC.FrameRect(&itemRect, brBtnShadow); } } else // ...else draw non pressed button { CPen penBtnHiLight; // White CPen pen3DLight; // Light gray CPen penBtnShadow; // Dark gray CPen pen3DDKShadow; // Black penBtnHiLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNHILIGHT)); // White pen3DLight.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DLIGHT)); // Light gray penBtnShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_BTNSHADOW)); // Dark gray pen3DDKShadow.CreatePen(PS_SOLID, 0, ::GetSysColor(COLOR_3DDKSHADOW)); // Black if (m_bIsFlat) { if (m_bMouseOnButton && m_bDrawBorder) { pDC.Draw3dRect(itemRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW)); } } else { // Draw top-left borders // White line pOldPen = pDC.SelectPen(penBtnHiLight); pDC.MoveTo(itemRect.left, itemRect.bottom-1); pDC.LineTo(itemRect.left, itemRect.top); pDC.LineTo(itemRect.right, itemRect.top); // Light gray line pDC.SelectPen(pen3DLight); pDC.MoveTo(itemRect.left+1, itemRect.bottom-1); pDC.LineTo(itemRect.left+1, itemRect.top+1); pDC.LineTo(itemRect.right, itemRect.top+1); // Draw bottom-right borders // Black line pDC.SelectPen(pen3DDKShadow); pDC.MoveTo(itemRect.left, itemRect.bottom-1); pDC.LineTo(itemRect.right-1, itemRect.bottom-1); pDC.LineTo(itemRect.right-1, itemRect.top-1); // Dark gray line pDC.SelectPen(penBtnShadow); pDC.MoveTo(itemRect.left+1, itemRect.bottom-2); pDC.LineTo(itemRect.right-2, itemRect.bottom-2); pDC.LineTo(itemRect.right-2, itemRect.top); // pDC.SelectPen(pOldPen); } } // Read the button's title CString sTitle; int nLen = GetWindowTextLength(); int nRetLen = GetWindowText(sTitle.GetBufferSetLength(nLen), nLen + 1); CRect captionRect = lpDIS->rcItem; // Draw the icon if (m_csIcons[0].hIcon != 0) { DrawTheIcon(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled); } if (m_csBitmaps[0].hBitmap != 0) { pDC.SetBkColor(RGB(255,255,255)); DrawTheBitmap(pDC, !sTitle.IsEmpty(), lpDIS->rcItem, captionRect, m_bIsPressed, m_bIsDisabled); } // Write the button title (if any) if (!sTitle.IsEmpty()) { // Draw the button's title // If button is pressed then "press" title also if (m_bIsPressed && !m_bIsCheckBox) { captionRect.OffsetRect(1, 1); } // Center text CRect centerRect = captionRect; pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT); captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2); pDC.SetBkMode(TRANSPARENT); if (m_bIsDisabled) { captionRect.OffsetRect(1, 1); pDC.SetTextColor(::GetSysColor(COLOR_3DHILIGHT)); pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); captionRect.OffsetRect(-1, -1); pDC.SetTextColor(::GetSysColor(COLOR_3DSHADOW)); pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); } else { if (m_bMouseOnButton || m_bIsPressed) { pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_IN]); pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_IN]); } else { pDC.SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]); pDC.SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]); } pDC.DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER); } } if (!m_bIsFlat || (m_bIsFlat && m_bDrawFlatFocus)) { // Draw the focus rect if (m_bIsFocused) { CRect focusRect = itemRect; focusRect.DeflateRect(3, 3); pDC.DrawFocusRect(&focusRect); } } }
void CGuiVisioFolder::DrawFolder(CFolderBar* cfb,Style m_Style) { CRect rc=cfb->m_rect; CRect rcWin=cfb->m_rect; int nNuImage=cfb->m_img; CString szStringPoints=_T("..."); CBrush cb; CClientDC pDC(this); cb.CreateSysColorBrush(COLOR_BTNFACE); rc.top+=1; pDC.FillRect(&rc,&cb); //se pintan bordes que simulen un boton if (m_Style == mNormal) //el folder no tiene el mouse { pDC.Draw3dRect(rc, GuiDrawLayer::GetRGBColorBTNHigh(),GuiDrawLayer::GetRGBColorShadow()); rc.DeflateRect(1,1); pDC.Draw3dRect(rc, GuiDrawLayer::GetRGBColorFace(),GuiDrawLayer::GetRGBColorShadow()); } else if (m_Style == mFlat) //el mouse esta sobre el folder pero no presiona pDC.Draw3dRect(rc, GuiDrawLayer::GetRGBColorBTNHigh(),GuiDrawLayer::GetRGBColorShadow()); else if (m_Style == mPush) //el mouse esta sobre el folder y presiona pDC.Draw3dRect(rc, GuiDrawLayer::GetRGBColorShadow(),GuiDrawLayer::GetRGBColorBTNHigh()); int OldMode=pDC.SetBkMode(TRANSPARENT); cfont = pDC.SelectObject(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT))); CString m_cadBreak=cfb->m_lpMsg; int cont=m_cadBreak.GetLength(); CSize coor=pDC.GetTextExtent(m_cadBreak,m_cadBreak.GetLength()); CSize szImage=CSize(0,0); //se dibuja la imagen if(nNuImage != -1) { IMAGEINFO pImageInfo; m_Img.GetImageInfo(nNuImage,&pImageInfo); CRect rcima =pImageInfo.rcImage; szImage=CSize(rcima.Width(),rcima.Height()); CPoint pti=CPoint(rc.left+2,rc.top+3); m_Img.Draw(&pDC, nNuImage, pti, ILD_TRANSPARENT); } //guardar espacio para la imagen rc.left+=szImage.cx+4; rc.right-=8; if ( coor.cx > rc.Width()) { rc.left+=1; while(cont > 1 ) { CString m_scadtemp=m_cadBreak+szStringPoints; CSize coor=pDC.GetTextExtent(m_scadtemp,m_scadtemp.GetLength()); if(coor.cx > rc.Width()) m_cadBreak=m_cadBreak.Left(m_cadBreak.GetLength()-1); else break; cont--; } m_cadBreak+=szStringPoints; rc.right+=3; pDC.DrawText(m_cadBreak,rc,DT_SINGLELINE|DT_LEFT|DT_VCENTER); } else pDC.DrawText(cfb->m_lpMsg,rc,DT_WORDBREAK|DT_SINGLELINE|DT_CENTER|DT_VCENTER); //----se dibuja el gripper---------- rcWin.top+=5; rcWin.right-=4; rcWin.left=rcWin.right-3; rcWin.bottom-=4; for (int i=0; i < rcWin.Height(); i+=2) { CRect rcWindow; CBrush cb; cb.CreateSolidBrush(::GetSysColor(COLOR_BTNSHADOW)); rcWindow=rcWin; rcWindow.top=rcWin.top+i; rcWindow.bottom=rcWindow.top+1; pDC.FillRect(rcWindow,&cb); cb.DeleteObject(); } //------------------------- cb.DeleteObject(); pDC.SetBkColor(OldMode); }
LRESULT CNavigatorOptionsDlg::OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { UINT idCtl = (UINT) wParam; // control identifier LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam; // item-drawing information CDCHandle pDC = lpDrawItemStruct->hDC; CRect rc = lpDrawItemStruct->rcItem; if (idCtl == IDC_NAV_COLOR) { pDC.DrawEdge(&rc, (lpDrawItemStruct->itemState & ODS_SELECTED)? EDGE_SUNKEN : EDGE_RAISED, BF_RECT | BF_ADJUST); rc.InflateRect(-1,-1); pDC.FillSolidRect(&rc, m_color); } else { int w = 12; int h = 12; int id = lpDrawItemStruct->itemID; if (id >= 0) { COLORREF ref; if (lpDrawItemStruct->itemState & ODS_SELECTED) ref = ::GetSysColor(COLOR_HIGHLIGHT); else ref = ::GetSysColor(COLOR_WINDOW); // pDC->FillSolidRect(rc.left+1, rc.top+1, rc.Width()-1, rc.Height()-1, ref); pDC.FillSolidRect(&rc, ref); if (lpDrawItemStruct->itemState & ODS_FOCUS) pDC.DrawFocusRect(&rc); if (id >= 1) { HBRUSH hOldBrush = pDC.SelectBrush((HBRUSH)GetStockObject(NULL_BRUSH)); pDC.Rectangle(rc.left+1, rc.top+1, rc.left+w+3, rc.top+h+3); pDC.SelectBrush(hOldBrush); CBrush brush; brush.CreateSolidBrush(Colors[id].color); /* #define MyFillRect(x, y, w, h, br) \ r.left = x; r.top = y; r.right = x+w; r.bottom = y+h; \ pDC->FillRect(&r, br) */ CRect r(rc.left+2, rc.top+2, rc.left+2+w, rc.top+2+h); pDC.FillRect(&r, brush); } if (lpDrawItemStruct->itemState & ODS_SELECTED) { pDC.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); pDC.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); } else { pDC.SetTextColor(::GetSysColor(COLOR_WINDOWTEXT)); pDC.SetBkColor(::GetSysColor(COLOR_WINDOW)); } pDC.TextOut(rc.left+((id >= 1)? (w+6): 4), rc.top+2, (LPCTSTR)lpDrawItemStruct->itemData); } } return 0; }
void CPanTool::OnMouseMove(_CVIEW* pView, UINT nFlags, CPoint& point) { ::SetCursor(AfxGetApp()->LoadCursor(IDC_PAN)); CDC* pDC = NULL; pDC = pView->GetDC(); if (pDC == NULL) return; CMiniCADDoc* pDoc = pView->GetDocument(); if (pDoc==NULL)return; CADGraphics *pGraphics = &pDoc->m_Graphics; CDisplay *pDisplay = pGraphics->m_pDisplay; if (pDisplay == NULL) return; if (!c_bDown) { DeleteDC(pDC->m_hDC); return; } ::SetCursor(AfxGetApp()->LoadCursor(IDC_PANDOWN)); double ddx,ddy; int dx,dy; dx=point.x-c_PtOld.x; dy=point.y-c_PtOld.y; ddx=dx/pDoc->m_Graphics.m_ZoomRate; ddy=dy/pDoc->m_Graphics.m_ZoomRate; int cx = point.x - c_PtDown.x; int cy = point.y - c_PtDown.y; CBrush brush; brush.CreateSolidBrush(pDoc->m_Graphics.m_BKColor); CRect rect; CRect rect2; pView->GetClientRect(rect); if(pView->m_curWorkSpace==MODELSPACE) { if (cx>0) rect2.SetRect(0,0,cx,rect.Height()); else rect2.SetRect(rect.Width()+cx,0,rect.Width(),rect.Height()); pDC->FillRect(&rect2, &brush); if (cy>0) rect2.SetRect(0,0,rect.Width(),cy-1); else rect2.SetRect(0,rect.Height()+cy,rect.Width(),rect.Height()); pDC->FillRect(&rect2, &brush); pDC->BitBlt(cx,cy,rect.Width(),rect.Height(),pDisplay->GetDC(),0,0,SRCCOPY); } else { CRect moveRect=pView->m_ModelRect; CDC* pPaperDC=pDisplay->GetPaperDC(); int xOffset=0; int yOffset=0; if (cx>0) { if(cx>pView->m_ModelRect.Width())cx=pView->m_ModelRect.Width(); rect2.SetRect(pView->m_ModelRect.left,pView->m_ModelRect.top,pView->m_ModelRect.left+cx,pView->m_ModelRect.top+pView->m_ModelRect.Height()); moveRect.left+=cx; } else { if(cx<-pView->m_ModelRect.Width())cx=-pView->m_ModelRect.Width(); rect2.SetRect(pView->m_ModelRect.left+pView->m_ModelRect.Width()+cx,pView->m_ModelRect.top,pView->m_ModelRect.left+pView->m_ModelRect.Width(),pView->m_ModelRect.top+pView->m_ModelRect.Height()); moveRect.right+=cx; xOffset-=cx; } pPaperDC->FillRect(&rect2, &brush); if (cy>0) { if(cy>pView->m_ModelRect.Height())cy=pView->m_ModelRect.Height(); rect2.SetRect(pView->m_ModelRect.left,pView->m_ModelRect.top,pView->m_ModelRect.left+pView->m_ModelRect.Width(),pView->m_ModelRect.top+cy); moveRect.top+=cy; } else { if(cy<-pView->m_ModelRect.Height())cy=-pView->m_ModelRect.Height(); rect2.SetRect(pView->m_ModelRect.left,pView->m_ModelRect.top+pView->m_ModelRect.Height()+cy,pView->m_ModelRect.left+pView->m_ModelRect.Width(),pView->m_ModelRect.top+pView->m_ModelRect.Height()); moveRect.bottom+=cy; yOffset-=cy; } pPaperDC->FillRect(&rect2, &brush); pPaperDC->BitBlt(moveRect.left,moveRect.top,moveRect.Width(),moveRect.Height(),pDisplay->GetDC(),xOffset,yOffset,SRCCOPY); pView->Invalidate(false); } brush.DeleteObject(); DeleteDC(pDC->m_hDC); CDrawTool::OnMouseMove(pView, nFlags, point); }
void CColorButton::DrawFilledRect(CDC *DC, CRect R, COLORREF color) { CBrush B; B.CreateSolidBrush(color); DC->FillRect(R, &B); }
void CLinkButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // 获取一个CDC指针 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); //定义按钮区域并初始化 CRect rect(lpDrawItemStruct->rcItem); //设置背景模式 COLORREF oc=RGB(30,123,255); //oc = pDC->GetTextColor(); int iObk = pDC->SetBkMode(TRANSPARENT); //初始化按钮状态 UINT state = lpDrawItemStruct->itemState; CFont * pOldFont = NULL; int iYOffset = 0, iXOffset = 0; CString strText; GetWindowText(strText); rect.top += iYOffset; rect.left += iXOffset; if (state & ODS_DISABLED) { //按钮置灰(DISABLED) CBrush grayBrush; grayBrush.CreateSolidBrush (GetSysColor (COLOR_GRAYTEXT)); CSize sz = pDC->GetTextExtent(strText); int x = rect.left + (rect.Width() - sz.cx)/2; int y = rect.top + (rect.Height() - sz.cy)/2; rect.top += 2; rect.left += 2; pDC->SetTextColor(GetSysColor(COLOR_3DHIGHLIGHT)); pDC->DrawText(strText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); rect.top -= 2; rect.left -= 2; pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); pDC->DrawText(strText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } else { if (bHighlight)//光标在按钮上 { if (state & ODS_SELECTED) { //按下按钮 pDC->Draw3dRect(rect,RGB(0,0,255), RGB(0,0,255)); } else { //未按下按钮 pDC->Draw3dRect(rect,RGB(255,0,0),RGB(255,0,0)); } //字体颜色 pDC->SetTextColor(RGB(0,0,255)); //加下画线(也可以用其他字体) if (fUnderline.GetSafeHandle() == NULL) { CFont * pFont = GetFont(); ASSERT(pFont); LOGFONT lf; pFont->GetLogFont(&lf); lf.lfUnderline = TRUE; fUnderline.CreateFontIndirect(&lf); } pOldFont = pDC->SelectObject(&fUnderline); } else { pDC->SetTextColor(RGB(255,123,30)); pDC->Draw3dRect(rect,RGB(255,0,0),RGB(255,0,0)); } pDC->DrawText(strText, rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); if (pOldFont) pDC->SelectObject(pOldFont); } }
LRESULT SliderBoth::WindowProc(UINT m,WPARAM w,LPARAM l) { if((m==WM_USER)||(m==WM_USER+1)||(m==WM_USER+100)) { CRect rcMe; GetClientRect(&rcMe); if(b_Horz) { const int iXL=MARGIN_ME; const int iXR=rcMe.right-MARGIN_ME; double dbOne=(iXR-iXL)*1.0/(pos.iMax-pos.iMin); if(m==WM_USER) { int iMove=(int)(((int)w)/dbOne); int iL,iR; GetPosition(iL,iR); if(l) iL+=iMove; else iR+=iMove; P_SetPosition(iL,iR,l,!l); // CClientDC dc(this); // // int iV=209; // // COLORREF clrBk=RGB(iV,iV,iV);//LSC 原屏蔽此句 // COLORREF clrBk=RGB(0,0,255); //LSC 修改整个slider控件的背景色 // dc.FillRect(&rcMe,&CBrush(clrBk));//LSC原代码执行此句 } else if(m==WM_USER+1) { int iL,iR; GetPosition(iL,iR); if((pos.iOldL!=iL)||(pos.iOldR!=iR)) { pos.iOldL=iL; pos.iOldR=iR; //post event GetParent()->PostMessage(WM_COMMAND,i_ID); SetBlockColor(); #if 0 CClientDC dc(this); CRect rc; GetClientRect(&rc); int iNumTic=(pos.iMax-pos.iMin)/pos.iTick; const int iL=MARGIN_SLIDE; const int iR=rc.right-MARGIN_SLIDE; const double dbStep=(iR-iL)*1.0/iNumTic; double db=iL; CBrush brush; //brush.CreateSolidBrush(RGB(200,100,255)); brush.CreateSolidBrush(RGB(165,196,211)); CBrush * pOldBrush= dc.SelectObject (&brush); double lval = pos.iL*dbStep; double rval = pos.iR*dbStep; dc.Rectangle((int)lval+MARGIN_SLIDE*2,rc.top+1,(int)rval,rc.bottom-MARGIN_SLIDE*2); dc.SelectObject (pOldBrush); brush.DeleteObject(); #endif } } if(m==WM_USER+100) { b_Initialized=1; //P_SetPosition(pos.iMin,pos.iMax,1,1); P_SetPosition(m_min,m_max,1,1);//注意,后两个参数是1,2,3...的1,不是l,j,k的l RedrawWindow(); } } else { const int iXL=rcMe.bottom-MARGIN_ME; const int iXR=rcMe.top+MARGIN_ME; double dbOne=(iXL-iXR)*1.0/(pos.iMax-pos.iMin); if(m==WM_USER) { int iMove=(int)(((int)w)/dbOne); int iL,iR; GetPosition(iL,iR); if(l) iL-=iMove; else iR-=iMove; P_SetPosition(iL,iR,l,!l); } else if(m==WM_USER+1) { int iL,iR; GetPosition(iL,iR); if((pos.iOldL!=iL)||(pos.iOldR!=iR)) { pos.iOldL=iL; pos.iOldR=iR; //post event; GetParent()->PostMessage(WM_COMMAND,i_ID); //wm.DT(200,i_ID); } } else if(m==WM_USER+100) { b_Initialized=1; P_SetPosition(pos.iMin,pos.iMax,1,1); RedrawWindow(); } } } return CWnd::WindowProc(m,w,l); }
void CChooseClrAnimList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC *pDC; pDC = CDC::FromHandle( lpDrawItemStruct->hDC ); //dc.Attach(lpDrawItemStruct->hDC); CRect rcDraw = lpDrawItemStruct->rcItem; if (lpDrawItemStruct->itemID >= 0) { if (lpDrawItemStruct->itemAction & ODA_SELECT) { CBrush brRect; if (lpDrawItemStruct->itemState & ODS_SELECTED) { // Draw selection brRect.CreateSolidBrush( RGB(0, 0, 128)); } else { brRect.CreateSolidBrush( RGB(255, 255, 255) ); } pDC->FillRect( rcDraw, &brRect ); } CString sTxt; GetText(lpDrawItemStruct->itemID, sTxt); CK_FAVOURITE *pFavourite = (CK_FAVOURITE *)GetItemData(lpDrawItemStruct->itemID); CSize szText = pDC->GetTextExtent( sTxt ); pDC->TextOut(rcDraw.left + 2, rcDraw.top + (rcDraw.Height() / 2) - (szText.cy / 2), sTxt); // Draw the keyframes CRect rcFrame; rcFrame.left = rcDraw.left + szText.cx + 10; rcFrame.top = rcDraw.top + 2; rcFrame.right = rcDraw.right; rcFrame.bottom = rcDraw.bottom - 2; CBrush brBlack(RGB(0, 0, 0)); pDC->FrameRect(&rcFrame, &brBlack); // Fill in the frame with the colour keys rcFrame.left ++; rcFrame.top ++; rcFrame.bottom --; rcFrame.right --; m_posColRatio = 1.0f / rcFrame.Width(); for (int i = 0; i < rcFrame.Width(); i ++) { int r, g, b; PosToCol(pFavourite, i, &r, &g, &b); CBrush brCol(RGB(r, g, b)); pDC->FillRect(CRect(i + rcFrame.left, rcFrame.top, rcFrame.left + i + 1, rcFrame.Height() + rcFrame.top), &brCol); } } }
void CGuiPanelWnd::DrawGripper(CDC* pDC, CRect* rc) { CRect gripper = rc; gripper.top =3; gripper.left+=4; gripper.right-=3; if(m_StyleDisplay == GUISTYLE_XP) gripper.bottom =gripper.top +nGapGripper-3; if(m_StyleDisplay == GUISTYLE_2003) gripper.bottom =gripper.top +nGapGripper+1; //si la ventana esta activa pintamos el caption o el area del titulo de color azul if(!m_bActive) { if (m_StyleDisplay == GUISTYLE_2003) { CGradient M(CSize(gripper.Width(),gripper.Height())); M.PrepareVertical(pDC,m_StyleDisplay); M.Draw(pDC,4,0,0,0,gripper.Width(),gripper.Height(),SRCCOPY); } if (m_StyleDisplay == GUISTYLE_XP) { CPen cp(PS_SOLID,1,::GetSysColor(COLOR_BTNSHADOW)); CPen* cpold=pDC->SelectObject(&cp); //linea superior pDC->MoveTo(gripper.left+1,gripper.top); pDC->LineTo(gripper.right,gripper.top); //linea izquierda pDC->MoveTo(gripper.left,gripper.top+1); pDC->LineTo(gripper.left,gripper.bottom); //linea inferior pDC->MoveTo(gripper.left+1,gripper.bottom); pDC->LineTo(gripper.right,gripper.bottom); //linea derecha pDC->MoveTo(gripper.right,gripper.top+1); pDC->LineTo(gripper.right,gripper.bottom); pDC->SelectObject(cpold); } } else { if (m_StyleDisplay == GUISTYLE_XP) { CBrush cb; cb.CreateSolidBrush(::GetSysColor(COLOR_ACTIVECAPTION));//GuiDrawLayer::GetRGBCaptionXP()); pDC->FillRect(gripper,&cb); cb.DeleteObject(); } if (m_StyleDisplay == GUISTYLE_2003) { CGradient M(CSize(gripper.Width(),gripper.Height())); M.PrepareCaption(pDC,m_StyleDisplay); M.Draw(pDC,4,0,0,0,gripper.Width(),gripper.Height(),SRCCOPY); } } if(m_StyleDisplay == GUISTYLE_2003) //no es XP { CRect rcWin=gripper; //rcWin.left= gripper.left; rcWin.top+=5; rcWin.left+=5; rcWin.right=rcWin.left+2; rcWin.bottom-=4; CRect rcBlack; for (int i=0; i < rcWin.Height(); i+=4) { CRect rcWindow; CBrush cb; cb.CreateSolidBrush(::GetSysColor(COLOR_BTNHIGHLIGHT)); rcWindow=rcWin; rcWindow.top=rcWin.top+i; rcWindow.bottom=rcWindow.top+2; pDC->FillRect(rcWindow,&cb); rcBlack=rcWindow; rcBlack.left-=1; rcBlack.top=(rcWin.top+i)-1; rcBlack.bottom=rcBlack.top+2; rcBlack.right=rcBlack.left+2; cb.DeleteObject(); cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Theme)); pDC->FillRect(rcBlack,&cb); } } gripper.DeflateRect(1, 1); CString m_caption; GetWindowText(m_caption); CFont m_cfont; m_cfont.CreateFont(-11,0,0,0,400,0,0,0,0,1,2,1,34,_T("Verdana")); CFont* m_fontOld=pDC->SelectObject(&m_cfont); int nMode = pDC->SetBkMode(TRANSPARENT); CSize SizeCad=pDC->GetTextExtent(m_caption); CRect rCText=gripper; rCText.top=6; rCText.bottom =rCText.top+14; int cont=SizeCad.cx; while(cont > 1 && gripper.Width() > 0) { CSize coor=pDC->GetTextExtent(m_caption,m_caption.GetLength()); if(coor.cx > gripper.Width()-10) { m_caption=m_caption.Left(m_caption.GetLength()-1); } else break; cont--; } if (gripper.Width() > 0 ) if (!m_bActive) pDC->TextOut(rCText.left+8,rCText.top,m_caption); else { if (!GuiDrawLayer::m_Theme) pDC->SetTextColor(RGB(255,255,255)); pDC->TextOut(rCText.left+8,rCText.top,m_caption); } //CRect gripper; //------------------------------------------------ GetWindowRect( gripper ); ScreenToClient( gripper ); gripper.OffsetRect( -gripper.left, -gripper.top ); gripper.left=gripper.right-20; gripper.right-=7; gripper.top+=6; gripper.bottom=gripper.top+13; m_rcCloseBtn=gripper; //m_rcCloseBtn.left-=4; //ClientToScreen(m_rcCloseBtn); m_CloseBtn.Paint(pDC,m_stateBtn,gripper,NULL_BRUSH); //------------------------------------------------ pDC->SetBkMode(nMode); pDC->SelectObject(m_fontOld); }
int CXTPExcelTabCtrlTheme::DrawTab(CDC* pDC, CXTPExcelTabCtrl* pTabCtrl, const CPoint& pt, bool bSelected, CXTPTcbItem* pTcbItem) { if (pDC == NULL || pTcbItem == NULL || !::IsWindow(pTabCtrl->GetSafeHwnd())) return -1; // Saves the current state of the device context, we will // restore the state when the method looses scope. This will // simplify selecting objects. const int nSavedDC = pDC->SaveDC(); const int iHeight = m_cy; const int iBase = iHeight / 2; const int iWidth = iHeight + iHeight / 2; // 2 bases + 2 margins const bool bBottom = (pTabCtrl->GetTabStyle() & FTS_XTP_BOTTOM) == FTS_XTP_BOTTOM; pDC->SelectObject(pTabCtrl->GetTabFont(bSelected)); const CSize szText = pDC->GetTextExtent(pTcbItem->szTabLabel); CRect rcText; rcText.left = pt.x + iBase + iBase / 2; rcText.top = pt.y + ((iHeight - szText.cy)/2)-1; rcText.right = rcText.left + szText.cx; rcText.bottom = rcText.top + szText.cy; COLORREF crBack = GetTabBackColor(pTcbItem); COLORREF crFore = GetTabTextColor(pTcbItem); if (bSelected) { crBack = GetSelTabBackColor(pTcbItem); crFore = GetSelTabTextColor(pTcbItem); } CPen penBack(PS_SOLID, 1, crBack); CPen penWindow(PS_SOLID, 1, m_clr3DHilight); CPen penShadow(PS_SOLID, 1, m_clr3DShadow); CPen penOutline(PS_SOLID, 1, m_clrBtnText); CBrush brush; brush.CreateSolidBrush(crBack); POINT points[] = { { pt.x, pt.y + iHeight - 1 }, { pt.x + iBase - 1, pt.y }, { pt.x + szText.cx + iWidth - iBase - 1, pt.y }, { pt.x + szText.cx + iWidth - 1, pt.y + iHeight - 1 } }; // swap vertical coordinates if (bBottom) { points[0].y = points[1].y; points[2].y = points[3].y; points[1].y = points[2].y; points[3].y = points[0].y; } pDC->SelectObject(&penOutline); pDC->SetBkColor(crBack); pDC->SelectObject(&brush); pDC->Polygon(points, 4); pDC->SetTextColor(crFore); pDC->DrawText(pTcbItem->szTabLabel, rcText, DT_CENTER); pDC->SelectObject(&penShadow); if (bSelected) { pDC->MoveTo(pt.x + iBase, points[1].y); pDC->LineTo(pt.x + iBase * 2 + szText.cx - 1, points[1].y); pDC->SelectObject(&penBack); pDC->MoveTo(pt.x + 1, points[0].y); pDC->LineTo(pt.x + szText.cx + iWidth - 1, points[0].y); } else { // highlight line on left pDC->SelectObject(&penWindow); pDC->MoveTo(pt.x + 1, points[0].y); pDC->LineTo(pt.x + 1 + iBase, points[0].y + iHeight); // shadow line on top pDC->SelectObject(&penShadow); pDC->MoveTo(pt.x, points[0].y); pDC->LineTo(pt.x + szText.cx + iWidth, points[0].y); // shadow line on bottom pDC->MoveTo(pt.x + iBase, points[1].y); pDC->LineTo(pt.x + szText.cx + iHeight - 1, points[1].y); } // Cleanup. pDC->RestoreDC(nSavedDC); brush.DeleteObject(); return szText.cx + iWidth; }
void COXItemTipWnd::Display(CRect& rect, CString sText, int nOffset, int nAlignment, CFont* pFont, COLORREF clrText, COLORREF clrBackground) { ASSERT_VALID(m_pParentWnd); ASSERT(::IsWindow(m_pParentWnd->GetSafeHwnd())); ASSERT(::IsWindow(m_hWnd)); CWnd* pWnd=GetActiveWindow(); if(pWnd==NULL || (!IsDescendant(pWnd,m_pParentWnd) && (m_pParentWnd->GetExStyle()&WS_EX_TOPMOST)!=WS_EX_TOPMOST)) { return; } CClientDC dc(this); // device context for drawing CFont* pOldFont=NULL; if(pFont) { pOldFont=dc.SelectObject(pFont); } COLORREF clrOld=ID_OX_COLOR_NONE; if(clrText!=ID_OX_COLOR_NONE) { clrOld=dc.SetTextColor(clrText); } int nOldBkMode=dc.SetBkMode(TRANSPARENT); CRect rectDraw=rect; dc.DrawText(sText,&rectDraw,DT_CALCRECT|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX); rectDraw.right+=2*nOffset; if(rectDraw.Width()>rect.Width()) { rect.right=rect.left+rectDraw.Width(); } if(rectDraw.Height()>rect.Height()) { rect.bottom=rect.top+rectDraw.Height(); } // it's show time! m_pParentWnd->ClientToScreen(&rect); // adjust rectangle to fit the screen // CWnd* pParentWnd=m_pParentWnd; BOOL bTopMostParent=FALSE; while(pParentWnd!=NULL) { if(pParentWnd->GetExStyle() & WS_EX_TOPMOST) { bTopMostParent=TRUE; break; } pParentWnd=pParentWnd->GetParent(); } DWORD dwMessagePos=::GetMessagePos(); CPoint point(GET_X_LPARAM(dwMessagePos),GET_Y_LPARAM(dwMessagePos)); CRect rectDisplay=GetMonitorRectFromPoint(point,!bTopMostParent); if(rect.right>rectDisplay.right) { rect.OffsetRect(rectDisplay.right-rect.right,0); } if(rect.left<rectDisplay.left) { rect.OffsetRect(rectDisplay.left-rect.left,0); } // ///////////////////////////////////////////////////////////// if(bTopMostParent) { SetWindowPos(&wndTopMost,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOACTIVATE); } else { SetWindowPos(NULL,rect.left,rect.top,rect.Width(), rect.Height(),SWP_NOZORDER|SWP_NOACTIVATE); } ShowWindow(SW_SHOWNA); if(clrBackground!=ID_OX_COLOR_NONE) { CBrush brush; brush.CreateSolidBrush(clrBackground); CRect rectClient; GetClientRect(rectClient); dc.FillRect(&rectClient,&brush); } else { SendMessage(WM_ERASEBKGND,(WPARAM)(HDC)dc); } rectDraw=rect; rectDraw.DeflateRect(nOffset,0); ScreenToClient(&rectDraw); dc.DrawText(sText,&rectDraw,nAlignment|DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX); if(pOldFont) { dc.SelectObject(pOldFont); } if(clrOld!=ID_OX_COLOR_NONE) { dc.SetTextColor(clrOld); } dc.SetBkMode(nOldBkMode); m_nTimerID=SetTimer(ID_OXITEMTIP_TIMER,ID_OXITEMTIP_TIMER_DELAY,NULL); if(m_nTimerID==0) { TRACE(_T("COXItemTipWnd::Display: failed to set timer to check item tip state\n")); } }
void CLoungeDlg::OnPaint() { CRect r2; GetUpdateRect(&r2); ClientToScreen(&r2); if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); if (pImage_) { // // Paint the background graphics // CRect r; GetClientRect(&r); pImage_->drawImage(dc, r); // Need to fill the tab control tab's backround // with button color because it won't paint it if (tabCtrl_.GetSafeHwnd()) { CRect r; tabCtrl_.GetItemRect(0, &r); CRect rectTab; tabCtrl_.GetWindowRect(&rectTab); ScreenToClient(&rectTab); rectTab.bottom = rectTab.top + tabCtrl_.GetRowCount() * r.Height() + 5; dc.FillSolidRect(&rectTab, GetSysColor(COLOR_BTNFACE)); ClientToScreen(&rectTab); tabCtrl_.ScreenToClient(&rectTab); tabCtrl_.RedrawWindow(&rectTab); } if (Base::IsMaximized(this)) { // fill uncovered areas CBrush br; COLORREF c = RGB(196, 152, 96); br.CreateSolidBrush(c); CRect r; GetClientRect(&r); CSize s = pImage_->getSize(); CRect r2(r); r2.left = r.left + s.cx; dc.FillRect(&r2, &br); r2.right = r2.left; r2.left = r.left; r2.top = r.top + s.cy; dc.FillRect(&r2, &br); } } int oldMode = dc.SetBkMode(TRANSPARENT); // // Paint the alpha bump rectangle and the text // BYTE red = 70, green = 32, blue = 20, alpha = 100; COLORREF light = RGB(224, 159, 95); COLORREF dark = RGB(max(0, 0.4f * float(red)), max(0, 0.4f * float(green)), max(0, 0.4f * float(blue))); CRect r; GetDlgItem(IDC_LOUNGE_GROUP1)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawRectAlpha(&dc, r, red, green, blue, alpha); Base::DrawBumpRect(&dc, r, dark, light); CFont* pOldFont = dc.SelectObject(&font_); GetDlgItem(IDC_PROMPT_USERNAME)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, "Username", r.TopLeft(), RGB(255, 255, 255), RGB(0, 0, 0)); GetDlgItem(IDC_PROMPT_STATUS)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, "Status", r.TopLeft(), RGB(255, 255, 255), RGB(0, 0, 0)); GetDlgItem(IDC_PROMPT_NUMTABLES)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, "# Tables", r.TopLeft(), RGB(255, 255, 255), RGB(0, 0, 0)); GetDlgItem(IDC_PROMPT_NUMPLAYERS)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, "# Players", r.TopLeft(), RGB(255, 255, 255), RGB(0, 0, 0)); GetDlgItem(IDC_LD_RADIO1)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, g_szViewByWaitingLists, CPoint(r.right + 2, r.top), RGB(255, 255, 255), RGB(0, 0, 0)); GetDlgItem(IDC_LD_RADIO2)->GetWindowRect(&r); ScreenToClient(&r); Base::DrawBumpText(&dc, g_szViewByTables, CPoint(r.right + 2, r.top), RGB(255, 255, 255), RGB(0, 0, 0)); dc.SetBkMode(oldMode); dc.SelectObject(pOldFont); // // Update the list control if needed // listCtrl_.GetWindowRect(&r); if (r2.IntersectRect(&r, &r2)) { listCtrl_.Invalidate(); } // // Paint the radio buttons // CPoint ofs(0, 2); if (viewByWaitingLists()) { radioBtnOn_.TransBlt(&dc, rectRadio1_.TopLeft() + ofs); radioBtnOff_.TransBlt(&dc, rectRadio2_.TopLeft() + ofs); } else { radioBtnOn_.TransBlt(&dc, rectRadio2_.TopLeft() + ofs); radioBtnOff_.TransBlt(&dc, rectRadio1_.TopLeft() + ofs); } } }
// Draw the tiles // void CTileCastleFlag::Draw( CDC* pDC, int x, int y, int x2, int x3, int y2, int y3, int y4, int DrawingLevel) { // Compute polyline around tiles POINT Points1[4]; int NbPoint1 = 4; int TilePos = 0; double LowColor = GetLowColor( DrawingLevel ); Points1[0].x=x+x2; Points1[0].y=y-y2; Points1[1].x=x+x3; Points1[1].y=y; Points1[2].x=(int) (x+x3-x2/4.0); Points1[2].y=(int) (y+y2/4.0); Points1[3].x=x+x2; Points1[3].y=(int) (y-y2/2.0); double cosa; double sina; switch( m_CurrentRotation ) { case 0: break; case 1: cosa = cos(60/180.0*PI); sina = sin(60/180.0*PI); break; case 2: cosa = cos(120/180.0*PI); sina = sin(120/180.0*PI); break; case 3: cosa = cos(180/180.0*PI); sina = sin(180/180.0*PI); break; case 4: cosa = cos(240/180.0*PI); sina = sin(240/180.0*PI); break; case 5: cosa = cos(300/180.0*PI); sina = sin(300/180.0*PI); break; } if( m_CurrentRotation!=0 ) { for( int i=0; i<NbPoint1; i++ ) { double x1,y1; x1 = cosa*(Points1[i].x-x-x2)-sina*(Points1[i].y-y-(y3-y2)/2.0); y1 = sina*(Points1[i].x-x-x2)+cosa*(Points1[i].y-y-(y3-y2)/2.0); Points1[i].x = (int) (x+x2+x1); Points1[i].y = (int) (y+(y3-y2)/2.0+y1); } } CPen Pen; Pen.CreatePen(PS_NULL,0,RGB(0,0,0)); CPen* pOldPen = pDC->SelectObject( &Pen ); CBrush Brush; if( m_IsSelected ) Brush.CreateSolidBrush( RGB(255,255*LowColor,255*LowColor) ); else Brush.CreateSolidBrush( RGB(min(255,GetRValue(m_TileColor)+(255-GetRValue(m_TileColor))*LowColor),min(255,GetGValue(m_TileColor)+(255-GetGValue(m_TileColor))*LowColor),min(255,GetBValue(m_TileColor)+(255-GetBValue(m_TileColor))*LowColor)) ); CBrush* pOldBrush = pDC->SelectObject( &Brush ); pDC->Polygon( Points1, NbPoint1 ); // Draw points CBrush BlackBrush; BlackBrush.CreateSolidBrush( RGB(min(255,255*LowColor),min(255,255*LowColor),min(255,255*LowColor)) ); pDC->SelectObject( &BlackBrush ); double xe1 = (Points1[3].x+Points1[0].x)*.5; double ye1 = (Points1[3].y+Points1[0].y)*.5; double xe2 = (Points1[2].x+Points1[1].x)*.5; double ye2 = (Points1[2].y+Points1[1].y)*.5; int xe3 = (int) ((xe1+xe2)*.5); int ye3 = (int) ((ye1+ye2)*.5); int diameter = (int) (x2/10.0); pDC->Ellipse( xe3-diameter, ye3-diameter, xe3+diameter, ye3+diameter ); pDC->SelectObject( pOldBrush ); pDC->SelectObject( pOldPen ); DrawExtend( pDC, x, y, x2, x3, y2, y3, y4, DrawingLevel); }
void CMyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { int nItem = lpDrawItemStruct->itemID, nOffset; CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rcItem(lpDrawItemStruct->rcItem), rcHighlight; CRect rcBounds, rcLabel, rcIcon, rcSub, rcColumn; BOOL bHighlight; CString strLabel; CImageList* pImageList; // DC 상태 저장 int nSavedDC = pDC->SaveDC(); UINT nJustify; CBrush brush; LV_ITEM lvi; lvi.mask = LVIF_IMAGE | LVIF_STATE; lvi.iItem = nItem; lvi.iSubItem = 0; lvi.stateMask = 0xFFFF; GetItem(&lvi); // 아이템의 선택여부 조사 bHighlight =((lvi.state & LVIS_DROPHILITED) || ((lvi.state & LVIS_SELECTED) && ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS)))); // 그릴 영역을 구함 GetItemRect(nItem, rcBounds, LVIR_BOUNDS); GetItemRect(nItem, rcLabel, LVIR_LABEL); GetItemRect(nItem, rcIcon, LVIR_ICON); rcColumn = rcBounds; strLabel = GetItemText(nItem, 0); nOffset = (pDC->GetTextExtent(_T(" "), 1).cx) << 1; rcHighlight = rcBounds; rcHighlight.left = rcLabel.left; // Background를 그린다 pDC->SetBkMode(TRANSPARENT); if(bHighlight) { brush.CreateSolidBrush(m_colorBackHighlight); pDC->SetTextColor(m_colorTextHighlight); pDC->FillRect(rcHighlight, &brush); } else { brush.CreateSolidBrush(nItem % 2 ? m_colorBackOdd : m_colorBackEven); pDC->FillRect(rcBounds, &brush); } if(brush.m_hObject) brush.DeleteObject(); rcColumn.right = rcColumn.left + GetColumnWidth(0); // State Icon을 그린다 if(lvi.state & LVIS_STATEIMAGEMASK) { int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1; pImageList = GetImageList(LVSIL_STATE); if(pImageList) { pImageList->Draw(pDC, nImage, CPoint(rcColumn.left, rcColumn.top), ILD_TRANSPARENT); } }
void COptionTreeItemColor::DrawControl(CDC *pDC, const RECT &rcRect) { // Declare variables HGDIOBJ hOld; HGDIOBJ hOldBrush; COLORREF crOld; int nOldBack; CRect rcText, rcColor, rcClient; CString strText; CBrush bBrush; COLORREF crOldBack; // Get window rect GetClientRect(rcClient); // Select font hOld = pDC->SelectObject(m_otOption->GetNormalFont()); // Create bush bBrush.CreateSolidBrush(m_crColor); // Set text color if (IsReadOnly() == TRUE || m_otOption->IsWindowEnabled() == FALSE) { crOld = pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); } else { crOld = pDC->SetTextColor(GetTextColor()); } // Set background color crOldBack = pDC->SetBkColor(GetBackgroundColor()); // Set background mode nOldBack = pDC->SetBkMode(TRANSPARENT); // Select brush hOldBrush = pDC->SelectObject(GetSysColorBrush(COLOR_BTNSHADOW)); // Get color rectangle rcColor.left = rcRect.left + 1; rcColor.right = rcColor.left + (long) OT_COLOR_SIZE; rcColor.top = rcRect.top + OT_SPACE - 2; rcColor.bottom = rcColor.top + (long) OT_COLOR_SIZE; // Draw color border rcColor.InflateRect(1, 1, 1, 1); pDC->PatBlt(rcColor.left, rcColor.top, rcColor.Width(), rcColor.Height(), PATCOPY); // Draw color rcColor.DeflateRect(1, 1, 1, 1); pDC->FillRect(rcColor, &bBrush); // Get text rectangle rcText.left = rcColor.right + OT_SPACE; rcText.right = rcRect.right; rcText.top = rcRect.top; rcText.bottom = rcRect.bottom; // Get text if (GetOption(OT_COLOR_SHOWHEX) == TRUE) { strText.Format(_T("#%.6X"), m_crColor); } else { strText.Format(_T("RGB (%d, %d, %d)"), GetRValue(m_crColor), GetGValue(m_crColor), GetBValue(m_crColor)); } // Draw text pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER); pDC->DrawText(strText, rcText, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT); // Delete brush if (bBrush.GetSafeHandle() != NULL) { bBrush.DeleteObject(); } // Restore GDI ojects pDC->SelectObject(hOldBrush); pDC->SelectObject(hOld); pDC->SetTextColor(crOld); pDC->SetBkMode(nOldBack); pDC->SetBkColor(crOldBack); }
BOOL COutLook::OnPaint(HDC hDC) { CPaintDC dc(GetSafeHwnd()); CRect rect,rcClient; GetClientRect(&rect); CRect rcMsg; int iy=0; int m_iNumBotton= m_ArrayButtons.GetSize(); int iMitad= rect.Width()/2; iMitad-=(m_sizeImage.cx/2); iMitad--; int nMode; rcClient=rect; CBrush cbr; cbr.CreateSolidBrush(CDrawLayer::GetRGBColorFace()); CGDI MemDC; CBitmap m_BitmapMemDC; MemDC.CreateCompatibleDC(dc.m_hDC); m_BitmapMemDC.CreateCompatibleBitmap(dc.m_hDC, rect.Width(),rect.Height()); CBitmap m_bitmapOld=MemDC.SelectObject(&m_BitmapMemDC); MemDC.FillRect(&rect,&cbr); nMode =MemDC.SetBkMode(TRANSPARENT); CFont cfont(MemDC.SelectObject((HFONT)GetStockObject(DEFAULT_GUI_FONT))); for( int iCont=0; iCont< m_iNumBotton;iCont++) { CItems* cit=(CItems*)m_ArrayButtons[iCont]; CRect rcWin; cit->m_bt.GetWindowRect(rcWin); ScreenToClient(rcWin); rcMsg=rcWin; rcMsg.top=rcWin.bottom+2; rcMsg.bottom=rcMsg.top+16; rcMsg.left=rect.left; rcMsg.right=rect.right; if (m_TypeOutLook) MemDC.DrawText(cit->m_szMessage,rcMsg,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } MemDC.SetBkMode(nMode); MemDC.SelectObject(cfont.GetFont()); if (m_iDrawFrameUp==TRUE) { m_rectArrowUp.top=5; m_rectArrowUp.bottom=m_rectArrowUp.top+16; m_rectArrowUp.right=rect.right-5; m_rectArrowUp.left=m_rectArrowUp.right-16; MemDC.DrawFrameControl(m_rectArrowUp,DFC_SCROLL,DFCS_SCROLLUP); } if (m_iDrawFrameDown==TRUE) { m_rectArrowDown.bottom=rect.bottom-5; m_rectArrowDown.top=m_rectArrowDown.bottom-16; m_rectArrowDown.right=rect.right-5; m_rectArrowDown.left=m_rectArrowDown.right-16; MemDC.DrawFrameControl(m_rectArrowDown,DFC_SCROLL,DFCS_SCROLLDOWN); } dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),MemDC.m_hDC, rcClient.left,rcClient.top,SRCCOPY); MemDC.SelectObject(&m_bitmapOld); m_BitmapMemDC.DeleteObject(); MemDC.DeleteDC(); return TRUE; }