Start with the project you created in Implementing Hit Testing.
Note: This tutorial will only use 3 types of objects (Line, Ellipse and Polygon) to keep things simple. For more information about the vector object types supported by the toolkit, refer to the VECTOROBJECT structure.
Comment out these local variables from the WndProc function:
static OPENFILENAME OpenFileName;static L_TCHAR szFileName[ _MAX_PATH ];static L_TCHAR szFileTitle[ _MAX_PATH ];static L_TCHAR *szFilter[] = { TEXT("All Files\0*.*\0") };
Comment out these lines from WM_CREATE handler:
// reset the OPENFILENAME structurememset( &OpenFileName, 0, sizeof( OPENFILENAME ) );OpenFileName.lStructSize = sizeof( OPENFILENAME );OpenFileName.hwndOwner = hWnd;OpenFileName.lpstrFilter = szFilter[ 0 ];OpenFileName.lpstrFile = szFileName;OpenFileName.nMaxFile = _MAX_PATH;OpenFileName.lpstrFileTitle = szFileTitle;OpenFileName.nMaxFileTitle = _MAX_PATH;
Comment out these 2 cases from the switch( wParam ) statement in WM_COMMAND handle:
case IDM_OPEN:case IDM_SAVE:
Add these local variables under the VECTORPEN Pen; statement in the WndProc function:
VECTORLINE Line; // line vector objectVECTORELLIPSE Ellipse; // circle vector objectVECTORPOLYGON Polygon; // polygon vector objectL_INT i;
Add the following lines in WM_CREATE handler after L_VecAttachToWindow and before ResetView:
// fill in the layer descriptor structure and add new layer to the vector handleLayerDesc.nSize = sizeof( VECTORLAYERDESC );lstrcpy( LayerDesc.szName, TEXT("Default Layer"));LayerDesc.bVisible = TRUE;LayerDesc.bLocked = FALSE;LayerDesc.dwTag = 0L;L_VecAddLayer ( &Vector, &LayerDesc, &Layer, 0L );// make this the active layer in the vector handleL_VecSetActiveLayer ( &Vector, &Layer );
Add the following code to the WM_CHAR handler, after the break; statement of case B:
case 'l':case 'L':// add a new vector lineL_VecInitObject ( &Line.Object );Line.Object.nSize = sizeof( VECTORLINE );Line.Object.nType = VECTOR_LINE;// set the line penLine.Pen.nSize = sizeof( VECTORPEN );Line.Pen.NewPen.LogPen.lopnColor = RGB( rand() % 246 + 10, rand() % 246 + 10, rand() % 246 + 10 );Line.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;Line.Pen.NewPen.LogPen.lopnWidth.x = 1;Line.Pen.NewPen.LogPen.lopnWidth.y = 1;// set the line start and end pointsfor( i = 0; i < 2; i++ ){Line.Point[ i ].x = rand() % 100;Line.Point[ i ].y = rand() % 100;Line.Point[ i ].z = rand() % 100;}// add the object to the active layerL_VecAddObject ( &Vector, NULL, VECTOR_LINE, &Line, NULL );// update view parameters and re-paint windowResetView( hWnd, &Vector );break;case 'e':case 'E':// add a new ellipse objectL_VecInitObject ( &Ellipse.Object );Ellipse.Object.nSize = sizeof( VECTORELLIPSE );Ellipse.Object.nType = VECTOR_ELLIPSE;// set the ellipse penEllipse.Pen.nSize = sizeof( VECTORPEN );Ellipse.Pen.NewPen.LogPen.lopnColor = RGB( rand() % 246 + 10, rand() % 246 + 10, rand() % 246 + 10 );Ellipse.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;Ellipse.Pen.NewPen.LogPen.lopnWidth.x = 1;Ellipse.Pen.NewPen.LogPen.lopnWidth.y = 1;// set the ellipse brushEllipse.Brush.nSize = sizeof( VECTORBRUSH );Ellipse.Brush.BrushType.StandardBrush.LogBrush.lbColor = RGB( rand() % 246 + 10, rand() % 246 + 10, rand() % 246 + 10 );Ellipse.Brush.BrushType.StandardBrush.LogBrush.lbStyle = BS_SOLID;Ellipse.Brush.BrushType.StandardBrush.LogBrush.lbHatch = 0;// set the ellipse center, x radius and y radiusEllipse.Point.x = rand() % 100;Ellipse.Point.y = rand() % 100;Ellipse.Point.z = rand() % 100;Ellipse.xRadius = rand() % 10;Ellipse.yRadius = rand() % 10;// add the object to the active layerL_VecAddObject ( &Vector, NULL, VECTOR_ELLIPSE, &Ellipse, NULL );// update view parameters and re-paint windowResetView( hWnd, &Vector );break;case 'g':case 'G':// add a new polygon objectL_VecInitObject ( &Polygon.Object );Polygon.Object.nSize = sizeof( VECTORPOLYGON );Polygon.Object.nType = VECTOR_POLYGON;// set the polygon penPolygon.Pen.nSize = sizeof( VECTORPEN );Polygon.Pen.NewPen.LogPen.lopnColor = RGB( rand() % 246 + 10, rand() % 246 + 10, rand() % 246 + 10 );Polygon.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;Polygon.Pen.NewPen.LogPen.lopnWidth.x = 1;Polygon.Pen.NewPen.LogPen.lopnWidth.y = 1;// set the polygon brushPolygon.Brush.nSize = sizeof( VECTORBRUSH );Polygon.Brush.BrushType.StandardBrush.LogBrush.lbColor = RGB( rand() % 246 + 10, rand() % 246 + 10, rand() % 246 + 10 );Polygon.Brush.BrushType.StandardBrush.LogBrush.lbStyle = BS_SOLID;Polygon.Brush.BrushType.StandardBrush.LogBrush.lbHatch = 0;// set the polygon pointsPolygon.nPointCount = rand() % 5 + 3;Polygon.Point = (pVECTORPOINT) malloc( Polygon.nPointCount * sizeof( VECTORPOINT ) );for( i = 0; i < Polygon.nPointCount; i++ ){Polygon.Point[ i ].x = rand() % 100;Polygon.Point[ i ].y = rand() % 100;Polygon.Point[ i ].z = rand() % 100;}// set polygon fill modePolygon.nPolyFillMode = VECTOR_POLY_ALTERNATE;// add the object to the active layerL_VecAddObject ( &Vector, NULL, VECTOR_POLYGON, &Polygon, NULL );free( Polygon.Point );// update view parameters and re-paint windowResetView( hWnd, &Vector );break;