help me with this, plz

Started by
1 comment, last by Zipster 24 years ago
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.peRed, palette.peGreen, palette.peBlue); lp.lopnStyle = PS_SOLID; lp.lopnWidth = p; lp.lopnColor = RGB(palette.peRed, palette.peGreen, palette.peBlue); pen = CreatePenIndirect(&lp); brush = CreateSolidBrush(RGB(palette.peRed, palette.peGreen, palette.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? <img src="sad.gif" width=15 height=15 align=middle>
Advertisement
im glad to know no one can solve this one!!

makes me feel special!!

what i meant to say:
my god people!! is this really that hard!!! ;(

Edited by - Zipster on 3/31/00 1:10:18 AM
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);

This topic is closed to new replies.

Advertisement