void CZoominTool::OnLButtonUp(_CVIEW* pView, UINT nFlags, CPoint& point) { CDC* pDC = NULL; pDC = pView->m_pDC; if (pDC == NULL) return; CRect newRect(c_PtDown,point); CPen Pen; if (!Pen.CreatePen(PS_SOLID, 1, RGB(0,0,0))) return; CPen *pOldPen = pDC->SelectObject(&Pen); int oldDrawMode = pDC->SetROP2(R2_NOT); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(newRect); pDC->SetROP2(oldDrawMode); pDC->SelectObject(pOldPen); Pen.DeleteObject(); int cx = abs(point.x - c_PtDown.x); int cy = abs(point.y - c_PtDown.y); if (cx<5 && cy<5) { pView->m_Graphics.ZoomAtPoint(&c_PtDown,1.2); pView->Refresh(); } else { pView->m_Graphics.ZoomInAtExtent(&c_PtDown,&point); pView->Refresh(); } CDrawTool::OnLButtonUp(pView, nFlags, point); }
void CZoominTool::OnMouseMove(_CVIEW* pView, UINT nFlags, CPoint& point) { ::SetCursor(AfxGetApp()->LoadCursor(IDC_ZOOMIN)); CDC* pDC = NULL; pDC = pView->GetDC(); if (pDC == NULL) return; if (!c_bDown) { DeleteDC(pDC->m_hDC); return; } CRect oldRect(c_PtDown,c_PtOld); CRect newRect(c_PtDown,point); //CRect TrackRect; // TrackRect.SetRect(m_StartPoint,point); CPen Pen; if (!Pen.CreatePen(PS_SOLID, 1, RGB(0,0,0))) return; CPen *pOldPen = pDC->SelectObject(&Pen); //int oldDrawMode = m_pDC->SetROP2(R2_XORPEN); int oldDrawMode = pDC->SetROP2(R2_NOT); pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(oldRect); pDC->Rectangle(newRect); pDC->SetROP2(oldDrawMode); pDC->SelectObject(pOldPen); Pen.DeleteObject(); DeleteDC(pDC->m_hDC); CDrawTool::OnMouseMove(pView, nFlags, point); }
void CLeftPanelDlgBar::Mark(CDC *pDC, CRect r, bool bErase) { m_rcCurMark = r; CPen pen (PS_SOLID, 1, bErase ? GetSysColor (COLOR_3DFACE) : RGB (0x6B, 0x8B, 0xBD)); CPen* pOldPen = pDC->SelectObject (&pen); CBrush* pOldBrush = (CBrush*) pDC->SelectStockObject (HOLLOW_BRUSH); // adjust marker rectangle r.left--; r.top--; r.right--; r.bottom += 3; // draw pDC->Rectangle (&r); // draw shade CPen penShadow (PS_GEOMETRIC | PS_ENDCAP_SQUARE, 2, bErase ? GetSysColor (COLOR_3DFACE) : RGB (0x51, 0x70, 0xA7)); pDC->SelectObject (&penShadow); pDC->MoveTo (r.right + 1, r.top + 1); POINT pt[2] = {r.right + 1, r.bottom, r.left + 1, r.bottom}; pDC->PolylineTo (pt, 2); // clean up pDC->SelectObject (pOldPen); pen.DeleteObject (); penShadow.DeleteObject (); pDC->SelectObject (pOldBrush); }
void CHSScrollBar::DrawBorder( CDC* pDC ) { CPen Pen; Pen.CreatePenIndirect(&m_logpen.GetPen(HsLOGPEN::hor)); CPen* pOldPen; pOldPen = pDC->SelectObject(&Pen); // 画上边框 pDC->MoveTo(m_rect.left, m_rect.top); pDC->LineTo(m_rect.right, m_rect.top); // 画下边框 pDC->MoveTo(m_rect.left, m_rect.bottom); pDC->LineTo(m_rect.right, m_rect.bottom); Pen.DeleteObject(); Pen.CreatePenIndirect(&m_logpen.GetPen(HsLOGPEN::ver)); pDC->SelectObject(&Pen); // 画左边框 pDC->MoveTo(m_rect.left, m_rect.top); pDC->LineTo(m_rect.left, m_rect.bottom); // 画右边框 pDC->MoveTo(m_rect.right, m_rect.top); pDC->LineTo(m_rect.right, m_rect.bottom); pDC->SelectObject(pOldPen); Pen.DeleteObject(); }
//******************************************************************************** void CHeaderView::DrawArrow(CGDI* pDC,CRect rc,BOOL bUp) { CPen cp; CPen cps; CPen cpw; cp.CreatePen(PS_SOLID,1, m_clrFace); cps.CreatePen(PS_SOLID,1, m_clrShadow); cpw.CreatePen(PS_SOLID,1, m_clrLight); HPEN hPen; (void)hPen; rc.left=rc.right-12; rc.right=rc.left+8; rc.bottom=rc.top+12; rc.top+=2; int m_mitad=rc.left+4; if (bUp == TRUE) { //linea izquierda hPen=pDC->SelectObject(&cps); pDC->MoveTo(rc.left,rc.bottom); pDC->LineTo(m_mitad,rc.top); //linea derecha pDC->SelectObject(&cpw); pDC->MoveTo(rc.right,rc.bottom); pDC->LineTo(m_mitad,rc.top); //linea de abajo pDC->MoveTo(rc.left,rc.bottom); pDC->LineTo(rc.right,rc.bottom); } else { rc.bottom=rc.top+12; rc.top+=4; //linea izquierda hPen=pDC->SelectObject(&cps); pDC->MoveTo(rc.left,rc.top); pDC->LineTo(m_mitad,rc.bottom); //linea superior pDC->MoveTo(rc.left,rc.top); pDC->LineTo(rc.right,rc.top); //linea derecha pDC->SelectObject(&cpw); pDC->MoveTo(rc.right,rc.top); pDC->LineTo(m_mitad,rc.bottom); } cp.DeleteObject(); cps.DeleteObject(); cpw.DeleteObject(); //pDC->SelectObject(pOld); }
/* 画棋子 */ void Chess::DrawChess(CDC *pDC) { CBrush *brush; COLORREF color; CPen pen; int a, b; a = x - SIZE / 2; b = y - SIZE / 2; /* 选择颜色 */ if (this->color == WHITE) /* 白色 */ { color = RGB(255, 255, 255); pen.CreatePen(PS_SOLID, 1, color); } else /* 黑色 */ { color = RGB(0, 0, 0); pen.CreatePen(PS_SOLID, 1, color); } brush = new CBrush(color); /* 笔的属性 */ pDC->SelectObject(brush); /* 使用这支笔 */ pDC->SelectObject(&pen); pDC->Ellipse(a, b, a + size, b + size); /* 画圆 */ brush->DeleteObject(); pen.DeleteObject(); }
void DlgPalette::DrawCell(CDC *pDC, long index) { CRect rect; if (!GetCellRect(index, rect)) return; CBrush brush; if (m_editalpha){ brush.CreateSolidBrush(RGB(m_pal[index].rgbReserved, m_pal[index].rgbReserved , m_pal[index].rgbReserved )); }else{ brush.CreateSolidBrush(RGB(m_pal[index].rgbRed , m_pal[index].rgbGreen , m_pal[index].rgbBlue )); } CPen pen; if (index==m_selected) pen.CreatePen(PS_SOLID, 2, ::GetSysColor(COLOR_3DDKSHADOW)); else pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell colour pDC->Rectangle(rect); // restore DC and cleanup pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); brush.DeleteObject(); pen.DeleteObject(); }
void CTEditCtrlWnd::OnPaint() { CPaintDC dc(this); CString strWindow, strCurreny; CRect rcClient; GetClientRect(rcClient); dc.FillSolidRect(rcClient, m_clrFace); dc.SetBkMode(TRANSPARENT); /*dc.Draw3dRect(rcClient, m_clrBottomRight, m_clrTopLeft);*/ CPen pen; pen.CreatePen(PS_SOLID, 1, RGB(200, 200, 200)); CPen* pOldPen = (CPen*)dc.SelectObject(&pen); dc.Rectangle(rcClient); dc.SelectObject(pOldPen); pen.DeleteObject(); rcClient.DeflateRect(2, 2, 2, 2); GetWindowText(strWindow); strCurreny = GetCurrencyText(strWindow); strCurreny = strWindow; CFont *pOldFont = dc.SelectObject(&m_fontDefault); dc.DrawText(strCurreny, rcClient, DT_VCENTER | DT_SINGLELINE | DT_RIGHT); dc.SelectObject(pOldFont); }
void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting CPen Pen; Pen.CreatePen(PS_SOLID, 1, RGB(0,0,255)); CPen *pOldPen; pOldPen = dc.SelectObject(&Pen); CBrush Brush; Brush.CreateSolidBrush(RGB(0,255,0)); CBrush *pOldBrush = dc.SelectObject(&Brush); { dc.MoveTo(0,0); dc.LineTo(100,100); dc.Rectangle(100,100,200,200); } dc.SelectObject(pOldPen); dc.SelectObject(pOldBrush); Brush.DeleteObject(); Pen.DeleteObject(); if(dibData == NULL) return; SetDIBitsToDevice(dc.m_hDC, 0, 0, imageWidth, imageHeight, 0, 0, 0, imageHeight, dstData, bitmapInfo, DIB_RGB_COLORS); }
void CGroup1::Draw9(CDC* pDC, CSize& ScreenSize, int CameraX, int CameraY, // position on camera long x, long y, // position on screen long lFactorX, long lFactorY, long CameraFactor, COLORREF Pix, COLORREF PrevPix, DWORD) { long Diff = Pix - PrevPix; long R = GetRValue(Diff); long G = GetGValue(Diff); long B = GetBValue(Diff); COLORREF CurrColor = SelectColor(R, G, B); long lastX = min(x+lFactorX, ScreenSize.cx); long lastY = min(y+lFactorY, ScreenSize.cy); CRect r(x, y, lastX, lastY); CBrush b(RGB(0,0,0)); CPen pen; pen.CreatePen(PS_SOLID, 1, CurrColor); CPen* pOld = pDC->SelectObject(&pen); CBrush* pOldB = pDC->SelectObject(&b); pDC->MoveTo(R*3,G); pDC->LineTo(CameraX*3, B*3); b.DeleteObject(); pen.DeleteObject(); pDC->SelectObject(pOld); pDC->SelectObject(pOldB); }
void CHeadCtrol::PaintDragLine(int pos, bool bOne ) //ÍÏקÏßÌõ { CDC* pDC = CWnd::FromHandle(m_hListWnd)->GetWindowDC(); int nRop = pDC->SetROP2(R2_NOTXORPEN); CRect lrect; CWnd::FromHandle(m_hListWnd)->GetClientRect( &lrect ); CPen pen; pen.CreatePen(0, 1, RGB(0, 0, 0)); CPen *pOP = pDC->SelectObject(&pen); if( posPre != -1 ) { pDC->MoveTo( posPre,0 ); pDC->LineTo( posPre,lrect.bottom ); } if( !bOne ) { pDC->MoveTo( pos,0 ); pDC->LineTo( pos,lrect.bottom ); } pDC->SetROP2(nRop); pDC->SelectObject(pOP); pen.DeleteObject(); ReleaseDC(pDC); posPre = pos; }
void QuoteTableCtrlGeneralSort::OnDraw(CDC* pDC) { CHSGridCtrl::OnDraw(pDC); CRect rect, itemrect, rccvlient; GetClientRect(rccvlient); ClientToScreen(rccvlient); GetClientRect(rect); itemrect = rect; if (GetRowCount() <=0) return; int rowheight = GetRowHeight(0); itemrect.bottom = rowheight-1; COLORREF bkcolor = GetBkColor(); COLORREF textcolor = RGB(155,155,155); if (m_iColorFontProt) textcolor = m_iColorFontProt->GetQuoteTabTextColor(); CFont* pFont; CFont* pOldFont; BOOL bCreat = FALSE; if (m_iFont) pFont = (CFont*)m_iFont->GetQuoteColHeadFont(); else { pFont = new CFont(); VERIFY(pFont->CreateFont(16,0, 0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("宋体"))); bCreat = TRUE; } pOldFont = pDC->SelectObject(pFont); pDC->SetBkColor( GetSysColor(COLOR_HIGHLIGHT) ); pDC->SetBkColor(bkcolor); pDC->SetTextColor(textcolor); pDC->SetBkColor(bkcolor); pDC->DrawText(m_pTableFlag->strTitle, &itemrect, DT_CENTER | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); pDC->SelectObject(pOldFont); if (bCreat) pFont->DeleteObject(); CPen hPen; hPen.CreatePen(PS_SOLID ,1,RGB(200,0,0)); CPen* hOldPen = pDC->SelectObject(&hPen); pDC->MoveTo(CPoint(itemrect.left,itemrect.bottom)); pDC->LineTo(CPoint(itemrect.right, itemrect.bottom)); pDC->SelectObject(hOldPen); hPen.DeleteObject(); }
//----- OnSizeParent() ------------------------------------------------------ void BCTabBarCtrl::OnNcPaint() { CRect rectCLient, rectNC; GetWindowRect(rectNC); rectNC.OffsetRect(-rectNC.left, -rectNC.top); CWindowDC dc(this); CPen pen; DWORD dwSysGray = GetSysColor(COLOR_BTNFACE); dc.DrawEdge(rectNC, EDGE_ETCHED, BF_TOP); rectNC.DeflateRect(0, 2, 0, 0); CBrush brush(dwSysGray); dc.FrameRect(rectNC, &brush); for(int iIndx = 0; iIndx < 2; iIndx++) { rectNC.DeflateRect(1, 1, 1, 1); dc.FrameRect(rectNC, &brush); } rectNC.DeflateRect(0, 1, 0, 2); pen.DeleteObject(); pen.CreatePen(PS_GEOMETRIC | PS_SOLID, 1, dwSysGray); dc.SelectObject(&pen); dc.MoveTo(rectNC.left, rectNC.top); dc.LineTo(rectNC.right, rectNC.top); }
////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CGraph::CGraph(CDC *hdc,int x1,int y1,int x2,int y2,int R,int G,int B,int W,int mX,int mY) { posX1 = x1; posY1 = y1; posX2 = x2; posY2 = y2; OldPoint.x = 0; OldPoint.y = 125; dc = hdc; ////////////////////////////////////////////////////////////////////////////////////////////////// //****************************** Создание виртуальных окон *************************************** memDC_static.CreateCompatibleDC(hdc); memBmp_static.CreateCompatibleBitmap(hdc,posX2 - posX1,posY2 - posY1); memDC_static.SelectObject(&memBmp_static); memDC_static.PatBlt(0,0,posX2 - posX1,posY2 - posY1,BLACKNESS); memDC_dynamic.CreateCompatibleDC(hdc); memBmp_dynamic.CreateCompatibleBitmap(hdc,posX2 - posX1,posY2 - posY1); memDC_dynamic.SelectObject(&memBmp_dynamic); memDC_dynamic.PatBlt(0,0,posX2 - posX1,posY2 - posY1,BLACKNESS); ////////////////////////////////////////////////////////////////////////////////////////////////// //************************************************************************************************ CPen TempPen; TempPen.CreatePen(PS_SOLID,1,RGB(80,80,50)); int StepX = (x2 - x1) / mX; for(int i = 0; i <= posX2; i+=StepX) { memDC_dynamic.SelectObject(&TempPen); memDC_dynamic.MoveTo(i,0); memDC_dynamic.LineTo(i,y2); } int StepY = (y2 - y1) / mY; for(int j = 0; j <= posX2; j+=StepY) { memDC_dynamic.SelectObject(&TempPen); memDC_dynamic.MoveTo(0,j); memDC_dynamic.LineTo(x2,j); } memDC_dynamic.SelectStockObject(NULL_PEN); TempPen.DeleteObject(); ////////////////////////////////////////////////////////////////////////////////////////////////// //************************************* Создание Pen ********************************************* Pen.CreatePen(PS_SOLID,W,RGB(R,G,B)); memDC_static.SelectObject(&Pen); }
void Point::drawcircle(CDC *pDC) { CPen *pe = new CPen(PS_SOLID,1,RGB(0,0,0)); CPen * oldpen = pDC->SelectObject(pe); pDC->Ellipse(x-AREA,y-AREA,x+AREA,y+AREA); pDC->SelectObject(oldpen); pe->DeleteObject(); }
void MFC_VIEWER::DrawCircle(int x,int y, int radius,int width,int r,int g,int b) { CPen pen; pen.CreatePen(PS_SOLID,width,RGB(r,g,b)); dcbmp.SelectObject(&pen); dcbmp.Ellipse(x-radius,y-radius,x+radius,y+radius); pen.DeleteObject(); }
void CSignalView::ReDrawmap(CDC *pDC) { if(pDC==NULL) return; double *pdata = m_SignalData.GetData(); double *pcolor = m_SignalColor.GetData(); size_t length = m_SignalData.GetDataSize(); int base = m_SignalRect.Height()/2; pDC->FillSolidRect(0,0,m_SignalRect.Width() ,m_SignalRect.Height(),RGB(255,255,255)); COLORREF precolor = (int)pcolor[0]; COLORREF curcolor = precolor; CPen drawpen; int prey = 0; if(pdata[0]<=0) { prey = m_MinValue==0?(pdata[0]*(-1.0)+base):(pdata[0]/m_MinValue*base+base); } else prey = m_MaxValue==0?(base-pdata[0]):(base-pdata[0]/m_MaxValue*base); drawpen.CreatePen(PS_SOLID , 1 , precolor); for (int i=1; i<length; i++) { if(precolor!=curcolor) { drawpen.DeleteObject(); drawpen.CreatePen(PS_SOLID ,1,curcolor); precolor = curcolor; } pDC->SelectObject(drawpen); int cury = 0; if(m_MaxValue==0&&m_MinValue==0) { cury = (int)(pdata[i]*(-1.0)+base); } else { cury = (pdata[i]-m_MinValue)*m_SignalRect.Height()/(m_MaxValue-m_MinValue)+base-m_MeanValue; } pDC->MoveTo(i-1,prey); pDC->LineTo(i,cury); prey = cury; curcolor = (int)pcolor[i]; } drawpen.DeleteObject(); }
void MFC_VIEWER::DrawLine(int x1,int y1,int x2,int y2,int width,int r,int g,int b) { CPen pen; pen.CreatePen(PS_SOLID,width,RGB(r,g,b)); dcbmp.SelectObject(&pen); dcbmp.MoveTo(x1,y1); dcbmp.LineTo(x2,y2); pen.DeleteObject(); }
void CColorButton::DrawLine(CDC *DC, CRect EndPoints, COLORREF color) { CPen newPen; newPen.CreatePen(PS_SOLID, 1, color); CPen *oldPen = DC->SelectObject(&newPen); DC->MoveTo(EndPoints.left, EndPoints.top); DC->LineTo(EndPoints.right, EndPoints.bottom); DC->SelectObject(oldPen); newPen.DeleteObject(); }
void CColorButton::DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color) { CPen newPen; newPen.CreatePen(PS_SOLID, 1, color); CPen *oldPen = DC->SelectObject(&newPen); DC->MoveTo(left, top); DC->LineTo(right, bottom); DC->SelectObject(oldPen); newPen.DeleteObject(); }
void CMoveTool::OnMouseMove(_CVIEW* pView, UINT nFlags, CPoint& point) { 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(pDoc->m_Graphics.m_GraphicsMode==Layout) SetCursor(AfxGetApp()->LoadCursor(IDC_DRAW_B)); else SetCursor(AfxGetApp()->LoadCursor(IDC_DRAW_W)); if(c_bSnap) { pDoc->m_Graphics.m_bSnapStatus=true; pDoc->m_Graphics.SnapHandle(pDC,point); } if(c_nDown!=1) { DeleteDC(pDC->m_hDC); return; } CPen Pen; if (!Pen.CreatePen(PS_DOT, 1, RGB(0,0,0))) return; CPen* pOldPen = pDC->SelectObject(&Pen); int oldDrawMode = pDC->SetROP2(R2_XORPEN); if(!c_bJustDraw) { pDC->MoveTo(c_PtDown); pDC->LineTo(c_PtOld); } pDC->MoveTo(c_PtDown); pDC->LineTo(point); CSize size1,size2; size1.cx =c_PtOld.x-c_PtDown.x; size1.cy =c_PtOld.y-c_PtDown.y; size2.cx =point.x-c_PtDown.x; size2.cy =point.y-c_PtDown.y; if(!c_bJustDraw) { pDoc->m_Graphics.MoveEntities(pDC,size1); } c_bJustDraw=false; pDoc->m_Graphics.MoveEntities(pDC,size2); pDC->SetROP2(oldDrawMode); pDC->SelectObject(pOldPen); Pen.DeleteObject(); DeleteDC(pDC->m_hDC); CDrawTool::OnMouseMove(pView, nFlags, point); }
//************************************************************************ void CHeaderView::BiselaBoton(CRect rcWin,CGDI* pDC) { CPen cp; CPen cps; CPen cpw; cp.CreatePen(PS_SOLID,1, m_clrFace); cps.CreatePen(PS_SOLID,1, CDrawLayer::GetRGBSemiShadow()); cpw.CreatePen(PS_SOLID,1, m_clrLight); /*************************************************** pDC->Draw3dRect(rcWin,m_clrLight,m_clrShadow); rcWin.DeflateRect(1,1); pDC->Draw3dRect(rcWin,m_clrFace,m_clrFace); ***************************************************/ int iNumItems=GetItemCount(); int iContx=0; for (int i =0; i < iNumItems; i++) { CRect recItem; GetItemRect(i, recItem); iContx+=recItem.Width(); //quitamos todas las lineas recItem.DeflateRect(1,1); pDC->SelectObject(&cpw); pDC->MoveTo(iContx-2,rcWin.top+1); pDC->LineTo(iContx-2,rcWin.bottom-1); pDC->SelectObject(&cps); pDC->MoveTo(iContx-1,rcWin.top+1); pDC->LineTo(iContx-1,rcWin.bottom-1); pDC->SelectObject(&cpw); pDC->MoveTo(iContx,rcWin.top+1); pDC->LineTo(iContx,rcWin.bottom-1); } cp.DeleteObject(); cps.DeleteObject(); cpw.DeleteObject(); }
void CrainDlg::doThread()//由线程执行的方法 { CBrush aBrush;//画笔,主要用来填充颜色 CPen aPen;//钢笔,主要用来画线条 CRect aRect;//矩形, CWnd * pWind=GetDlgItem(IDC_PIC);//获取画图框资源 CDC* pDC=pWind->GetDC();//画布 struct dropletchain *pRain;//用来读取雨点链表 while(1) { //画背景 aBrush.CreateSolidBrush(RGB(0,0,0));//设置画笔的颜色,即天空的颜色 pWind->GetClientRect(&aRect);//获取画布大小 aRect.bottom-=DEFAULT_BOTTOM_HEIGHT;//修改底部的高度,底部向上为天空 pDC->FillRect(aRect,&aBrush);//绘制上方天空 aBrush.DeleteObject();//用完画笔删除 aBrush.CreateSolidBrush(RGB(9,128,104));//设置池塘的颜色 aRect.top+=aRect.Height();//顶部下移 aRect.bottom+=DEFAULT_BOTTOM_HEIGHT;//底部高度下移 pDC->FillRect(aRect,&aBrush);//绘制下方池塘 aBrush.DeleteObject();//删除画笔 pDC->SelectStockObject(NULL_BRUSH);//把DC设置成空心画笔,在画涟漪时可以画出空心椭圆 pRain=pDropletchain;//把指针移向链表头 while(pRain) { aPen.CreatePen(PS_SOLID,pRain->data->thick,pRain->data->color);//创建钢笔 pDC->SelectObject(&aPen);//用这个钢笔来画画 if(pRain->data->y>aRect.top)//若雨点到达池塘顶部 { //画涟漪 pDC->Ellipse(pRain->data->x-pRain->data->radius-ELLIPSE,pRain->data->y-pRain->data->radius,pRain->data->x+pRain->data->radius+ELLIPSE,pRain->data->y+pRain->data->radius);//画出椭圆 pRain->data->radius++;//涟漪椭圆半径增大 if(pRain->data->radius>pRain->data->len||pRain->data->x+pRain->data->radius+ELLIPSE>=aRect.Width()) initDroplet(pRain->data);//如果雨点半径大于雨点长度则重新生成雨点 } else { //画雨点 pDC->MoveTo(pRain->data->x,pRain->data->y);//把画笔移动到指定的坐标 pDC->LineTo(pRain->data->x+(int)pRain->data->len*sin(pRain->data->angle),pRain->data->y+(int)pRain->data->len*cos(pRain->data->angle));//根据角度和长度绘制出斜线 pRain->data->x+=pRain->data->speed;pRain->data->y+=pRain->data->speed;//雨点的坐标增大,增大幅度为各自的speed if(pRain->data->x+(int)pRain->data->len*sin(pRain->data->angle)>=aRect.Width()-pRain->data->thick) initDroplet(pRain->data);//如果超出右侧界限则重新生成雨点 } aPen.DeleteObject();//删除钢笔 pRain=pRain->next;// } Sleep(100-m_slider.GetPos());//在死循环中休眠线程,形成动画效果 } pDC->ReleaseOutputDC();//释放DC资源 }
void CMoveTool::OnLButtonDown(_CVIEW * pView, UINT nFlags, CPoint& point) { 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_nDown==0) { c_PtDown=point; CPen Pen; if (!Pen.CreatePen(PS_DOT, 1, RGB(0,0,0))) return; pDC->SelectObject(&Pen); int oldDrawMode = pDC->SetROP2(R2_XORPEN); if(c_bSnap && pDoc->m_Graphics.m_bHaveSnap) { c_PtDown = pDoc->m_Graphics.DocToClient(pDoc->m_Graphics.m_curSnapP); } m_PointOrigin = c_PtDown; pDC->MoveTo(c_PtDown); pDC->LineTo(c_PtDown); pDC->SetROP2(oldDrawMode); Pen.DeleteObject(); } if(c_nDown<2) c_nDown++; if(c_nDown==2) { c_nDown=0; c_PtDown=point; if(c_bSnap && pDoc->m_Graphics.m_bHaveSnap) { c_PtDown = pDoc->m_Graphics.DocToClient(pDoc->m_Graphics.m_curSnapP); } CSize size1; size1.cx = c_PtDown.x-m_PointOrigin.x; size1.cy = c_PtDown.y-m_PointOrigin.y; pDoc->m_Graphics.MoveEntitiesTo(size1); pView->ReDraw(); } c_PtOld = c_PtDown; DeleteDC(pDC->m_hDC); //CDrawTool::OnLButtonDown(pView, nFlags, point); }
void CRectTool::OnMouseMove(_CVIEW* pView, UINT nFlags, CPoint& point) { 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 (pDoc->m_Graphics.m_GraphicsMode==Layout) SetCursor(AfxGetApp()->LoadCursor(IDC_DRAW_B)); else SetCursor(AfxGetApp()->LoadCursor(IDC_DRAW_W)); if (c_bSnap) { pDoc->m_Graphics.m_bSnapStatus=true; pDoc->m_Graphics.SnapHandle(pDC,point); } if (c_nDown!=1) { DeleteDC(pDC->m_hDC); return; } CPen Pen; if (!Pen.CreatePen(PS_SOLID, 1, RGB(255,255,255))) return; CPen* pOldPen = pDC->SelectObject(&Pen); LOGBRUSH logBrush; logBrush.lbColor = 0; logBrush.lbHatch = 0; logBrush.lbStyle = BS_NULL; CBrush NullBrush; NullBrush.CreateBrushIndirect(&logBrush); CBrush* pOldBrush = pDC->SelectObject(&NullBrush); int oldDrawMode = pDC->SetROP2(R2_XORPEN); if (!c_bJustDraw) pDC->Rectangle(c_PtDown.x,c_PtDown.y,c_PtOld.x,c_PtOld.y); c_bJustDraw = false; pDC->Rectangle(c_PtDown.x,c_PtDown.y,point.x,point.y); pDC->SetROP2(oldDrawMode); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldBrush); Pen.DeleteObject(); DeleteDC(pDC->m_hDC); CDrawTool::OnMouseMove(pView, nFlags, point); }
void CGroup1::LinesTop14(CDC* pDC, CSize& ScreenSize, int CameraX, int CameraY, // position on camera long x, long y, // position on screen long lFactorX, long lFactorY, long CameraFactor, COLORREF Pix, COLORREF PrevPix, DWORD) { long Diff = Pix - PrevPix; long R = GetRValue(Diff); long G = GetGValue(Diff); long B = GetBValue(Diff); COLORREF CurrColor = SelectColor(R, G, B); long rgb=(R+G+B)/3; long lastX = min(x+lFactorX, ScreenSize.cx); long lastY = min(y+lFactorY, ScreenSize.cy); CRect r(x, y, lastX, lastY); CBrush b(RGB(0,0,0)); CPen pen; pen.CreatePen(PS_SOLID, 1, CurrColor); CPen* pOld = pDC->SelectObject(&pen); CBrush* pOldB = pDC->SelectObject(&b); if (x<ScreenSize.cx/2 && y<ScreenSize.cy/2 ) { pDC->MoveTo (0,0); pDC->LineTo(x,y); } else if (x>ScreenSize.cx/2 && y<ScreenSize.cy/2 ) { pDC->MoveTo (ScreenSize.cx,0); pDC->LineTo(x,y); } else if (x<ScreenSize.cx/2 && y>ScreenSize.cy/2 ) { pDC->MoveTo (0,ScreenSize.cy); pDC->LineTo(x,y); } else if (x>ScreenSize.cx/2 && y>ScreenSize.cy/2 ) { pDC->MoveTo (ScreenSize.cx,ScreenSize.cy); pDC->LineTo(x,y); } b.DeleteObject(); pen.DeleteObject(); pDC->SelectObject(pOld); pDC->SelectObject(pOldB); }
void CSpy::DrawRect(HWND hWnd) { ::GetWindowRect(hWnd,&m_rc); if(m_rc!=m_r) { CDC DC,*pDC; CPen pen(PS_SOLID, 10, RGB(255,0,0)); CPen *pOldPen = NULL; HDC hDC = NULL; hDC = ::GetWindowDC(hWnd); pDC=DC.FromHandle (hDC); pOldPen = pDC->SelectObject(&pen); pDC->MoveTo(0, 0); pDC->LineTo(m_rc.Width(), 0); pDC->LineTo(m_rc.Width(), m_rc.Height()); pDC->LineTo(0, m_rc.Height()); pDC->LineTo(0, 0); pDC->SelectObject(pOldPen); pOldPen->DeleteObject (); ::DeleteObject (hDC); pDC->DeleteDC (); ::ReleaseDC(m_hWnd,hDC); m_r=m_rc; m_h1=m_h; if(m_h1!=hWnd) { ::RedrawWindow(m_h1, NULL, NULL, RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_ERASENOW | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); } m_h=hWnd; } }
void CLinkButton::DrawControl(CDC &dc, CRect rcUpdate) { int nWidth = m_rc.Width(); int nHeight = m_rc.Height(); if(!m_bUpdate) { UpdateMemDC(dc, nWidth * 4, nHeight); m_memDC.SetBkMode(TRANSPARENT); //CFont *pOldFont = m_memDC.SelectObject(&m_font); COLORREF clrText[4] = {m_clrTextNormal, m_clrTextHover, m_clrTextDown, m_clrTextDisable}; CRect rcText = m_rcText; rcText.OffsetRect(-m_rc.left, -m_rc.top); COLORREF clrOld = m_memDC.SetTextColor(clrText[0]); for(int i = 0; i < 4; i++) { m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY); m_memDC.SetTextColor(clrText[i]); //m_memDC.DrawText(m_strTitle, &rcText, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS); // Ï»®Ïß if(i == 1 || i == 2) { CPen pen; pen.CreatePen(PS_SOLID, 1, clrText[i]); CPen *pOldPen = m_memDC.SelectObject(&pen); m_memDC.MoveTo(rcText.left, rcText.bottom); m_memDC.LineTo(rcText.right, rcText.bottom); m_memDC.SelectObject(pOldPen); pen.DeleteObject(); } rcText.OffsetRect(nWidth, 0); } //m_memDC.SelectObject(pOldFont); m_memDC.SetTextColor(clrOld); } dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY); }
forEachTrack (pMIDIData, pTempTrack) { if (pMusicalScoreFrame->IsTrackVisible (i)) { if (lVisibleTopTrack <= i && i <= lVisibleBottomTrack) { long lColor = MIDITrack_GetForeColor (pTempTrack); pDC->SetTextColor (lColor); CPen theTrackPen; CBrush theTrackBrush; theTrackPen.CreatePen (PS_SOLID, 1, lColor); theTrackBrush.CreateSolidBrush (lColor); CPen* pOldPen = pDC->SelectObject (&theTrackPen); CBrush* pOldBrush = pDC->SelectObject (&theTrackBrush); DrawTimeAndKeySignature (pDC, i, lTime); pDC->SelectObject (pOldPen); pDC->SelectObject (pOldBrush); theTrackPen.DeleteObject (); theTrackBrush.DeleteObject (); } } i++; }
void CInfoDlg::SpyInvertBorder(const HWND &hWnd) { // 若非窗口则返回 if(!IsWindow(hWnd)) return; CRect rect; // 窗口矩形 // 得到窗口矩形 ::GetWindowRect(hWnd, &rect); CDC dc; // 窗口设备上下文 dc.Attach(::GetWindowDC(hWnd)); // 设置窗口当前前景色的混合模式为R2_NOT // R2_NOT - 当前的像素值为屏幕像素值的取反,这样可以覆盖掉上次的绘图 dc.SetROP2(R2_NOT); // 创建画笔 CPen pen; // PS_INSIDEFRAME - 产生封闭形状的框架内直线,指定一个限定矩形 // 3 * GetSystemMetrics(SM_CXBORDER) - 三倍边界粗细 // RGB(0,0,0) - 黑色 pen.CreatePen(PS_INSIDEFRAME, 3 * GetSystemMetrics(SM_CXBORDER), RGB(0, 0, 0)); // 选择画笔 HGDIOBJ old_pen = dc.SelectObject(pen); // 设定画刷 HGDIOBJ old_brush = dc.SelectObject(GetStockObject(NULL_BRUSH)); // 画矩形 dc.Rectangle(0, 0, rect.Width(), rect.Height()); // 恢复原来的设备环境 dc.SelectObject(old_pen); dc.SelectObject(old_brush); pen.DeleteObject(); }