void PaintRoutine (HWND hwnd, HDC hdc, int cxArea, int cyArea) { static TCHAR szString [] = TEXT ("Filling") ; HFONT hFont ; SIZE size ; hFont = EzCreateFont (hdc, TEXT ("Times New Roman"), 1440, 0, 0, TRUE) ; SelectObject (hdc, hFont) ; SetBkMode (hdc, TRANSPARENT) ; GetTextExtentPoint32 (hdc, szString, lstrlen (szString), &size) ; BeginPath (hdc) ; TextOut (hdc, (cxArea - size.cx) / 2, (cyArea - size.cy) / 2, szString, lstrlen (szString)) ; EndPath (hdc) ; SelectObject (hdc, CreateHatchBrush (HS_DIAGCROSS, RGB (255, 0, 0))) ; SetBkColor (hdc, RGB (0, 0, 255)) ; SetBkMode (hdc, OPAQUE) ; StrokeAndFillPath (hdc) ; DeleteObject (SelectObject (hdc, GetStockObject (WHITE_BRUSH))) ; SelectObject (hdc, GetStockObject (SYSTEM_FONT)) ; DeleteObject (hFont) ; }
void GdiContext2D::Check() { //because GDI closes the path after Fill or stroke //we need a state to do both at the same time if (this->flags == 0) { //not using path return; } if (this->flags == 1) { COLORREF color = ColorToColorRef(strokeStyle.m_Color); HPEN hpen = CreatePen(PS_SOLID, (int)lineWidth, color); //TODO HPEN oldPen = (HPEN) SelectObject(m_hDC, hpen); StrokePath(m_hDC); SelectObject(m_hDC, oldPen); // DeleteObject(hpen); } else if (this->flags == 2) { COLORREF color = ColorToColorRef(fillStyle.m_Color); LOGBRUSH logbrush; logbrush.lbColor = color; logbrush.lbStyle = BS_SOLID; logbrush.lbHatch = 0; HBRUSH hBrush = CreateBrushIndirect(&logbrush); HBRUSH oldBrush = (HBRUSH)SelectObject(m_hDC, hBrush); // FillPath(m_hDC); // SelectObject(m_hDC, oldBrush); DeleteObject(hBrush); } else if (this->flags == 3) { COLORREF color2 = ColorToColorRef(strokeStyle.m_Color); HPEN hpen = CreatePen(PS_SOLID, (int) lineWidth, color2); //TODO HPEN oldPen = (HPEN) SelectObject(m_hDC, hpen); COLORREF color = ColorToColorRef(fillStyle.m_Color); LOGBRUSH logbrush; logbrush.lbColor = color; logbrush.lbStyle = BS_SOLID; logbrush.lbHatch = 0; HBRUSH hBrush = CreateBrushIndirect(&logbrush); HBRUSH oldBrush = (HBRUSH)SelectObject(m_hDC, hBrush); // StrokeAndFillPath(m_hDC); // SelectObject(m_hDC, oldPen); SelectObject(m_hDC, oldBrush); // DeleteObject(hBrush); DeleteObject(hpen); } this->flags = 0; }
PHP_METHOD(WinGdiPath, strokeAndFill) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters_none() == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(StrokeAndFillPath(dc_obj->hdc)); }
static PetscErrorCode PetscDrawTriangle_Win32(PetscDraw draw,PetscReal x1,PetscReal yone,PetscReal x2,PetscReal y2, PetscReal x3,PetscReal y3,int c1,int c2,int c3) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; HBRUSH hbrush; HPEN hpen; int p1x,p1y,p2x,p2y,p3x,p3y; HDC bit; PetscFunctionBegin; AverageColorTriangle_Win32(draw,c1,c2,c3); hbrush = CreateSolidBrush(windraw->currentcolor); hpen = CreatePen(PS_SOLID,0,windraw->currentcolor); p1x = XTRANS(draw,windraw,x1); p2x = XTRANS(draw,windraw,x2); p3x = XTRANS(draw,windraw,x3); p1y = YTRANS(draw,windraw,yone); p2y = YTRANS(draw,windraw,y2); p3y = YTRANS(draw,windraw,y3); if(windraw->node->DoubleBuffered) { bit = windraw->node->DoubleBuffer; } else { bit = windraw->node->Buffer; } BeginPath(bit); MoveToEx(bit,p1x,p1y,NULL); LineTo(bit,p2x,p2y); LineTo(bit,p3x,p3y); LineTo(bit,p1x,p1y); EndPath(bit); SelectPen(bit,hpen); SelectBrush(bit,hbrush); StrokeAndFillPath(bit); /* Forces a WM_PAINT message and erases background */ InvalidateRect(windraw->hWnd,NULL,TRUE); UpdateWindow(windraw->hWnd); PetscFunctionReturn(0); }
void __fastcall TExtPolyline::DrawTo(void *dc,void *pen,void *brush) { CreatePath(dc); if (brush) { void* oldbrush=SelectObject(dc,brush); if (pen) { void *oldpen=SelectObject(dc,pen); StrokeAndFillPath(dc); SelectObject(dc,oldpen); } else FillPath(dc); SelectObject(dc,oldbrush); } else if (pen) { void *oldpen=SelectObject(dc,pen); StrokePath(dc); SelectObject(dc,oldpen); } }
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { INITCOMMONCONTROLSEX icx; icx.dwSize = sizeof(INITCOMMONCONTROLSEX); icx.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&icx); hTrackBar = CreateWindow( TRACKBAR_CLASS, "", TBS_HORZ | TBS_BOTH | TBS_AUTOTICKS | TBS_FIXEDLENGTH | TBS_ENABLESELRANGE | WS_CHILD | WS_VISIBLE, 10, 260, 375, 40, hWnd, NULL, hInst, NULL ); assert(hTrackBar != NULL); SNDMSG(hTrackBar, TBM_SETTHUMBLENGTH, 20, 0); SNDMSG(hTrackBar, TBM_SETRANGEMAX, TRUE, 100); // create the TrueType (scalable) font HDC hDC = GetDC(hWnd); try { // see Chapter 4 for the definition of MakeFont hTTFont = font::MakeFont(hDC, "Impact", 72); if (!hTTFont) throw; } catch (...) { ReleaseDC(hWnd, hDC); } ReleaseDC(hWnd, hDC); break; } case WM_HSCROLL: { if (reinterpret_cast<HWND>(lParam) == hTrackBar) { // // adjust the scaling factor according to // the position of the trackbar's slider // scale = static_cast<double>( (SNDMSG(hTrackBar, TBM_GETPOS, 0, 0) + 1) / 50.0 ); InvalidateRect(hWnd, NULL, true); } break; } case WM_ERASEBKGND: { LRESULT res = DefWindowProc(hWnd, msg, wParam, lParam); HDC hDC = reinterpret_cast<HDC>(wParam); HFONT hOldFont = static_cast<HFONT>( SelectObject(hDC, hTTFont) ); try { SetBkMode(hDC, TRANSPARENT); // open a path bracket if (!BeginPath(hDC)) throw; // record the text to the path TextOut(hDC, 10, 10, pText, lstrlen(pText)); // close the path bracket and // select the path into hDC EndPath(hDC); // determine the number of endpoints in the path const int num_points = GetPath(hDC, NULL, NULL, 0); if (num_points > 0) { // make room for the POINTs and vertex types POINT* pPEnds = new POINT[num_points]; unsigned char* pTypes = new unsigned char[num_points]; try { // get the path's description int num_got = GetPath(hDC, pPEnds, pTypes, num_points); if (num_got > 0) { // start a new path bracket if (!BeginPath(hDC)) throw; // scale each point in the description int iPoint; for (iPoint = 0; iPoint < num_got; ++iPoint) { pPEnds[iPoint].x = static_cast<LONG>( scale * pPEnds[iPoint].x + 0.5 ); pPEnds[iPoint].y = static_cast<LONG>( scale * pPEnds[iPoint].y + 0.5 ); } for (iPoint = 0; iPoint < num_points; ++iPoint) { // handle the MoveToEx case if (pTypes[iPoint] == PT_MOVETO) { MoveToEx( hDC, pPEnds[iPoint].x, pPEnds[iPoint].y, NULL ); } // handle the LineTo case else if ( pTypes[iPoint] == PT_LINETO || pTypes[iPoint] == (PT_LINETO | PT_CLOSEFIGURE) ) { LineTo(hDC, pPEnds[iPoint].x, pPEnds[iPoint].y); } // handle the PolyBezierTo case else if ( pTypes[iPoint] == PT_BEZIERTO || pTypes[iPoint] == (PT_BEZIERTO | PT_CLOSEFIGURE) ) { PolyBezierTo(hDC, pPEnds + iPoint, 3); iPoint += 2; } } // close the new path bracket EndPath(hDC); // stroke and fill the new path StrokeAndFillPath(hDC); } } catch (...) { // clean up delete [] pTypes; delete [] pPEnds; throw; } // clean up delete [] pTypes; delete [] pPEnds; } // ... } catch (...) { SelectObject(hDC, hOldFont); } SelectObject(hDC, hOldFont); return res; } case WM_SIZE: { MoveWindow( hTrackBar, 0, HIWORD(lParam) - 40, LOWORD(lParam), 40, false ); break; } case WM_DESTROY: { // clean up DeleteObject(hTTFont); PostQuitMessage(0); break; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
void EmfPaintEngine::drawPath ( const QPainterPath & path ) { setClipping(); int points = path.elementCount(); POINT *pts = new POINT[points]; BYTE *types = new BYTE[points]; POINT *bzs = new POINT[3]; int bez = 0; BeginPath(metaDC); QMatrix m = painter()->worldMatrix(); for (int i = 0; i < points; i++){ QPainterPath::Element el = path.elementAt(i); QPointF p = m.map(QPointF(el.x, el.y)); int x = qRound(p.x()); int y = qRound(p.y()); pts[i].x = x; pts[i].y = y; switch(el.type){ case QPainterPath::MoveToElement: types[i] = PT_MOVETO; #ifndef Q_WS_WIN MoveToEx (metaDC, x, y, 0); #endif break; case QPainterPath::LineToElement: types[i] = PT_LINETO; #ifndef Q_WS_WIN LineTo(metaDC, x, y); #endif break; case QPainterPath::CurveToElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; bez++; #endif break; case QPainterPath::CurveToDataElement: types[i] = PT_BEZIERTO; #ifndef Q_WS_WIN bzs[bez] = pts[i]; if (bez == 2){ PolyBezierTo(metaDC, bzs, 3); bez = 0; } else bez++; #endif break; } } HPEN wpen = convertPen(painter()->pen()); SelectObject(metaDC, wpen); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif HBRUSH wbrush = convertBrush(painter()->brush()); SelectObject(metaDC, wbrush); EndPath(metaDC); if(QPoint(pts[0].x, pts[0].y) == QPoint(pts[points - 1].x, pts[points - 1].y)) StrokeAndFillPath(metaDC); else { FillPath(metaDC); #ifdef Q_WS_WIN PolyDraw(metaDC, pts, types, points); #else StrokePath(metaDC); #endif } resetClipping(); DeleteObject(wbrush); DeleteObject(wpen); delete [] pts; delete [] types; }