Archived

This topic is now archived and is closed to further replies.

Zipster

help me with this, plz

Recommended Posts

Heres the deal. I''m working on a paont program, and as of now i have a pencil mode and an ellipse mode for drawing. heres the code that draws the ellipse: int Draw_Circle_GDI(RECT *rect, int color, LPDIRECTDRAWSURFACE7 lpdds) { HDC xdc; HPEN pen; LOGPEN lp; POINT p; HBRUSH brush; LOGBRUSH lb; if(FAILED(lpdds->GetDC(&xdc))) return(0); SetBkMode(xdc, TRANSPARENT); p.x = 1; lb.lbStyle = BS_SOLID; lb.lbColor = RGB(palette[color].peRed, palette[color].peGreen, palette[color].peBlue); lp.lopnStyle = PS_SOLID; lp.lopnWidth = p; lp.lopnColor = RGB(palette[color].peRed, palette[color].peGreen, palette[color].peBlue); pen = CreatePenIndirect(&lp); brush = CreateSolidBrush(RGB(palette[color].peRed, palette[color].peGreen, palette[color].peBlue)); SelectObject(xdc, pen); SelectObject(xdc, brush); Ellipse(xdc, rect->left, rect->top, rect->right, rect->bottom); DeletePen(pen); DeleteBrush(brush); lpdds->ReleaseDC(xdc); return(1); } ///////////////////////////// To make a long story short, whenver i run my painr program and only draw using the pencil tool (i.e not executing the above code), everything works fine. However once i run the program and draw ellipses (i.e executing the above code), everything works fine until i exit the program, where after i quit i get a "This function has performed an illegal operation..." error message. Why is the above code causing this error?

Share this post


Link to post
Share on other sites
You must restore the original objects in the DC before deleting them, otherwise you app will crash.

HPEN OldPen = SelectObject(xdc, pen);

... Draw Something

SelectObject(xdc, OldPen);
DeleteObject(pen);

Share this post


Link to post
Share on other sites