problem with my painting ellipse program

I write a simple drawing ellipse program, I want to implement draw different outline ellipse, but my code doesn't work well with the line color, here's part of my code(part of WM_PAINT in WndProc funciton):

// oldHPEN and hPen are HPEN instance, hDC is HDC
if(ghMouseDown) {
	oldHPEN = (HPEN)SelectObject(hDC, hPen);
        Ellipse(hDC, gRect.left,, gRect.right, gRect.bottom);
	SelectObject(hDC, oldHPEN);
	for(unsigned int i = 0; i < gRects.size(); ++i) {
	//oldHPEN = (HPEN)SelectObject(hDC, hPen);
	Ellipse(hDC, gRects[i].left, gRects[i].top, gRects[i].right, 
	//SelectObject(hDC, oldHPEN);

when I omit the line in the for loop, it works well when LBUTTONDOWN and MOUSEMOVE, but if I uncomment these, it got weired, all ellipse becomes the last drawing color, what should I do?
I got puzzle with SelectObject function, I want to know what the SelectObject do ? why first we save the return, and next we don't need the return value?

it works well when use like this:

// save the Ellipse in the class gShape, and use the class method, the method use the same code as before.
if( gMouseDown ) 
// Draw all the permenent shapes.
for(inti = 0; i < gShapes.size(); ++i) 
Topic archived. No new replies allowed.