Start with the project you created in Collecting container events:
1. |
Add the following popup menu structure to the main menu you created in Implementing the Container - Initializing, Creating and Freeing: |
Edit &Object
&Line with ID = IDM_EDITOBJECT_LINE
&Square with ID = IDM_EDITOBJECT_SQUARE
&Rect with ID = IDM_EDITOBJECT_RECT
&Circle with ID = IDM_EDITOBJECT_CIRCLE
&Ellipse with ID = IDM_EDITOBJECT_ELLIPSE
P&olyline with ID = IDM_EDITOBJECT_POLYLINE
&Bezier with ID = IDM_EDITOBJECT_BEZIER
&Arc with ID = IDM_EDITOBJECT_ARC
&Text with ID = IDM_EDITOBJECT_TEXT
2. |
Add the following code to the WndProc function, just before the "return 0L ;" of the WM_CREATE message: |
EnableMenuItem ( GetMenu ( hWnd ), 2, MF_BYPOSITION | MF_GRAYED ) ;
3. |
Add the following lines to the WndProc function, after the EnableMenuItem function call in the "case IDM_FILE_OPEN" of the WM_COMMAND message: |
EnableMenuItem ( GetMenu ( hWnd ), 2, MF_BYPOSITION | MF_ENABLED ) ;
4. |
Add the following functions before the OnOpen function definition: |
L_VOID OnEditObjectLine ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERLINEDATA LineData ;
LineData.vptLine[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
LineData.vptLine[0].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
LineData.vptLine[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
LineData.vptLine[1].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_LINE ;
Data.pObjectData = &LineData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectSquare ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERSQUAREDATA SquareData ;
SquareData.vptSquare[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
SquareData.vptSquare[0].y = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
SquareData.vptSquare[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
SquareData.vptSquare[1].y = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_SQUARE ;
Data.pObjectData = &SquareData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectRect ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERRECTDATA RectData ;
RectData.vptRect[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
RectData.vptRect[0].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
RectData.vptRect[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
RectData.vptRect[1].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_RECT ;
Data.pObjectData = &RectData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectCircle ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERCIRCLEDATA CircleData ;
CircleData.vptCircle[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
CircleData.vptCircle[0].y = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
CircleData.vptCircle[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
CircleData.vptCircle[1].y = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_CIRCLE ;
Data.pObjectData = &CircleData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectEllipse ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERELLIPSEDATA EllipseData ;
EllipseData.vptEllipse[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
EllipseData.vptEllipse[0].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
EllipseData.vptEllipse[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
EllipseData.vptEllipse[1].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_ELLIPSE ;
Data.pObjectData = &EllipseData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectPolyline ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERPOLYLINEDATA PolylineData ;
VECTORPOINT vptPolyline [ 4 ] ;
vptPolyline[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
vptPolyline[0].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
vptPolyline[1].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
vptPolyline[1].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4;
vptPolyline[2].x = ( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4 ;
vptPolyline[2].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ;
vptPolyline[3].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
vptPolyline[3].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ;
PolylineData.pvptPoints = vptPolyline ;
PolylineData.nPointCount = 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_POLYLINE ;
Data.pObjectData = &PolylineData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectBezier ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERBEZIERDATA BezierData ;
BezierData.vptBezier[0].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
BezierData.vptBezier[0].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4;
BezierData.vptBezier[1].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 2 ;
BezierData.vptBezier[1].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
BezierData.vptBezier[2].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 2 ;
BezierData.vptBezier[2].y = ( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4;
BezierData.vptBezier[3].x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
BezierData.vptBezier[3].y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_BEZIER ;
Data.pObjectData = &BezierData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectArc ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERARCDATA ArcData ;
ArcData.vptCenter.x = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 2 ;
ArcData.vptCenter.y = ( BITMAPHEIGHT ( pBitmap ) - 1 ) / 2 ;
ArcData.Radius = ( BITMAPWIDTH ( pBitmap ) - 1 ) / 4 ;
ArcData.StartAngle = 10 ;
ArcData.SweepAngle = 45 ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_ARC ;
Data.pObjectData = &ArcData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
L_VOID OnEditObjectText ( pCONTAINERHANDLE pContainer, pBITMAPHANDLE pBitmap )
{
CONTAINEROBJECTDATA Data ;
CONTAINERTEXTDATA TextData ;
TextData.pszText = TEXT("LEAD TECHNOLOGIES, INC.") ;
TextData.cbLength = lstrlen( TextData.pszText ) * sizeof (L_TCHAR);
SetRect ( &TextData.rcText,
( BITMAPWIDTH ( pBitmap ) - 1 ) / 4,
( BITMAPHEIGHT ( pBitmap ) - 1 ) / 4,
( ( BITMAPWIDTH ( pBitmap ) - 1 ) * 3 ) / 4,
( ( BITMAPHEIGHT ( pBitmap ) - 1 ) * 3 ) / 4 ) ;
// set the container object data
Data.nSize = sizeof ( CONTAINEROBJECTDATA ) ;
Data.nObjectType = CONTAINER_OBJECT_TYPE_TEXT ;
Data.pObjectData = &TextData ;
// start editing an object
// double click the left-mouse button to end editing
// click right-mouse button to abort editing
L_ContainerEditObject ( pContainer, &Data ) ;
}
5. |
Add the following code to the WndProc function, after the statement "return 0L ;" of the case IDM_DRAWOBJECT_TEXT of the WM_COMMAND message: |
case IDM_EDITOBJECT_LINE:
OnEditObjectLine ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_SQUARE:
OnEditObjectSquare ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_RECT:
OnEditObjectRect ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_CIRCLE:
OnEditObjectCircle ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_ELLIPSE:
OnEditObjectEllipse ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_POLYLINE:
OnEditObjectPolyline ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_BEZIER:
OnEditObjectBezier ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_ARC:
OnEditObjectArc ( pContainer, &hBitmap ) ;
return 0L ;
case IDM_EDITOBJECT_TEXT:
OnEditObjectText ( pContainer, &hBitmap ) ;
return 0L ;
6. |
Compile and run the project by selecting Build->Rebuild Solution from the menu, and then Debug->Start Without Debugging. |