
CIS 4930-4 Component-Level Programming EMA 100
Program #3 Methods 10 Points
Construct an ActiveX control that displays the following window. The border is required
and the horizontal and vertical lines should bisect the window.
Use the following steps to create your control.
1. Create a new control. (Don’t modify any of your previous efforts, start from
scratch!
2. In the OnDraw routine, put the following lines AT THE VERY BEGINNING of
the routine.
// Set the line color
CPen MyPen;
MyPen.CreatePen(PS_SOLID,0,RGB(0,0,0));
CPen * OldPen = pdc->SelectObject(&MyPen);
// Set the background color
CBrush MyBrush;
MyBrush.CreateSolidBrush(RGB(255,255,255));
CBrush * OldBrush = pdc->SelectObject(&MyBrush);
//Drawing Commands follow this line
3. To draw the rectangle, use the following drawing command. Note that rcBounds
is a parameter to the OnDraw routine. rcBounds gives the screen coordinates of
your control’s window, and this command draws a rectangle around the window.
pdc->Rectangle(&rcBounds);
4. To draw the cross hairs, you must compute the horizontal and vertical centers of
the window. Use the following code to do this.
// Note: vertical coordinates get larger as you go down.
long VertMid = rcBounds.left + ((rcBounds.right-rcBounds.left+1)/2);
long HorzMid = rcBounds.top + ((rcBounds.bottom-rcBounds.top+1)/2);
5. Use these two new coordinates to draw the lines, using the following commands.
pdc->MoveTo(VertMid,rcBounds.top);
pdc->LineTo(VertMid,rcBounds.bottom);
pdc->MoveTo(rcBounds.left,HorzMid);
pdc->LineTo(rcBounds.left,HorzMid);
6. After drawing the cross hairs, YOU MUST add the following cleanup code to
restore the previous line and background colors, and delete the system objects you
created in step 2 above.
pdc->SelectObject(OldPen);
pdc->SelectObject(OldBrush);
MyBrush.DeleteObject( );
MyPen.DeleteObject( );
7. Compile your control and test it at this point, to make sure it draws the box
correctly.