Exemplo n.º 1
0
Arquivo: UTL.C Projeto: Fahrni/T3
void nDrawConcaveFrame( HDC hDestDC, RECT rc )
{
#ifdef DEBUGGING
// the below two statements are for debugging on my mono monitor.
    static LOGPEN lpLtGray = { PS_SOLID, 1, 1, clrBLACK },
                  lpWhite  = { PS_SOLID, 1, 1, clrBLACK };
#else
    static LOGPEN lpLtGray = { PS_SOLID, 1, 1, clrDKGRAY },
                  lpWhite  = { PS_SOLID, 1, 1, clrWHITE };
#endif

    HPEN hLtGray, hWhite;

    hLtGray = CreatePenIndirect( &lpLtGray );
    hWhite  = CreatePenIndirect( &lpWhite );

    MoveTo( hDestDC, rc.right, rc.top );

    // Paint the top and left side lines, light gray.
    SelectObject( hDestDC, hLtGray );
    LineTo( hDestDC, rc.left, rc.top );
    LineTo( hDestDC, rc.left, rc.bottom );

    // Paint the bottom and right side lines, white.
    SelectObject( hDestDC, hWhite );
    LineTo( hDestDC, rc.right, rc.bottom );
    LineTo( hDestDC, rc.right, rc.top );

    DeleteObject( hLtGray );
    DeleteObject( hWhite );

    // Rectangle( hDestDC, rc.left, rc.top, rc.right, rc.bottom );

}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
// -----------------------------------------------------------------------
// Changes the Color to use when rendering onto the canvas.
// -----------------------------------------------------------------------
void MWcanvas16::color(const Color* c)
{
    // ---- render anything that was buffered ----
    flush();

    // ---- reference new color ----
    Resource::ref(c);
    Resource::unref(lg_color_);
    lg_color_ = c;

    // ---- set new pen color ----
    pen_stats_.lopnColor = c->rep()->msColor();
    pen_ = CreatePenIndirect(&pen_stats_);
    DeleteObject( SelectObject(drawable_, pen_));

    // ----  set new brush color ----
    if (c->rep()->stipple)
    {
        // THIS NEEDS WORK
        //
        // brush_stats_.lbStyle = BS_PATTERN;
        // brush_stats_.lbHatch = (long) c->rep()->stipple->hbm_;
    }
    else
    {
        brush_stats_.lbStyle = BS_SOLID;
        brush_stats_.lbColor = c->rep()->msColor();
    }
    brush_ = CreateBrushIndirect(&brush_stats_);
    DeleteObject( SelectObject(drawable_, brush_));

    // ---- set text color ----
    SetTextColor(drawable_, c->rep()->msColor());

    // ---- set color operation ----
    ColorRep* r = c->rep();
    if (r->op == Color::Copy)
    {
        SetROP2(drawable_, R2_COPYPEN);
    }
    else if (r->op == Color::Xor)
    {
//		SetROP2(drawable_, R2_XORPEN);
        SetROP2(drawable_, 6);   // this is insane, but...
    }
    else if (r->op == Color::Invisible)
    {
        SetROP2(drawable_, R2_NOP);
    }
    else
    {
        // ----- unrecognized color mode ----
        MWassert(0);
    }
}
Exemplo n.º 4
0
// -----------------------------------------------------------------------
// Initialize for begin of paint sequence... the display context is now
// valid.  Note that this isn't necessarily a result of the WM_PAINT
// message!
// -----------------------------------------------------------------------
void MWcanvas16::beginPaint(
    HDC hdc,							// device context to use
    const RECT& r)             			// area of update region
{
    MWcanvas::beginPaint(hdc, r);

    // ---- establish default pen and brush ----
    pen_ = CreatePenIndirect(&pen_stats_);
    old_pen_ = (HPEN) SelectObject(drawable_, pen_);
    brush_ = CreateBrushIndirect(&brush_stats_);
    old_brush_ = (HBRUSH) SelectObject(drawable_, brush_);
}
Exemplo n.º 5
0
Arquivo: pen.c Projeto: Sunmonds/wine
/***********************************************************************
 *           CreatePen    (GDI32.@)
 */
