drawing a circle
-
-
hi all, i need to make a start on this project which requires me to draw rectangels and circles in VC++. and i don't a have a CLUE where to start, and HOW to start! anybuddy there to help me out??? imran help me today, and i'll help YOU out tomorrow...
CDC::Rectangle CDC::Ellipse ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
-
hi all, i need to make a start on this project which requires me to draw rectangels and circles in VC++. and i don't a have a CLUE where to start, and HOW to start! anybuddy there to help me out??? imran help me today, and i'll help YOU out tomorrow...
If you're just drawing them ( i.e. they will not change ), you can do this in your OnPaint handler. Just use the methods already mentioned. If you want them to change/move, you will probably want to double buffer them, which means drawing them to another bitmap then copying it across just after creating the paintDC, to avoid flicker. To create a DC you do the following: CDC dc; dc.CreateCompatibleDC(NULL); // Creates a device context compatible with the screen CBitmap bm, *pOldBitmap; bm.Create(width, height, 1, GetDeviceCaps(dc.m_hDC, BITSPIXEL)); // Create a bitmap to draw onto pOldBitmap = dc.SelectObject(&bm); // Whenever you select something into a DC, a pointer to the old one is released // You *must* catch it and put it back in to avoid memory leaks CPen pen, *pOldPen; pen.Create(PS_SOLID, 1, RGB(255,0,0)); // Create a red pen, one pixel wide pOldPen = dc.SelectObject(&pen); // Now we can draw stuff using DrawREctangle, DrawEllipse, MoveTo, LineTo, etc. To draw filled shapes we need also create and select a brush to fill them. Then you create the paintDC, blt the CDC onto it, select the pointers you grabbed back into the DC and delete it ( using dc.DeleteDC(); ) I hope that helps. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese.
-
If you're just drawing them ( i.e. they will not change ), you can do this in your OnPaint handler. Just use the methods already mentioned. If you want them to change/move, you will probably want to double buffer them, which means drawing them to another bitmap then copying it across just after creating the paintDC, to avoid flicker. To create a DC you do the following: CDC dc; dc.CreateCompatibleDC(NULL); // Creates a device context compatible with the screen CBitmap bm, *pOldBitmap; bm.Create(width, height, 1, GetDeviceCaps(dc.m_hDC, BITSPIXEL)); // Create a bitmap to draw onto pOldBitmap = dc.SelectObject(&bm); // Whenever you select something into a DC, a pointer to the old one is released // You *must* catch it and put it back in to avoid memory leaks CPen pen, *pOldPen; pen.Create(PS_SOLID, 1, RGB(255,0,0)); // Create a red pen, one pixel wide pOldPen = dc.SelectObject(&pen); // Now we can draw stuff using DrawREctangle, DrawEllipse, MoveTo, LineTo, etc. To draw filled shapes we need also create and select a brush to fill them. Then you create the paintDC, blt the CDC onto it, select the pointers you grabbed back into the DC and delete it ( using dc.DeleteDC(); ) I hope that helps. Christian I've learned that you cannot make someone love you. All you can do is stalk them and hope they panic and give in. The early bird may get the worm, but it's the second mouse that gets the cheese.
good