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


Problem drawing a line with GDI

Recommended Posts

Codman    181
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:

Share this post

Link to post
Share on other sites
Colin Jeanne    1114
Some oddities:


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


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