HPEN WINAPI CreatePen( INT style, INT width, COLORREF color )
{
    LOGPEN logpen;

    TRACE("%d %d %06x\n", style, width, color );

    logpen.lopnStyle = style;
    logpen.lopnWidth.x = width;
    logpen.lopnWidth.y = 0;
    logpen.lopnColor = color;

    return CreatePenIndirect( &logpen );
}
Exemplo n.º 6
0
Shape::Shape(const POINT u, const POINT v
             ,const LOGPEN& lp, const LOGBRUSH& lb) // Passing Brush and Pen as reference
{
    mPt0.x = u.x;
    mPt0.y = u.y;
    mPt1.x = u.x;
    mPt1.y = u.y;

    mhPen		 = CreatePenIndirect(&lp);
    mhBrush		 = CreateBrushIndirect(&lb);

    mhOldBrush	 = 0;
    mhOldPen	 = 0;
}
Exemplo n.º 7
0
//SHAPE CLASS IMPLEMENTATION
Shape::Shape (const POINT u, const POINT v,
	const LOGPEN& lp, const LOGBRUSH & lb)
{

	mPt0.x = u.x;
	mPt0.y = u.y;
	mPt1.x = v.x;
	mPt1.y = v.y;
	mhPen  = CreatePenIndirect(&lp);
	mhBrush = CreateBrushIndirect(&lb);


	mhOldPen = 0;
	mhOldBrush = 0;
	

}
Exemplo n.º 8
0
/******************************************************************
 *         EMFDRV_SetDCPenColor
 */
COLORREF EMFDRV_SetDCPenColor( PHYSDEV dev, COLORREF color )
{
    EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
    EMRSELECTOBJECT emr;
    DWORD index;
    LOGPEN logpen = { PS_SOLID, { 0, 0 }, color };

    if (GetCurrentObject( dev->hdc, OBJ_PEN ) != GetStockObject( DC_PEN )) return color;

    if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
    if (!(physDev->dc_pen = CreatePenIndirect( &logpen ))) return CLR_INVALID;
    if (!(index = EMFDRV_CreatePenIndirect(dev, physDev->dc_pen))) return CLR_INVALID;
    GDI_hdc_using_object( physDev->dc_pen, dev->hdc );
    emr.emr.iType = EMR_SELECTOBJECT;
    emr.emr.nSize = sizeof(emr);
    emr.ihObject = index;
    return EMFDRV_WriteRecord( dev, &emr.emr ) ? color : CLR_INVALID;
}
Exemplo n.º 9
0
// -----------------------------------------------------------------------
// Changes the brush to use when rendering a path
// -----------------------------------------------------------------------
void MWcanvas16::brush(const Brush* b)
{
    if (b != nil && b != lg_brush_)
    {
        // ---- reference the new brush ----
        Resource::ref((const Resource*) b);
        Resource::unref((const Resource*) lg_brush_);
        lg_brush_ = b;

        // ---- get ready to create a new pen ----
        BrushRep& br = * b->rep(nil);
        pen_stats_.lopnStyle = (br.dashCount) ? PS_DASH : PS_SOLID;

        pen_stats_.lopnWidth.x = COORD2TWIPS(br.penWidth);

        // ---- establish the new pen ----
        pen_ = CreatePenIndirect(&pen_stats_);
        DeleteObject( SelectObject(drawable_, pen_));

    }
}
Exemplo n.º 10
0
/***********************************************************************
 *           GDI_Init
 *
 * GDI initialization.
 */
