Jump to content
  • Advertisement

Archived

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

Codman

Problem drawing a line with GDI

This topic is 5419 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Yes, you need to catch the return value of SelectObject in pOldPen and pass the address of pen. The select object call should look like:
pOldPen = pDC.SelectObject(&pen);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Fixed! 10x for help .

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!