Archived

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

Codman

Problem drawing a line with GDI

Recommended Posts

void CMenuDlg::DrawLine(CPoint p1, CPoint p2, COLORREF color ) { CClientDC pDC(this); CPen pen(PS_SOLID, 1, color); CPen *pOldPen = NULL; // Setam penita noastra pDC.SelectObject(pen); pDC.MoveTo(p1); pDC.LineTo(p2); // Restauram vechea penita pDC.SelectObject(pOldPen); } If I call this function once after a time i receive a error msg "The resource was " and the program get stuck. Also the blue window title bar becomes white (even in Visual C and Internet Explorer). If i remove the function from my program everything works well. I appreciate any help. ----------------------------- Codman - "The source for all things" "We design for eternity" Mail: Codman_Wu@personal.ro

Share this post


Link to post
Share on other sites
Some oddities:

pDC.SelectObject(pen);

1. pen is not a pointer (which, according to MSDN documentation, it should be)
2. You are not setting pOldPen to the return value of this call

pDC.SelectObject(pOldPen);

1. pOldPen will always be 0. You are not selecting the correct pen back into the DC.


Colin Jeanne | Invader''s Realm

Share this post


Link to post
Share on other sites