BOOL GDI_Init(void)
{
    HINSTANCE16 instance;
    HKEY hkey;
    GDIOBJHDR *ptr;
    int i;


    create_gdi_syslevel_cs();

    initialize_driver();


    if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Tweak.Fonts", &hkey))
        hkey = 0;

    /* create GDI heap */
    if ((instance = LoadLibrary16( "GDI.EXE" )) < 32) return FALSE;
    GDI_HeapSel = instance | 7;

    /* create stock objects */
    stock_objects[WHITE_BRUSH]  = CreateBrushIndirect( &WhiteBrush );
    stock_objects[LTGRAY_BRUSH] = CreateBrushIndirect( &LtGrayBrush );
    stock_objects[GRAY_BRUSH]   = CreateBrushIndirect( &GrayBrush );
    stock_objects[DKGRAY_BRUSH] = CreateBrushIndirect( &DkGrayBrush );
    stock_objects[BLACK_BRUSH]  = CreateBrushIndirect( &BlackBrush );
    stock_objects[NULL_BRUSH]   = CreateBrushIndirect( &NullBrush );

    stock_objects[WHITE_PEN]    = CreatePenIndirect( &WhitePen );
    stock_objects[BLACK_PEN]    = CreatePenIndirect( &BlackPen );
    stock_objects[NULL_PEN]     = CreatePenIndirect( &NullPen );

    stock_objects[DEFAULT_PALETTE] = PALETTE_Init();
    stock_objects[DEFAULT_BITMAP]  = CreateBitmap( 1, 1, 1, 1, NULL );

    stock_objects[OEM_FIXED_FONT]      = create_stock_font( "OEMFixed", &OEMFixedFont, hkey );
    stock_objects[ANSI_FIXED_FONT]     = create_stock_font( "AnsiFixed", &AnsiFixedFont, hkey );
    stock_objects[ANSI_VAR_FONT]       = create_stock_font( "AnsiVar", &AnsiVarFont, hkey );
    stock_objects[SYSTEM_FONT]         = create_stock_font( "System", &SystemFont, hkey );
    stock_objects[DEVICE_DEFAULT_FONT] = create_stock_font( "DeviceDefault", &DeviceDefaultFont, hkey );
    stock_objects[SYSTEM_FIXED_FONT]   = create_stock_font( "SystemFixed", &SystemFixedFont, hkey );
    stock_objects[DEFAULT_GUI_FONT]    = create_stock_font( "DefaultGui", &DefaultGuiFont, hkey );


    /* clear the NOSYSTEM bit on all stock objects*/
    for (i = 0; i < NB_STOCK_OBJECTS; i++)
    {
        if (!stock_objects[i])
        {
            if (i == 9) continue;  /* there's no stock object 9 */
            ERR( "could not create stock object %d\n", i );
            return FALSE;
        }
        ptr = GDI_GetObjPtr( stock_objects[i], MAGIC_DONTCARE );
        ptr->wMagic &= ~OBJECT_NOSYSTEM;
        GDI_ReleaseObj( stock_objects[i] );
    }

    if (hkey) RegCloseKey( hkey );

    WineEngInit();

    return TRUE;
}
Exemplo n.º 11
0
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);
    }
}
Exemplo n.º 12
0
//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND	- 处理应用程序菜单
//  WM_PAINT	- 绘制主窗口
//  WM_DESTROY	- 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	LOGBRUSH brush;
	brush.lbStyle = BS_NULL;
	HBRUSH hBrush = CreateBrushIndirect(&brush);

	LOGPEN pen;
	POINT penWidth;
	penWidth.x = 2;
	penWidth.y = 2;

	int color[7][3] = { { 254, 67, 101 }, { 217, 104, 49 }, { 250, 227, 113 }, { 131, 175, 155 }, { 69, 137, 148 }, { 1, 77, 103 }, { 89, 61, 67 } };
	pen.lopnColor = RGB(color[rown][0], color[rown][1], color[rown][2]);
	timess = timess + 1;
	if (timess == TIMESS)
	{
		rown = rown + 1;
		timess = 0;
	}
	if (rown == 6)
		rown = -0;

	pen.lopnStyle = PS_SOLID;
	pen.lopnWidth = penWidth;
	HPEN hPen = CreatePenIndirect(&pen);


	switch (message)
	{
	case WM_TRAY:
		switch (lParam)
		{
		case WM_RBUTTONDOWN:
		{
			//获取鼠标坐标 
			POINT pt; GetCursorPos(&pt);

			//解决在菜单外单击左键菜单不消失的问题 
			SetForegroundWindow(hWnd);

			//使菜单某项变灰 
			//EnableMenuItem(hMenu, ID_SHOW, MF_GRAYED);     

			//显示并获取选中的菜单 
			int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, hWnd,
				NULL);
			if (cmd == ID_SHOW)
				MessageBox(hWnd, L"Win32 API 实现系统托盘程序", L"托盘程序", MB_OK);
			if (cmd == ID_EXIT)
				PostMessage(hWnd, WM_DESTROY, NULL, NULL);
		}
		break;
		case WM_LBUTTONDOWN:
			MessageBox(hWnd, L"Win32 API 实现系统托盘程序", L"托盘程序", MB_OK);
			break;
		case WM_LBUTTONDBLCLK:
			break;
		}
		break;

	case WM_TIMER:
		ShowTrayMsg();
		KillTimer(hWnd, wParam);
		break;

	case WM_COPYDATA:
		if (wParam == -1 && lParam == -1)
		{
			GetScreenCapture();
			ShowWindow(hWnd, SW_SHOW);
			UpdateWindow(hWnd);
		}


	case WM_COMMAND:
		wmId = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 分析菜单选择:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_CREATE:
		//GetScreenCapture();
		break;
	case WM_PAINT:
	{
		hdc = BeginPaint(hWnd, &ps);

		HDC memDc = CreateCompatibleDC(hdc);
		HBITMAP bmp = CreateCompatibleBitmap(hdc, screenW, screenH);
		SelectObject(memDc, bmp);

		BitBlt(memDc, 0, 0, screenW, screenH, g_grayMemDc, 0, 0, SRCCOPY);
		SelectObject(memDc, hBrush);
		SelectObject(memDc, hPen);

		if (isDrawing || isSelect)
		{

			BitBlt(memDc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, g_srcMemDc, rect.left, rect.top, SRCCOPY);
			Rectangle(memDc, rect.left, rect.top, rect.right, rect.bottom);
		}

		BitBlt(hdc, 0, 0, screenW, screenH, memDc, 0, 0, SRCCOPY);

		DeleteObject(bmp);
		DeleteObject(memDc);

		EndPaint(hWnd, &ps);
	}
	break;

	case WM_LBUTTONDOWN:
	{
		if (!isSelect)
		{
			POINT pt;
			GetCursorPos(&pt);
			rect.left = pt.x;
			rect.top = pt.y;
			rect.right = pt.x;
			rect.bottom = pt.y;

			isDrawing = true;
			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;

	case WM_LBUTTONUP:
	{
		if (isDrawing && !isSelect)
		{
			isDrawing = false;
			POINT pt;
			GetCursorPos(&pt);
			rect.right = pt.x;
			rect.bottom = pt.y;

			isSelect = true;

			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;

	case WM_MOUSEMOVE:
	{
		if (isDrawing&& !isSelect)
		{
			POINT pt;
			GetCursorPos(&pt);
			rect.right = pt.x;
			rect.bottom = pt.y;
			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;
	case WM_LBUTTONDBLCLK:
	{
		if (isSelect)
		{
			WriteDatatoClipBoard();
			InvalidateRgn(hWnd, 0, false);
			ShowWindow(hWnd, SW_HIDE);
			//ShowWindow(hWnd, SW_MINIMIZE);



			TCHAR MyDir[_MAX_PATH];
			SHGetSpecialFolderPath(hWnd, MyDir, CSIDL_DESKTOP, 0);	//获取特殊路径,获取桌面路径
			CString  str;
			str.Format(_T("%s"), MyDir);
			CString depart = "\\";
			CString lkuohao = "(";
			CString rkuohao = ")";
			CString name = SHOT_NAME;
			CString cstype = SHOT_TYPE;
			//cstring to char*
			CString strPath = str + depart + name + cstype;
			//char *path = (LPSTR)(LPCTSTR)cstr;

			//CString strPath = L"C:\\Users\\Wayne\\Desktop\\2015年最新软件进展\\call_log.csv";


			int nLength = strPath.GetLength();
			int nBytes = WideCharToMultiByte(CP_ACP, 0, strPath, nLength, NULL, 0, NULL, NULL);
			char* VoicePath = new char[nBytes + 1];
			memset(VoicePath, 0, nLength + 1);
			WideCharToMultiByte(CP_OEMCP, 0, strPath, nLength, VoicePath, nBytes, NULL, NULL);
			VoicePath[nBytes] = 0;

			//strPath    *VoicePath

			int woc = 2;
			CString woca;
			CString cstrn = strPath;

			while (_access(VoicePath, 0) == 0)
			{
				woca.Format(_T("%d"), woc);
				cstrn = strPath + lkuohao + woca + rkuohao + cstype;
				//判断有没有~
				int n2Length = cstrn.GetLength();
				int n2Bytes = WideCharToMultiByte(CP_ACP, 0, cstrn, n2Length, NULL, 0, NULL, NULL);
				VoicePath = new char[n2Bytes + 1];
				memset(VoicePath, 0, n2Length + 1);
				WideCharToMultiByte(CP_OEMCP, 0, cstrn, n2Length, VoicePath, n2Bytes, NULL, NULL);
				VoicePath[n2Bytes] = 0;
				woc++;
			}

			SaveBmp(hBmp, cstrn);	//使用下面的函数

		}
		isSelect = false;

	}
	break;
	case WM_DESTROY:
	{//窗口销毁时删除托盘 
		Shell_NotifyIcon(NIM_DELETE, &nid);

		UNINSPROC    uninstproc;
		uninstproc = (UNINSPROC)GetProcAddress(m_hDll, "UnInstallHook");
		BOOL bResult = uninstproc();

		::FreeLibrary(m_hDll);
		m_hDll = NULL;

		PostQuitMessage(0);
		break;
	}
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}