void WinInitPicture (int size, int mode, int pr, int pg, int pb, int br, int bg, int bb, char *fname, int fstyle, int fsize, HRGN clipRgn, BOOL bDoubleBuffered, OSPictContext context ) { LOGBRUSH lb; LOGFONT lf; DWORD style; context->penSize = size; context->penPat = iBlackPattern; context->penMode = mode; context->penColor = RGB (pr, pg, pb); context->backColor = RGB (br, bg, bb); context->lastActivity = FILLING; if (bDoubleBuffered) { RECT clipRect; if (GetClipBox(context->hDC,&clipRect) == ERROR) { printf("osInitPicture -> GetClipBox failed\n"); exit(1); } context->hBufferedDC = context->hDC; context->hDC = CreateCompatibleDC(context->hBufferedDC); context->hBufferBitmap = CreateCompatibleBitmap(context->hBufferedDC,clipRect.right-clipRect.left,clipRect.bottom-clipRect.top); SelectObject(context->hDC, context->hBufferBitmap); if (!BitBlt(context->hDC, 0, 0, clipRect.right-clipRect.left, clipRect.bottom-clipRect.top, context->hBufferedDC, clipRect.left, clipRect.top, SRCCOPY)) { printf("osDonePicture -> BitBlt failed\n"); exit(1); } SetViewportOrgEx(context->hDC,-clipRect.left,-clipRect.top,NULL); } thePolygon = NULL; SetPolyFillMode (context->hDC, WINDING); strcpy (context->curFont, fname); context->fontstyle = fstyle; context->fontsize = PointsToPix(context->hDC,fsize); // PointsToPix by MW SetLogFontData (&lf, context->curFont, context->fontstyle, context->fontsize); if (context->penSize == 1) style = PS_COSMETIC | PS_SOLID; else style = PS_GEOMETRIC | PS_INSIDEFRAME; lb.lbStyle = BS_SOLID; lb.lbColor = context->penColor; lb.lbHatch = 0; context->theNormalPen = ExtCreatePen (style, context->penSize, &lb, 0, NULL); lb.lbStyle = BS_SOLID; lb.lbColor = context->backColor; lb.lbHatch = 0; context->theBackPen = ExtCreatePen (style, context->penSize, &lb, 0, NULL); SetBrushOrgEx (context->hDC,0,0,NULL); context->theNormalBrush = CreateSolidBrush (context->penColor); context->theBackBrush = CreateSolidBrush (context->backColor); context->theFont = CreateFontIndirect (&lf); SaveDC (context->hDC); SetWindowOrgEx (context->hDC, 0,0, NULL); SelectObject (context->hDC, GetStockObject (NULL_PEN)); SelectObject (context->hDC, context->theNormalBrush); SelectObject (context->hDC, context->theFont); SetBkMode (context->hDC, TRANSPARENT); SetBkColor (context->hDC, context->backColor); SetTextAlign (context->hDC, TA_LEFT | TA_BASELINE); WinSetMode (context->penMode, context); SetStretchBltMode (context->hDC,COLORONCOLOR); /* PA: when stretching bitmaps, use COLORONCOLOR mode. */ if (ghCaretWnd) { int mess, p1, p2, p3, p4, p5, p6; WinKickOsThread (CcRqHIDECARET, (int) ghCaretWnd, 0, 0, 0, 0, 0, &mess, &p1, &p2, &p3, &p4, &p5, &p6); } if (clipRgn != NULL) SelectClipRgn (context->hDC, clipRgn); } /* WinInitPicture */
static void winPrepareLine (GraphicsScreen me) { HPEN newPen; int lineWidth_pixels = LINE_WIDTH_IN_PIXELS (me) + 0.5; if (! lineWidth_pixels) lineWidth_pixels = 1; my d_fatNonSolid = my lineType != Graphics_DRAWN && my lineWidth > 1; if (Melder_debug == 10) { LOGBRUSH brush; brush. lbStyle = BS_SOLID; brush. lbColor = my d_winForegroundColour; brush. lbHatch = my lineType == Graphics_DRAWN ? 0 : my lineType == Graphics_DOTTED ? PS_DOT : my lineType == Graphics_DASHED ? PS_DASH : PS_DASHDOT; newPen = ExtCreatePen (PS_GEOMETRIC, lineWidth_pixels, & brush, 0, NULL); } else { /*newPen = CreatePen (my lineType == Graphics_DRAWN ? PS_SOLID : my lineType == Graphics_DOTTED ? PS_DOT : my lineType == Graphics_DASHED ? PS_DASH : PS_DASHDOT, my fatNonSolid ? 1 : lineWidth_pixels, my foregroundColour);*/ LOGPEN pen; pen. lopnStyle = my lineType == Graphics_DRAWN ? PS_SOLID : my lineType == Graphics_DOTTED ? PS_DOT : my lineType == Graphics_DASHED ? PS_DASH : PS_DASHDOT; pen. lopnWidth. x = my d_fatNonSolid ? 1 : lineWidth_pixels; pen. lopnWidth. y = 0; pen. lopnColor = my d_winForegroundColour | 0x02000000; newPen = CreatePenIndirect (& pen); } SelectPen (my d_gdiGraphicsContext, newPen); DeletePen (my d_winPen); my d_winPen = newPen; }
int CALLBACK EnhMetaFileProc (HDC hdc, HANDLETABLE * pHandleTable, CONST ENHMETARECORD * pEmfRecord, int iHandles, LPARAM pData) { HBRUSH hBrush ; HPEN hPen ; LOGBRUSH lb ; if (pEmfRecord->iType != EMR_HEADER && pEmfRecord->iType != EMR_EOF) PlayEnhMetaFileRecord (hdc, pHandleTable, pEmfRecord, iHandles) ; if (pEmfRecord->iType == EMR_RECTANGLE) { hBrush = SelectObject (hdc, GetStockObject (NULL_BRUSH)) ; lb.lbStyle = BS_SOLID ; lb.lbColor = RGB (0, 255, 0) ; lb.lbHatch = 0 ; hPen = SelectObject (hdc, ExtCreatePen (PS_SOLID | PS_GEOMETRIC, 5, &lb, 0, NULL)) ; Ellipse (hdc, 100, 100, 200, 200) ; DeleteObject (SelectObject (hdc, hPen)) ; SelectObject (hdc, hBrush) ; } return TRUE ; }
void select(int color) { for (l2elem* elem = next; elem != this; elem = elem->next) { pen_cache_item* ci = (pen_cache_item*)elem; if (ci->color == color && ci->style == line_settings.linestyle && ci->width == line_settings.thickness && (line_settings.linestyle != USERBIT_LINE || line_settings.upattern == ci->pattern)) { ci->unlink(); // LRU discipline ci->link_after(this); if (hPen != ci->pen) { hPen = ci->pen; SelectObject(hdc[0], hPen); SelectObject(hdc[1], hPen); } return; } } hPen = NULL; if (line_settings.linestyle == USERBIT_LINE) { LOGBRUSH lb; lb.lbColor = PALETTEINDEX(color); lb.lbStyle = BS_SOLID; DWORD style[32]; hPen = ExtCreatePen(PS_GEOMETRIC|PS_USERSTYLE, line_settings.thickness, &lb, convert_userbits(style,line_settings.upattern), style); } if (hPen == NULL) { hPen = CreatePen(line_style_cnv[line_settings.linestyle], line_settings.thickness, PALETTEINDEX(color)); } SelectObject(hdc[0], hPen); SelectObject(hdc[1], hPen); pen_cache_item* p; if (free == NULL) { p = (pen_cache_item*)prev; p->unlink(); DeleteObject(p->pen); } else { p = free; free = (pen_cache_item*)p->next; } p->pen = hPen; p->color = color; p->width = line_settings.thickness; p->style = line_settings.linestyle; p->pattern = line_settings.upattern; p->link_after(this); }
static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style) { PLOT_LOG("from %d,%d to %d,%d", x0, y0, x1, y1); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG("HDC not set on call to plotters"); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF); /* windows 0x00bbggrr */ DWORD penstyle = PS_GEOMETRIC | ((style->stroke_type == PLOT_OP_TYPE_DOT) ? PS_DOT : (style->stroke_type == PLOT_OP_TYPE_DASH) ? PS_DASH: 0); LOGBRUSH lb = {BS_SOLID, col, 0}; HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); if (pen == NULL) { DeleteObject(clipregion); return false; } HGDIOBJ bak = SelectObject(plot_hdc, (HGDIOBJ) pen); if (bak == NULL) { DeleteObject(pen); DeleteObject(clipregion); return false; } /* RECT r; r.left = x0; r.top = y0; r.right = x1; r.bottom = y1; */ SelectClipRgn(plot_hdc, clipregion); MoveToEx(plot_hdc, x0, y0, (LPPOINT) NULL); LineTo(plot_hdc, x1, y1); SelectClipRgn(plot_hdc, NULL); pen = SelectObject(plot_hdc, bak); DeleteObject(pen); DeleteObject(clipregion); return true; }
void CCurvePen::Physicalize() { if (PhysicalPen) DeleteObject(PhysicalPen); LOGBRUSH brush; brush.lbStyle = BS_SOLID; brush.lbColor = Color; ((CCurvePen*)this)->PhysicalPen = ExtCreatePen(PS_GEOMETRIC | PS_JOIN_ROUND | PS_SOLID, Width, &brush, 0, NULL); }
static void test_ps_alternate(void) { HDC hdc; HBITMAP bmp; HPEN pen; LOGBRUSH lb; INT iRet; HGDIOBJ hRet; lb.lbStyle = BS_SOLID; lb.lbColor = RGB(0xff,0xff,0xff); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL); if(pen == NULL && GetLastError() == 0xdeadbeef) { skip("looks like 9x, skipping PS_ALTERNATE tests\n"); return; } ok(pen != NULL, "gle=%d\n", GetLastError()); hdc = CreateCompatibleDC(NULL); ok(hdc != NULL, "gle=%d\n", GetLastError()); bmp = CreateBitmap(8, 1, 1, 1, NULL); ok(bmp != NULL, "gle=%d\n", GetLastError()); hRet = SelectObject(hdc, bmp); ok(hRet != NULL, "gle=%d\n", GetLastError()); hRet = SelectObject(hdc, pen); ok(hRet != NULL, "gle=%d\n", GetLastError()); iRet = SetBkMode(hdc, TRANSPARENT); ok(iRet, "gle=%d\n", GetLastError()); TEST_LINE(0, 1, "10000000") TEST_LINE(0, 2, "10000000") TEST_LINE(0, 3, "10100000") TEST_LINE(0, 4, "10100000") TEST_LINE(1, 4, "01010000") TEST_LINE(1, 5, "01010000") TEST_LINE(4, 8, "00001010") DeleteObject(pen); DeleteObject(bmp); DeleteDC(hdc); }
HPEN CTextLayout::CreateUnderlinePen(BYTE bAttr, int nWidth) { const DWORD s_dwDotStyles[] = {1,2}; const DWORD s_dwDashStyles[] = {3,2}; DWORD dwPenStyle = PS_GEOMETRIC | PS_SOLID; DWORD dwStyles = 0; const DWORD *lpdwStyles = NULL; switch (bAttr) { case ATTR_INPUT: dwPenStyle = PS_GEOMETRIC | PS_USERSTYLE | PS_ENDCAP_FLAT; dwStyles = 2; lpdwStyles = s_dwDotStyles; break; case ATTR_TARGET_CONVERTED: case ATTR_TARGET_NOTCONVERTED: dwPenStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT; nWidth *= 2; break; case ATTR_CONVERTED: case ATTR_INPUT_ERROR: case ATTR_FIXEDCONVERTED: default: dwPenStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT; break; } LOGBRUSH lbr; lbr.lbStyle = BS_SOLID; lbr.lbColor = 0; lbr.lbHatch = 0; lbr.lbColor = RGB(0, 0, 0); return ExtCreatePen(dwPenStyle, nWidth, &lbr, dwStyles, lpdwStyles); }
HPEN CTextLayout::CreateUnderlinePen(const TF_DISPLAYATTRIBUTE *pda, int nWidth) { const DWORD s_dwDotStyles[] = {1,2}; const DWORD s_dwDashStyles[] = {3,2}; DWORD dwPenStyle = PS_GEOMETRIC | PS_SOLID; DWORD dwStyles = 0; const DWORD *lpdwStyles = NULL; if (pda->fBoldLine) nWidth *= 2; switch (pda->lsStyle) { case TF_LS_NONE: return NULL; case TF_LS_SOLID: dwPenStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT; break; case TF_LS_DOT: case TF_LS_DASH: case TF_LS_SQUIGGLE: dwPenStyle = PS_GEOMETRIC | PS_USERSTYLE | PS_ENDCAP_FLAT; dwStyles = 2; lpdwStyles = s_dwDotStyles; break; } LOGBRUSH lbr; lbr.lbStyle = BS_SOLID; lbr.lbColor = 0; lbr.lbHatch = 0; lbr.lbColor = GetAttributeColor(&pda->crLine); return ExtCreatePen(dwPenStyle, nWidth, &lbr, dwStyles, lpdwStyles); }
void CGdiAlpha::DrawLine(HDC hdc,int x1,int y1,int x2,int y2,COLORREF cr,UINT style, int iLineSize) { RECT rcDest; int iLineRadius = iLineSize / 2; int iRemainder = iLineSize % 2; if(x1==x2) //竖线 { if(y1>y2) _swap(y1,y2); SetRect(&rcDest,x1-iLineRadius,y1,x1+iLineRadius+iRemainder,y2); } else if(y1==y2)//横线 { if(x1>x2) _swap(x1,x2); SetRect(&rcDest,x1,y1-iLineRadius,x2,y1+iLineRadius+iRemainder); } else { if(x1>x2) _swap(x1,x2); if(y1>y2) _swap(y1,y2); SetRect(&rcDest,x1-iLineRadius,y1-iLineRadius,x2+iLineRadius+iRemainder,y2+iLineRadius+iRemainder); } ALPHAINFO ai; AlphaBackup(hdc,&rcDest,ai); LOGBRUSH lb; lb.lbStyle = BS_SOLID; lb.lbColor = cr; lb.lbHatch = 0; HPEN hPen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_FLAT | style, iLineSize, &lb, 0, NULL); HPEN hOld=(HPEN)SelectObject(hdc,hPen); MoveToEx(hdc,x1,y1,NULL); LineTo(hdc,x2,y2); SelectObject(hdc,hOld); DeleteObject(hPen); AlphaRestore(hdc,ai); }
static void ChangeTheBackPen (OSPictContext context) { HPEN hp; LOGBRUSH lb; DWORD style; lb.lbStyle = BS_SOLID; lb.lbColor = context->backColor; lb.lbHatch = 0; if (context->penSize == 1) style = PS_COSMETIC | PS_SOLID; else style = PS_GEOMETRIC | PS_INSIDEFRAME; hp = ExtCreatePen (style, context->penSize, &lb, 0, NULL); if (context->lastActivity == UNDRAWING) SelectObject (context->hDC, hp); DeleteObject (context->theBackPen); context->theBackPen = hp; } /* ChangeTheBackPen */
void TabEditorSplitter::MouseMove(wyBool isinit) { RECT parentrect; POINT curpos, pt; LOGBRUSH lb = {0}; WORD bitmap[] = {0x00AA, 0x0055, 0x00AA, 0x0055, 0x00AA, 0x0055, 0x00AA, 0x0055}; HBITMAP hbitmap; VERIFY(GetClientRect(m_hwndparent, &parentrect)); //set the tab height parentrect.top = m_isdlgsplitter == wyTrue ? 0 : CustomTab_GetTabHeight(m_hwndparent); // Get the screen coordinates and convert it into client points. VERIFY(GetCursorPos(&curpos)); VERIFY(ScreenToClient(m_hwndparent, &curpos)); if(m_isdragged == wyTrue) { pt = curpos; if(isinit == wyTrue) { m_y = pt.y; m_hdc = GetDC(m_hwndparent); hbitmap = CreateBitmap(8, 8, 1, 1, bitmap); lb.lbStyle = BS_PATTERN; lb.lbColor = 0; lb.lbHatch = (ULONG_PTR)hbitmap; m_hpen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_FLAT , 4, &lb, 0, NULL); DeleteBitmap(hbitmap); } if(curpos.y <= parentrect.top) { m_rect.top = parentrect.top; m_leftortoppercent = 0; } else { m_ischanged = wyTrue; if(curpos.y <= (parentrect.bottom - m_height)) { m_rect.top = curpos.y; m_leftortoppercent = (((curpos.y - parentrect.top) * 100 / (parentrect.bottom - parentrect.top) * 100) / 100); } else { m_rect.top = parentrect.bottom - m_height; m_leftortoppercent = 100; } } DrawTrackerLine(); if(isinit == wyTrue) { return; } m_y = pt.y; DrawTrackerLine(); } return; }
static void test_brush_pens(void) { char buffer[sizeof(EXTLOGPEN) + 15 * sizeof(DWORD)]; EXTLOGPEN *elp = (EXTLOGPEN *)buffer; LOGBRUSH lb; HPEN pen = 0; DWORD size; HBITMAP bmp = CreateBitmap( 8, 8, 1, 1, NULL ); BITMAPINFO *info; HGLOBAL hmem; hmem = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(*info) + 16 * 16 * 4 ); info = GlobalLock( hmem ); info->bmiHeader.biSize = sizeof(info->bmiHeader); info->bmiHeader.biWidth = 16; info->bmiHeader.biHeight = 16; info->bmiHeader.biPlanes = 1; info->bmiHeader.biBitCount = 32; info->bmiHeader.biCompression = BI_RGB; for (lb.lbStyle = BS_SOLID; lb.lbStyle <= BS_MONOPATTERN + 1; lb.lbStyle++) { SetLastError( 0xdeadbeef ); memset( buffer, 0xcc, sizeof(buffer) ); trace( "testing brush style %u\n", lb.lbStyle ); switch (lb.lbStyle) { case BS_SOLID: case BS_HATCHED: lb.lbColor = RGB(12,34,56); lb.lbHatch = HS_CROSS; pen = ExtCreatePen( PS_DOT | PS_GEOMETRIC, 3, &lb, 0, NULL ); ok( pen != 0, "ExtCreatePen failed err %u\n", GetLastError() ); size = GetObject( pen, sizeof(buffer), elp ); ok( size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "wrong size %u\n", size ); ok( elp->elpPenStyle == (PS_DOT | PS_GEOMETRIC), "wrong pen style %x\n", elp->elpPenStyle ); ok( elp->elpBrushStyle == lb.lbStyle, "wrong brush style %x\n", elp->elpBrushStyle ); ok( elp->elpColor == RGB(12,34,56), "wrong color %x\n", elp->elpColor ); ok( elp->elpHatch == HS_CROSS, "wrong hatch %lx\n", elp->elpHatch ); ok( elp->elpNumEntries == 0, "wrong entries %x\n", elp->elpNumEntries ); break; case BS_NULL: pen = ExtCreatePen( PS_SOLID | PS_GEOMETRIC, 3, &lb, 0, NULL ); ok( pen != 0, "ExtCreatePen failed err %u\n", GetLastError() ); size = GetObject( pen, sizeof(buffer), elp ); ok( size == sizeof(LOGPEN), "wrong size %u\n", size ); ok( ((LOGPEN *)elp)->lopnStyle == PS_NULL, "wrong pen style %x\n", ((LOGPEN *)elp)->lopnStyle ); ok( ((LOGPEN *)elp)->lopnColor == 0, "wrong color %x\n", ((LOGPEN *)elp)->lopnColor ); break; case BS_PATTERN: lb.lbColor = RGB(12,34,56); lb.lbHatch = (ULONG_PTR)bmp; pen = ExtCreatePen( PS_DOT | PS_GEOMETRIC, 3, &lb, 0, NULL ); ok( pen != 0, "ExtCreatePen failed err %u\n", GetLastError() ); size = GetObject( pen, sizeof(buffer), elp ); ok( size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "wrong size %u\n", size ); ok( elp->elpPenStyle == (PS_DOT | PS_GEOMETRIC), "wrong pen style %x\n", elp->elpPenStyle ); ok( elp->elpBrushStyle == BS_PATTERN, "wrong brush style %x\n", elp->elpBrushStyle ); ok( elp->elpColor == 0, "wrong color %x\n", elp->elpColor ); ok( elp->elpHatch == (ULONG_PTR)bmp, "wrong hatch %lx/%p\n", elp->elpHatch, bmp ); ok( elp->elpNumEntries == 0, "wrong entries %x\n", elp->elpNumEntries ); break; case BS_DIBPATTERN: case BS_DIBPATTERNPT: lb.lbColor = DIB_PAL_COLORS; lb.lbHatch = lb.lbStyle == BS_DIBPATTERN ? (ULONG_PTR)hmem : (ULONG_PTR)info; pen = ExtCreatePen( PS_DOT | PS_GEOMETRIC, 3, &lb, 0, NULL ); ok( pen != 0, "ExtCreatePen failed err %u\n", GetLastError() ); size = GetObject( pen, sizeof(buffer), elp ); ok( size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "wrong size %u\n", size ); ok( elp->elpPenStyle == (PS_DOT | PS_GEOMETRIC), "wrong pen style %x\n", elp->elpPenStyle ); ok( elp->elpBrushStyle == BS_DIBPATTERNPT, "wrong brush style %x\n", elp->elpBrushStyle ); ok( elp->elpColor == 0, "wrong color %x\n", elp->elpColor ); ok( elp->elpHatch == lb.lbHatch || broken(elp->elpHatch != lb.lbHatch), /* <= w2k */ "wrong hatch %lx/%lx\n", elp->elpHatch, lb.lbHatch ); ok( elp->elpNumEntries == 0, "wrong entries %x\n", elp->elpNumEntries ); break; default: pen = ExtCreatePen( PS_DOT | PS_GEOMETRIC, 3, &lb, 0, NULL ); ok( !pen, "ExtCreatePen succeeded\n" ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); break; } if (pen) DeleteObject( pen ); else continue; /* cosmetic pens require BS_SOLID */ SetLastError( 0xdeadbeef ); pen = ExtCreatePen( PS_DOT, 1, &lb, 0, NULL ); if (lb.lbStyle == BS_SOLID) { ok( pen != 0, "ExtCreatePen failed err %u\n", GetLastError() ); size = GetObject( pen, sizeof(buffer), elp ); ok( size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "wrong size %u\n", size ); ok( elp->elpPenStyle == PS_DOT, "wrong pen style %x\n", elp->elpPenStyle ); ok( elp->elpBrushStyle == BS_SOLID, "wrong brush style %x\n", elp->elpBrushStyle ); ok( elp->elpColor == RGB(12,34,56), "wrong color %x\n", elp->elpColor ); ok( elp->elpHatch == HS_CROSS, "wrong hatch %lx\n", elp->elpHatch ); DeleteObject( pen ); } else { ok( !pen, "ExtCreatePen succeeded\n" ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); } } GlobalUnlock( hmem ); GlobalFree( hmem ); DeleteObject( bmp ); }
void Test_ExtPen(void) { HPEN hPen; EXTLOGPEN extlogpen; LOGBRUSH logbrush; DWORD dwStyles[17] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; struct { EXTLOGPEN extlogpen; DWORD dwStyles[50]; } elpUserStyle; int i; SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_EXTPEN, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_EXTPEN, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n"); FillMemory(&extlogpen, sizeof(EXTLOGPEN), 0x77); logbrush.lbStyle = BS_SOLID; logbrush.lbColor = RGB(1,2,3); logbrush.lbHatch = 22; hPen = ExtCreatePen(PS_GEOMETRIC | PS_DASH, 5, &logbrush, 0, NULL); SetLastError(ERROR_SUCCESS); ok(GDI_HANDLE_GET_TYPE(hPen) == GDI_OBJECT_TYPE_EXTPEN, "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN), NULL) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, 0, NULL) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject((HANDLE)GDI_HANDLE_GET_INDEX(hPen), 0, NULL) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, 5, NULL) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, -5, NULL) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); ok(GetObject((HANDLE)GDI_OBJECT_TYPE_EXTPEN, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %ld\n", GetLastError()); SetLastError(0xbadbad00); ok(GetObject(hPen, 0, &extlogpen) == 0, "\n"); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(ERROR_SUCCESS); ok(GetObject(hPen, 4, &extlogpen) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "got %ld\n", GetLastError()); SetLastError(ERROR_SUCCESS); ok(GetObject((HANDLE)GDI_OBJECT_TYPE_EXTPEN, 0, &extlogpen) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %ld\n", GetLastError()); SetLastError(ERROR_SUCCESS); ok(GetObject((HANDLE)GDI_OBJECT_TYPE_EXTPEN, 4, &extlogpen) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %ld\n", GetLastError()); SetLastError(ERROR_SUCCESS); ok(GetObject(hPen, sizeof(EXTLOGPEN) - 5, &extlogpen) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "got %ld\n", GetLastError()); /* Nothing should be filled */ ok(extlogpen.elpPenStyle == 0x77777777, "\n"); ok(extlogpen.elpWidth == 0x77777777, "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN), &extlogpen) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN)-sizeof(DWORD), &extlogpen) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN)-sizeof(DWORD)-1, &extlogpen) == 0, "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN)+2, &extlogpen) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); ok(GetObject(hPen, -5, &extlogpen) == sizeof(EXTLOGPEN)-sizeof(DWORD), "\n"); /* test if the fields are filled correctly */ ok(extlogpen.elpPenStyle == (PS_GEOMETRIC | PS_DASH), "\n"); ok(extlogpen.elpWidth == 5, "\n"); ok(extlogpen.elpBrushStyle == 0, "\n"); ok(extlogpen.elpColor == RGB(1,2,3), "\n"); ok(extlogpen.elpHatch == 22, "\n"); ok(extlogpen.elpNumEntries == 0, "\n"); DeleteObject(hPen); /* A maximum of 16 Styles is allowed */ hPen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 5, &logbrush, 16, (CONST DWORD*)&dwStyles); ok(GetObject(hPen, 0, NULL) == sizeof(EXTLOGPEN) + 15*sizeof(DWORD), "\n"); ok(GetObject(hPen, sizeof(EXTLOGPEN) + 15*sizeof(DWORD), &elpUserStyle) == sizeof(EXTLOGPEN) + 15*sizeof(DWORD), "\n"); for (i = 0; i <= 15; i++) ok(((EXTLOGPEN*)&elpUserStyle)->elpStyleEntry[i] == i, "%d\n", i); DeleteObject(hPen); }
void Test_General(void) { struct { LOGBRUSH logbrush; BYTE additional[600]; } TestStruct; PLOGBRUSH plogbrush; HBRUSH hBrush; HPEN hpen; INT ret; /* Test null pointer and invalid handles */ SetLastError(ERROR_SUCCESS); ok(GetObjectA(0, 0, NULL) == 0, "\n"); ok(GetObjectA((HANDLE)-1, 0, NULL) == 0, "\n"); /* Test invalid habdles of different types */ ok(GetObjectA((HANDLE)0x00380000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); ok(GetObjectA((HANDLE)0x00380000, 10, &TestStruct) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00010000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00020000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00030000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00040000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00060000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00070000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x000B0000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x000C0000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x000D0000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x000E0000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x000F0000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00110000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00120000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00130000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00140000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00150000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)0x00160000, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_SUCCESS, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_DC, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_DC, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_REGION, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_REGION, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_EMF, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_EMF, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_METAFILE, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_METAFILE, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectA((HANDLE)GDI_OBJECT_TYPE_ENHMETAFILE, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); SetLastError(ERROR_SUCCESS); ok(GetObjectW((HANDLE)GDI_OBJECT_TYPE_ENHMETAFILE, 0, NULL) == 0, "\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "\n"); /* Test need of alignment */ SetLastError(ERROR_SUCCESS); hBrush = GetStockObject(WHITE_BRUSH); plogbrush = (PVOID)((ULONG_PTR)&TestStruct.logbrush); ok(GetObject(hBrush, sizeof(LOGBRUSH), plogbrush) == sizeof(LOGBRUSH), "\n"); plogbrush = (PVOID)((ULONG_PTR)&TestStruct.logbrush + 2); ok(GetObject(hBrush, sizeof(LOGBRUSH), plogbrush) == sizeof(LOGBRUSH), "\n"); plogbrush = (PVOID)((ULONG_PTR)&TestStruct.logbrush + 1); //ok(GetObject(hBrush, sizeof(LOGBRUSH), plogbrush) == 0, "\n"); // fails on win7 /* Test invalid buffer */ SetLastError(0xbadbad00); ok(GetObjectA(GetStockObject(WHITE_BRUSH), sizeof(LOGBRUSH), (PVOID)0xc0000000) == 0, "\n"); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(0xbadbad00); ok(GetObjectW(GetStockObject(BLACK_PEN), sizeof(LOGPEN), (PVOID)0xc0000000) == 0, "\n"); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(0xbadbad00); ok(GetObjectW(GetStockObject(21), sizeof(BITMAP), (PVOID)0xc0000000) == 0, "\n"); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(0xbadbad00); ok(GetObjectW(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), (PVOID)0xc0000000) == 0, "\n"); ok(GetLastError() == 0xbadbad00, "wrong error: %ld\n", GetLastError()); SetLastError(ERROR_SUCCESS); _SEH2_TRY { ret = GetObjectA(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), (PVOID)0xc0000000); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ret = -1; } _SEH2_END ok(ret == -1, "should have got an exception\n"); ok(GetObjectW(GetStockObject(SYSTEM_FONT), 0x50000000, &TestStruct) == 356, "\n"); ok(GetObjectW(GetStockObject(WHITE_BRUSH), 0x50000000, &TestStruct) == sizeof(LOGBRUSH), "\n"); /* Test buffer size of 0 */ SetLastError(0xbadbad00); hBrush = CreateSolidBrush(123); ok(hBrush != NULL, "Failed to create brush\n"); ok_long(GetObjectA(hBrush, 0, &TestStruct), sizeof(LOGBRUSH)); ok_err(0xbadbad00); DeleteObject(hBrush); SetLastError(0xbadbad00); hpen = CreatePen(PS_SOLID, 1, 123); ok(hpen != NULL, "Failed to create pen\n"); ok_long(GetObjectA(hpen, 0, &TestStruct), 0); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(0xbadbad00); TestStruct.logbrush.lbStyle = BS_SOLID; TestStruct.logbrush.lbColor = RGB(1,2,3); TestStruct.logbrush.lbHatch = 0; hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID, 1, &TestStruct.logbrush, 0, NULL); ok(hpen != NULL, "Failed to create pen\n"); ok_long(GetObjectA(hpen, 0, &TestStruct), 0); ok((GetLastError() == 0xbadbad00) || (GetLastError() == ERROR_NOACCESS), "wrong error: %ld\n", GetLastError()); SetLastError(0xbadbad00); ok(GetObjectW(GetStockObject(SYSTEM_FONT), 0, &TestStruct) == 0, "\n"); ok_err(0xbadbad00); SetLastError(0xbadbad00); ok(GetObjectW(GetStockObject(21), 0, &TestStruct) == 0, "\n"); ok_err(0xbadbad00); }
static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { PLOT_LOG("rectangle from %d,%d to %d,%d", x0, y0, x1, y1); /* ensure the plot HDC is set */ if (plot_hdc == NULL) { LOG("HDC not set on call to plotters"); return false; } HRGN clipregion = CreateRectRgnIndirect(&plot_clip); if (clipregion == NULL) { return false; } x1++; y1++; COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF); DWORD penstyle = PS_GEOMETRIC | (style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT : (style->stroke_type == PLOT_OP_TYPE_DASH ? PS_DASH : (style->stroke_type == PLOT_OP_TYPE_NONE ? PS_NULL : 0))); LOGBRUSH lb = {BS_SOLID, pencol, 0}; LOGBRUSH lb1 = {BS_SOLID, style->fill_colour, 0}; if (style->fill_type == PLOT_OP_TYPE_NONE) lb1.lbStyle = BS_HOLLOW; HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); if (pen == NULL) { return false; } HGDIOBJ penbak = SelectObject(plot_hdc, (HGDIOBJ) pen); if (penbak == NULL) { DeleteObject(pen); return false; } HBRUSH brush = CreateBrushIndirect(&lb1); if (brush == NULL) { SelectObject(plot_hdc, penbak); DeleteObject(pen); return false; } HGDIOBJ brushbak = SelectObject(plot_hdc, (HGDIOBJ) brush); if (brushbak == NULL) { SelectObject(plot_hdc, penbak); DeleteObject(pen); DeleteObject(brush); return false; } SelectClipRgn(plot_hdc, clipregion); Rectangle(plot_hdc, x0, y0, x1, y1); pen = SelectObject(plot_hdc, penbak); brush = SelectObject(plot_hdc, brushbak); SelectClipRgn(plot_hdc, NULL); DeleteObject(pen); DeleteObject(brush); DeleteObject(clipregion); return true; }
// Function to drag the window splitter window. // Window is dragged by trapping the mousemove message void FrameWindowSplitter::MouseMove(wyBool isinit) { RECT parentrect; POINT curpos, pt; LOGBRUSH lb = {0}; WORD bitmap[] = {0x00AA, 0x0055, 0x00AA, 0x0055, 0x00AA, 0x0055, 0x00AA, 0x0055}; HBITMAP hbitmap; VERIFY(GetClientRect(m_hwndparent, &parentrect)); // Get the screen coordinates and convert it into client points. VERIFY(GetCursorPos (&curpos)); VERIFY(ScreenToClient(m_hwndparent, &curpos)); parentrect.left += 2; parentrect.right -= 2; parentrect.top += 2; parentrect.bottom -= 2; // logic to move the splitter. if(m_isdragged) { pt = curpos; if(isinit == wyTrue) { m_x = pt.x; m_hdc = GetDC(m_hwndparent); hbitmap = CreateBitmap(8, 8, 1, 1, bitmap); lb.lbStyle = BS_PATTERN; lb.lbColor = 0; lb.lbHatch = (ULONG_PTR)hbitmap; m_hpen = ExtCreatePen(PS_GEOMETRIC | PS_ENDCAP_FLAT , 4, &lb, 0, NULL); DeleteBitmap(hbitmap); } if(curpos.x <= parentrect.left) { m_rect.left = parentrect.left; m_leftortoppercent = 0; } else { if(curpos.x <= (parentrect.right - m_width)) { m_rect.left = curpos.x; m_leftortoppercent = ((curpos.x * 100 / parentrect.right * 100)/ 100); } else { m_rect.left = (parentrect.right - m_width); m_leftortoppercent = 100; } } DrawTrackerLine(); if(isinit == wyTrue) { return; } m_x = pt.x; DrawTrackerLine(); } }
static void test_logpen(void) { static const struct { UINT style; INT width; COLORREF color; UINT ret_style; INT ret_width; COLORREF ret_color; } pen[] = { { PS_SOLID, -123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { PS_SOLID, 0, RGB(0x12,0x34,0x56), PS_SOLID, 0, RGB(0x12,0x34,0x56) }, { PS_SOLID, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { PS_DASH, 123, RGB(0x12,0x34,0x56), PS_DASH, 123, RGB(0x12,0x34,0x56) }, { PS_DOT, 123, RGB(0x12,0x34,0x56), PS_DOT, 123, RGB(0x12,0x34,0x56) }, { PS_DASHDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOT, 123, RGB(0x12,0x34,0x56) }, { PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56) }, { PS_NULL, -123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 }, { PS_NULL, 123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 }, { PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56), PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56) }, { PS_USERSTYLE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { PS_ALTERNATE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 9, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 10, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 11, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 13, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 14, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, { 15, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }, }; INT i, size; HPEN hpen; LOGPEN lp; EXTLOGPEN elp; LOGBRUSH lb; DWORD_PTR unset_hatch; DWORD obj_type, user_style[2] = { 0xabc, 0xdef }; char elp_buffer[128]; EXTLOGPEN *ext_pen = (EXTLOGPEN *)elp_buffer; DWORD *ext_style = ext_pen->elpStyleEntry; for (i = 0; i < sizeof(pen)/sizeof(pen[0]); i++) { trace("%d: testing style %u\n", i, pen[i].style); /********************** cosmetic pens **********************/ /* CreatePenIndirect behaviour */ lp.lopnStyle = pen[i].style, lp.lopnWidth.x = pen[i].width; lp.lopnWidth.y = 11; /* just in case */ lp.lopnColor = pen[i].color; SetLastError(0xdeadbeef); hpen = CreatePenIndirect(&lp); if(hpen == 0 && GetLastError() == ERROR_INVALID_PARAMETER) { win_skip("No support for pen style %u (%d)\n", pen[i].style, i); continue; } obj_type = GetObjectType(hpen); ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type); memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp), &lp); ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError()); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); DeleteObject(hpen); /* CreatePen behaviour */ SetLastError(0xdeadbeef); hpen = CreatePen(pen[i].style, pen[i].width, pen[i].color); ok(hpen != 0, "CreatePen error %d\n", GetLastError()); obj_type = GetObjectType(hpen); ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type); /* check what's the real size of the object */ size = GetObject(hpen, 0, NULL); ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError()); /* ask for truncated data */ memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp.lopnStyle), &lp); ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError()); /* see how larger buffer sizes are handled */ memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp) * 4, &lp); ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError()); /* see how larger buffer sizes are handled */ memset(&elp, 0xb0, sizeof(elp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp) * 2, &elp); ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError()); memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp), &lp); ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError()); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); memset(&elp, 0xb0, sizeof(elp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp), &elp); /* for some reason XP differentiates PS_NULL here */ if (pen[i].style == PS_NULL) { ok(hpen == GetStockObject(NULL_PEN), "hpen should be a stock NULL_PEN\n"); ok(size == sizeof(EXTLOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); ok(elp.elpPenStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, elp.elpPenStyle); ok(elp.elpWidth == 0, "expected 0, got %u\n", elp.elpWidth); ok(elp.elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, elp.elpColor); ok(elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %u\n", elp.elpBrushStyle); ok(elp.elpHatch == 0, "expected 0, got %p\n", (void *)elp.elpHatch); ok(elp.elpNumEntries == 0, "expected 0, got %x\n", elp.elpNumEntries); } else { ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); memcpy(&lp, &elp, sizeof(lp)); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); } DeleteObject(hpen); /********** cosmetic pens created by ExtCreatePen ***********/ lb.lbStyle = BS_SOLID; lb.lbColor = pen[i].color; lb.lbHatch = HS_CROSS; /* just in case */ SetLastError(0xdeadbeef); hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 2, user_style); if (pen[i].style != PS_USERSTYLE) { ok(hpen == 0, "ExtCreatePen should fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong last error value %d\n", GetLastError()); SetLastError(0xdeadbeef); hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 0, NULL); if (pen[i].style != PS_NULL) { ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong last error value %d\n", GetLastError()); SetLastError(0xdeadbeef); hpen = ExtCreatePen(pen[i].style, 1, &lb, 0, NULL); } } else { ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong last error value %d\n", GetLastError()); SetLastError(0xdeadbeef); hpen = ExtCreatePen(pen[i].style, 1, &lb, 2, user_style); } if (pen[i].style == PS_INSIDEFRAME) { /* This style is applicable only for geometric pens */ ok(hpen == 0, "ExtCreatePen should fail\n"); goto test_geometric_pens; } if (pen[i].style > PS_ALTERNATE) { ok(hpen == 0, "ExtCreatePen should fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong last error value %d\n", GetLastError()); goto test_geometric_pens; } ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError()); obj_type = GetObjectType(hpen); /* for some reason XP differentiates PS_NULL here */ if (pen[i].style == PS_NULL) { ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type); ok(hpen == GetStockObject(NULL_PEN), "hpen should be a stock NULL_PEN\n"); } else ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type); /* check what's the real size of the object */ SetLastError(0xdeadbeef); size = GetObject(hpen, 0, NULL); switch (pen[i].style) { case PS_NULL: ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); break; case PS_USERSTYLE: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry[2] ), "GetObject returned %d, error %d\n", size, GetLastError()); break; default: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "GetObject returned %d, error %d\n", size, GetLastError()); break; } /* ask for truncated data */ memset(&elp, 0xb0, sizeof(elp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp.elpPenStyle), &elp); ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError()); /* see how larger buffer sizes are handled */ memset(elp_buffer, 0xb0, sizeof(elp_buffer)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp_buffer), elp_buffer); switch (pen[i].style) { case PS_NULL: ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); memcpy(&lp, ext_pen, sizeof(lp)); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); /* for PS_NULL it also works this way */ memset(&elp, 0xb0, sizeof(elp)); memset(&unset_hatch, 0xb0, sizeof(unset_hatch)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp), &elp); ok(size == sizeof(EXTLOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == unset_hatch, "expected 0xb0b0b0b0, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 0xb0b0b0b0, "expected 0xb0b0b0b0, got %x\n", ext_pen->elpNumEntries); break; case PS_USERSTYLE: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry[2] ), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 2, "expected 0, got %x\n", ext_pen->elpNumEntries); ok(ext_style[0] == 0xabc, "expected 0xabc, got %x\n", ext_style[0]); ok(ext_style[1] == 0xdef, "expected 0xdef, got %x\n", ext_style[1]); break; default: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 0, "expected 0, got %x\n", ext_pen->elpNumEntries); break; } ok(ext_pen->elpPenStyle == pen[i].style, "expected %x, got %x\n", pen[i].style, ext_pen->elpPenStyle); ok(ext_pen->elpWidth == 1, "expected 1, got %x\n", ext_pen->elpWidth); ok(ext_pen->elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, ext_pen->elpColor); ok(ext_pen->elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen->elpBrushStyle); DeleteObject(hpen); test_geometric_pens: /********************** geometric pens **********************/ lb.lbStyle = BS_SOLID; lb.lbColor = pen[i].color; lb.lbHatch = HS_CROSS; /* just in case */ SetLastError(0xdeadbeef); hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 2, user_style); if (pen[i].style != PS_USERSTYLE) { ok(hpen == 0, "ExtCreatePen should fail\n"); SetLastError(0xdeadbeef); hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 0, NULL); } if (pen[i].style == PS_ALTERNATE) { /* This style is applicable only for cosmetic pens */ ok(hpen == 0, "ExtCreatePen should fail\n"); continue; } if (pen[i].style > PS_ALTERNATE) { ok(hpen == 0, "ExtCreatePen should fail\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong last error value %d\n", GetLastError()); continue; } ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError()); obj_type = GetObjectType(hpen); /* for some reason XP differentiates PS_NULL here */ if (pen[i].style == PS_NULL) ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type); else ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type); /* check what's the real size of the object */ size = GetObject(hpen, 0, NULL); switch (pen[i].style) { case PS_NULL: ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); break; case PS_USERSTYLE: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry[2] ), "GetObject returned %d, error %d\n", size, GetLastError()); break; default: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "GetObject returned %d, error %d\n", size, GetLastError()); break; } /* ask for truncated data */ memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp.lopnStyle), &lp); ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError()); memset(&lp, 0xb0, sizeof(lp)); SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(lp), &lp); /* for some reason XP differentiates PS_NULL here */ if (pen[i].style == PS_NULL) { ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); } else /* XP doesn't set last error here */ ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/, "GetObject should fail: size %d, error %d\n", size, GetLastError()); memset(elp_buffer, 0xb0, sizeof(elp_buffer)); SetLastError(0xdeadbeef); /* buffer is too small for user styles */ size = GetObject(hpen, sizeof(EXTLOGPEN), elp_buffer); switch (pen[i].style) { case PS_NULL: ok(size == sizeof(EXTLOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == 0, "expected 0, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 0, "expected 0, got %x\n", ext_pen->elpNumEntries); /* for PS_NULL it also works this way */ SetLastError(0xdeadbeef); size = GetObject(hpen, sizeof(elp_buffer), &lp); ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError()); ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle); ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x); ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y); ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor); break; case PS_USERSTYLE: ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/, "GetObject should fail: size %d, error %d\n", size, GetLastError()); size = GetObject(hpen, sizeof(elp_buffer), elp_buffer); ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry[2] ), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 2, "expected 0, got %x\n", ext_pen->elpNumEntries); ok(ext_style[0] == 0xabc, "expected 0xabc, got %x\n", ext_style[0]); ok(ext_style[1] == 0xdef, "expected 0xdef, got %x\n", ext_style[1]); break; default: ok(size == FIELD_OFFSET( EXTLOGPEN, elpStyleEntry ), "GetObject returned %d, error %d\n", size, GetLastError()); ok(ext_pen->elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen->elpHatch); ok(ext_pen->elpNumEntries == 0, "expected 0, got %x\n", ext_pen->elpNumEntries); break; } /* for some reason XP differentiates PS_NULL here */ if (pen[i].style == PS_NULL) ok(ext_pen->elpPenStyle == pen[i].ret_style, "expected %x, got %x\n", pen[i].ret_style, ext_pen->elpPenStyle); else { ok(ext_pen->elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %x\n", PS_GEOMETRIC | pen[i].style, ext_pen->elpPenStyle); } if (pen[i].style == PS_NULL) ok(ext_pen->elpWidth == 0, "expected 0, got %x\n", ext_pen->elpWidth); else ok(ext_pen->elpWidth == pen[i].ret_width, "expected %u, got %x\n", pen[i].ret_width, ext_pen->elpWidth); ok(ext_pen->elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, ext_pen->elpColor); ok(ext_pen->elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen->elpBrushStyle); DeleteObject(hpen); } }
static void test_GetCurrentObject(void) { DWORD type; HPEN hpen; HBRUSH hbrush; HPALETTE hpal; HFONT hfont; HBITMAP hbmp; HRGN hrgn; HDC hdc; HCOLORSPACE hcs; HGDIOBJ hobj; LOGBRUSH lb; LOGCOLORSPACEA lcs; hdc = CreateCompatibleDC(0); assert(hdc != 0); type = GetObjectType(hdc); ok(type == OBJ_MEMDC, "GetObjectType returned %u\n", type); hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30)); assert(hpen != 0); SelectObject(hdc, hpen); hobj = GetCurrentObject(hdc, OBJ_PEN); ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj); hobj = GetCurrentObject(hdc, OBJ_EXTPEN); ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj); hbrush = CreateSolidBrush(RGB(10, 20, 30)); assert(hbrush != 0); SelectObject(hdc, hbrush); hobj = GetCurrentObject(hdc, OBJ_BRUSH); ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj); hpal = CreateHalftonePalette(hdc); assert(hpal != 0); SelectPalette(hdc, hpal, FALSE); hobj = GetCurrentObject(hdc, OBJ_PAL); ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj); hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "MS Sans Serif"); assert(hfont != 0); SelectObject(hdc, hfont); hobj = GetCurrentObject(hdc, OBJ_FONT); ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj); hbmp = CreateBitmap(100, 100, 1, 1, NULL); assert(hbmp != 0); SelectObject(hdc, hbmp); hobj = GetCurrentObject(hdc, OBJ_BITMAP); ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj); assert(GetObjectA(hbrush, sizeof(lb), &lb) == sizeof(lb)); hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE | PS_JOIN_BEVEL, 10, &lb, 0, NULL); assert(hpen != 0); SelectObject(hdc, hpen); hobj = GetCurrentObject(hdc, OBJ_PEN); ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj); hobj = GetCurrentObject(hdc, OBJ_EXTPEN); ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj); hcs = GetColorSpace(hdc); if (hcs) { trace("current color space is not NULL\n"); ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n"); hcs = CreateColorSpaceA(&lcs); ok(hcs != 0, "CreateColorSpace failed\n"); SelectObject(hdc, hcs); hobj = GetCurrentObject(hdc, OBJ_COLORSPACE); ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj); } hrgn = CreateRectRgn(1, 1, 100, 100); assert(hrgn != 0); SelectObject(hdc, hrgn); hobj = GetCurrentObject(hdc, OBJ_REGION); ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj); DeleteDC(hdc); }
static void test_ps_userstyle(void) { static DWORD style[17] = {0, 2, 0, 4, 5, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 17}; static DWORD bad_style[5] = {0, 0, 0, 0, 0}; static DWORD bad_style2[5] = {4, 7, 8, 3, -1}; LOGBRUSH lb; HPEN pen; INT size, i; struct { EXTLOGPEN elp; DWORD style_data[15]; } ext_pen; lb.lbColor = 0x00ff0000; lb.lbStyle = BS_SOLID; lb.lbHatch = 0; pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 3, NULL); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 0, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect2(0xdeadbeef, ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 17, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, -1, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(0xdeadbeef, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style2); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 16, style); ok(pen != 0, "ExtCreatePen should not fail\n"); size = GetObject(pen, sizeof(ext_pen), &ext_pen); expect(FIELD_OFFSET(EXTLOGPEN,elpStyleEntry[16]), size); for(i = 0; i < 16; i++) expect(style[i], ext_pen.elp.elpStyleEntry[i]); DeleteObject(pen); }
static void test_ps_userstyle(void) { static DWORD style[17] = {0, 2, 0, 4, 5, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 17}; static DWORD bad_style[5] = {0, 0, 0, 0, 0}; static DWORD bad_style2[5] = {4, 7, 8, 3, -1}; LOGBRUSH lb; HPEN pen; INT size, i; char buffer[offsetof(EXTLOGPEN, elpStyleEntry) + 16 * sizeof(DWORD)]; EXTLOGPEN *ext_pen = (EXTLOGPEN *)buffer; lb.lbColor = 0x00ff0000; lb.lbStyle = BS_SOLID; lb.lbHatch = 0; pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 3, NULL); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 0, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect2(0xdeadbeef, ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 17, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, -1, style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(0xdeadbeef, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style2); ok(pen == 0, "ExtCreatePen should fail\n"); expect(ERROR_INVALID_PARAMETER, GetLastError()); DeleteObject(pen); SetLastError(0xdeadbeef); pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 16, style); ok(pen != 0, "ExtCreatePen should not fail\n"); size = GetObjectW(pen, sizeof(buffer), ext_pen); ok(size == offsetof(EXTLOGPEN, elpStyleEntry[16]), "wrong size %d\n", size); for(i = 0; i < 16; i++) expect(style[i], ext_pen->elpStyleEntry[i]); DeleteObject(pen); }
static HPEN SetUpGraphicsPort( GC gc) { DWORD style; if (gc->line_style == LineOnOffDash) { unsigned char *p = (unsigned char *) &(gc->dashes); /* pointer to the dash-list */ /* * Below is a simple translation of serveral dash patterns to valid * windows pen types. Far from complete, but I don't know how to do it * better. Any ideas: <mailto:[email protected]> */ if (p[1] && p[2]) { if (!p[3] || p[4]) { style = PS_DASHDOTDOT; /* -.. */ } else { style = PS_DASHDOT; /* -. */ } } else { if (p[0] > (4 * gc->line_width)) { style = PS_DASH; /* - */ } else { style = PS_DOT; /* . */ } } } else { style = PS_SOLID; } if (gc->line_width < 2) { return CreatePen((int) style, gc->line_width, gc->foreground); } else { LOGBRUSH lb; lb.lbStyle = BS_SOLID; lb.lbColor = gc->foreground; lb.lbHatch = 0; style |= PS_GEOMETRIC; switch (gc->cap_style) { case CapNotLast: case CapButt: style |= PS_ENDCAP_FLAT; break; case CapRound: style |= PS_ENDCAP_ROUND; break; default: style |= PS_ENDCAP_SQUARE; break; } switch (gc->join_style) { case JoinMiter: style |= PS_JOIN_MITER; break; case JoinRound: style |= PS_JOIN_ROUND; break; default: style |= PS_JOIN_BEVEL; break; } return ExtCreatePen(style, (DWORD) gc->line_width, &lb, 0, NULL); } }
static bool rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { x1++; y1++; x0 = MAX(x0, 0); y0 = MAX(y0, 0); if (!((current_gui == NULL) || (thumbnail))) { x1 = MIN(x1, gui_window_width(current_gui)); y1 = MIN(y1, gui_window_height(current_gui)); } #if NSWS_PLOT_DEBUG LOG(("rectangle from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1, thumbnail)); #endif HDC hdc = doublebuffering ? bufferdc : GetDC(current_hwnd); if (hdc == NULL) { return false; } RECT *clipr = gui_window_clip_rect(current_gui); if (clipr == NULL) clipr = &localhistory_clip; HRGN clipregion = CreateRectRgnIndirect(clipr); if (clipregion == NULL) { if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } COLORREF pencol = (DWORD)(style->stroke_colour & 0x00FFFFFF); DWORD penstyle = PS_GEOMETRIC | (style->stroke_type == PLOT_OP_TYPE_DOT ? PS_DOT : (style->stroke_type == PLOT_OP_TYPE_DASH ? PS_DASH : (style->stroke_type == PLOT_OP_TYPE_NONE ? PS_NULL : 0))); LOGBRUSH lb = {BS_SOLID, pencol, 0}; LOGBRUSH lb1 = {BS_SOLID, style->fill_colour, 0}; if (style->fill_type == PLOT_OP_TYPE_NONE) lb1.lbStyle = BS_HOLLOW; HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); if (pen == NULL) { DeleteObject(clipregion); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } HGDIOBJ penbak = SelectObject(hdc, (HGDIOBJ) pen); if (penbak == NULL) { DeleteObject(clipregion); DeleteObject(pen); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } HBRUSH brush = CreateBrushIndirect(&lb1); if (brush == NULL) { DeleteObject(clipregion); SelectObject(hdc, penbak); DeleteObject(pen); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } HGDIOBJ brushbak = SelectObject(hdc, (HGDIOBJ) brush); if (brushbak == NULL) { DeleteObject(clipregion); SelectObject(hdc, penbak); DeleteObject(pen); DeleteObject(brush); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } RECT r; r.left = x0; r.top = y0; r.right = x1; r.bottom = y1; SelectClipRgn(hdc, clipregion); Rectangle(hdc, x0, y0, x1, y1); SelectClipRgn(hdc, NULL); /* ValidateRect(current_hwnd, &r); */ pen = SelectObject(hdc, penbak); brush = SelectObject(hdc, brushbak); DeleteObject(clipregion); DeleteObject(pen); DeleteObject(brush); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return true; }
static HPEN CreatePenFromStyle(COLORREF cl, int nLineWidth, int nLineStyle, DWORD dwCaps) { LOGBRUSH lb; lb.lbStyle = BS_SOLID; lb.lbColor = cl; lb.lbHatch = 0; switch(nLineStyle) { case 0: default: return ExtCreatePen(PS_GEOMETRIC | PS_SOLID | dwCaps, MAX(1, nLineWidth), &lb, 0, NULL); case 1: return ExtCreatePen(PS_COSMETIC | PS_ALTERNATE | dwCaps, MAX(1, 1), &lb, 0, NULL); case 2: return ExtCreatePen(PS_COSMETIC | PS_DOT | dwCaps, MAX(1, 1), &lb, 0, NULL); case 3: // Custom style { DWORD dwStyle[] = {2, 1}; return ExtCreatePen(PS_COSMETIC | PS_USERSTYLE | dwCaps, MAX(1, 1), &lb, 2, (CONST DWORD *)&dwStyle); } case 4: // Custom style { DWORD dwStyle[] = {2, 2}; return ExtCreatePen(PS_COSMETIC | PS_USERSTYLE | dwCaps, MAX(1, 1), &lb, 2, (CONST DWORD *)&dwStyle); } case 5: // Custom style { DWORD dwStyle[] = {3, 1}; return ExtCreatePen(PS_COSMETIC | PS_USERSTYLE | dwCaps, MAX(1, 1), &lb, 2, (CONST DWORD *)&dwStyle); } case 6: // Custom style { DWORD dwStyle[] = {4, 1}; return ExtCreatePen(PS_COSMETIC | PS_USERSTYLE | dwCaps, MAX(1, 1), &lb, 2, (CONST DWORD *)&dwStyle); } case 7: return ExtCreatePen(PS_COSMETIC | PS_DASH | dwCaps, MAX(1, 1), &lb, 0, NULL); case 8: return ExtCreatePen(PS_COSMETIC | PS_DASHDOT | dwCaps, MAX(1, 1), &lb, 0, NULL); case 9: return ExtCreatePen(PS_COSMETIC | PS_DASHDOTDOT | dwCaps, MAX(1, 1), &lb, 0, NULL); } }
static bool line(int x0, int y0, int x1, int y1, const plot_style_t *style) { #if NSWS_PLOT_DEBUG LOG(("ligne from %d,%d to %d,%d thumbnail %d", x0, y0, x1, y1, thumbnail)); #endif RECT *clipr = gui_window_clip_rect(current_gui); if (clipr == NULL) clipr = &localhistory_clip; HRGN clipregion = CreateRectRgnIndirect(clipr); if (clipregion == NULL) { return false; } HDC hdc = doublebuffering ? bufferdc : GetDC(current_hwnd); if (hdc == NULL) { DeleteObject(clipregion); return false; } COLORREF col = (DWORD)(style->stroke_colour & 0x00FFFFFF); /* windows 0x00bbggrr */ DWORD penstyle = PS_GEOMETRIC | ((style->stroke_type == PLOT_OP_TYPE_DOT) ? PS_DOT : (style->stroke_type == PLOT_OP_TYPE_DASH) ? PS_DASH: 0); LOGBRUSH lb = {BS_SOLID, col, 0}; HPEN pen = ExtCreatePen(penstyle, style->stroke_width, &lb, 0, NULL); if (pen == NULL) { DeleteObject(clipregion); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } HGDIOBJ bak = SelectObject(hdc, (HGDIOBJ) pen); if (bak == NULL) { DeleteObject(pen); DeleteObject(clipregion); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return false; } RECT r; r.left = x0; r.top = y0; r.right = x1; r.bottom = y1; SelectClipRgn(hdc, clipregion); MoveToEx(hdc, x0, y0, (LPPOINT) NULL); LineTo(hdc, x1, y1); SelectClipRgn(hdc, NULL); /* ValidateRect(current_hwnd, &r); */ pen = SelectObject(hdc, bak); DeleteObject(pen); DeleteObject(clipregion); if (!doublebuffering) ReleaseDC(current_hwnd, hdc); return true; }
INT Test_NtGdiSelectPen(PTESTINFO pti) { HDC hDC; HPEN hPen, hOldPen; LOGBRUSH logbrush; hDC = GetDC(NULL); ASSERT(hDC); hPen = GetStockObject(WHITE_PEN); /* Test NULL DC */ SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen(NULL, hPen); TEST(hOldPen == NULL); TEST(GetLastError() == ERROR_SUCCESS); /* Test invalid DC */ SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen((HDC)((ULONG_PTR)hDC & 0x0000ffff), hPen); TEST(hOldPen == NULL); TEST(GetLastError() == ERROR_SUCCESS); /* Test NULL pen */ SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen(hDC, NULL); TEST(hOldPen == NULL); TEST(GetLastError() == ERROR_SUCCESS); /* Test invalid pen */ SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen(hDC, (HPEN)((ULONG_PTR)hPen & 0x0000ffff)); TEST(hOldPen == NULL); TEST(GetLastError() == ERROR_SUCCESS); /* Test valid pen */ SelectObject(hDC, GetStockObject(BLACK_PEN)); SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen(hDC, hPen); TEST(hOldPen == GetStockObject(BLACK_PEN)); hOldPen = NtGdiSelectPen(hDC, hOldPen); TEST(hOldPen == hPen); TEST(GetLastError() == ERROR_SUCCESS); /* Test extpen */ SetLastError(ERROR_SUCCESS); logbrush.lbStyle = BS_SOLID; logbrush.lbColor = RGB(0x12,0x34,0x56); hPen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &logbrush, 0, NULL); ASSERT(hPen); hOldPen = NtGdiSelectPen(hDC, hPen); TEST(hOldPen != NULL); hOldPen = NtGdiSelectPen(hDC, hOldPen); TEST(hOldPen == hPen); TEST(GetLastError() == ERROR_SUCCESS); /* Test deleting pen */ SetLastError(ERROR_SUCCESS); hOldPen = NtGdiSelectPen(hDC, hPen); TEST(DeleteObject(hPen) == 1); hOldPen = NtGdiSelectPen(hDC, hOldPen); TEST(hOldPen == hPen); TEST(GetLastError() == ERROR_SUCCESS); /* Test that fallback pen is BLACK_PEN */ DeleteDC(hDC); return APISTATUS_NORMAL; }
HPEN EmfPaintEngine::convertPen(const QPen& pen) { INT style = PS_NULL; switch (pen.style()){ case Qt::SolidLine: style = PS_SOLID; break; case Qt::DashLine: style = PS_DASH; break; case Qt::DotLine: style = PS_DOT; break; case Qt::DashDotLine: style = PS_DASHDOT; break; case Qt::DashDotDotLine: style = PS_DASHDOTDOT; break; default: break; } INT capStyle = PS_ENDCAP_FLAT; switch (pen.capStyle()){ case Qt::FlatCap: break; case Qt::SquareCap: capStyle = PS_ENDCAP_SQUARE; break; case Qt::RoundCap: capStyle = PS_ENDCAP_ROUND; break; default: break; } INT joinStyle = PS_JOIN_MITER; switch (pen.joinStyle()){ case Qt::MiterJoin: break; case Qt::BevelJoin: joinStyle = PS_JOIN_BEVEL; break; case Qt::RoundJoin: joinStyle = PS_JOIN_ROUND; break; case Qt::SvgMiterJoin: joinStyle = PS_JOIN_MITER; break; default: break; } LOGBRUSH lbrush = {BS_SOLID, RGB(pen.color().red(),pen.color().green(),pen.color().blue()), 0}; return ExtCreatePen(PS_GEOMETRIC | style | capStyle | joinStyle, pen.width(), &lbrush, 0, NULL); }