the following code is from the examples on the book

 CPen pen (PS_SOLID, 0, RGB (192, 192, 192));
 CPen* pOldPen = dc.SelectObject (&pen);

 //do some drawing staff here

 dc.SelectObject (pOldPen);

I know once I create a pen, I can do some drawing staff, but why should I add "CPen* pOldPen = dc.SelectObject (&pen)" and "dc.SelectObject (pOldPen)" here? what's the use of that?

save and restore the original pen value. Some other part of the program may be expecting the pen to be the original value and your program doesn't want to pull the rug out from under it. Your program needs to be a little kinder and a little gentler about other parts of the program.

commented: Ah, windows guy-[Gr] +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.