Sets the object information of the class object. This function is available in the LEADTOOLS Vector Imaging Toolkit.
#include "ltwrappr.h"
virtual L_INT LVectorObject::UnlockObject(pObject)
Pointer to a VECTOROBJECT structure that contains the vector object information to set.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This function is used to update the object information of the class object.
To use this method, declare a variable of type VECTOROBJECT and pass the address to the LVectorObject::LockObject() method. After modifying the vector object settings, call LVectorObject::UnlockObject(). LVectorObject::LockObject() and LVectorObject::UnlockObject() should always be called in pairs. A more useful form of this method is available in any of the LVectorObject derived classes.
Before an object has been added to the LVectorBase object, using LVectorBase::AddObject or LVectorLayer::AddObject, UnlockObject() can be used to change ALL properties of an object. However, once the object has been added to the LVectorBase object, some properties cannot be changed using LVectorObject::UnlockObject(). Specifically, nPointCount, *Point, pszText, and pbyType cannot be changed. However, as long as the number of points does not change, the coordinates of the individual points can always be modified using LVectorObject::UnlockObject().
To get the current object information for a class object, call LVectorObject::LockObject.
LVectorObject::LockObject and LVectorObject::UnlockObject must be called in pairs.
This example will add a new green polyline to the Active Layer LVectorBase object.
L_INT LVectorObject__UnlockObjectExample_1(HWND hWnd, LVectorBase *pVector)
{
UNREFERENCED_PARAMETER(hWnd);
L_INT nRet;
VECTORPOLYLINE PolyLine;
LVectorPolyLine VectorPolyLine;
nRet = VectorPolyLine.LockObject(&PolyLine);
if(nRet != SUCCESS)
return nRet;
//Change default properties
PolyLine.nPointCount = 4;
VECTORPOINT Points[4] = {
50, 50, 0, 0,
80, 50, 0, 0,
80, 80, 0, 0,
50, 80, 0, 0
};
PolyLine.Point = Points;
PolyLine.Pen.bExtPen = FALSE;
PolyLine.Pen.NewPen.LogPen.lopnColor = RGB(0,255,0);
nRet = VectorPolyLine.UnlockObject(&PolyLine);
if(nRet != SUCCESS)
return nRet;
nRet = pVector->AddObject(&VectorPolyLine );
if(nRet != SUCCESS)
return nRet;
return SUCCESS;
}
// This example will add a rectangle to the Active Layer LVectorBase object.
// Once added, the rectangle will be rotated twice.
// Rotating the first time 90 degrees, the object type stays as VECTOR_RECTANGLE.
// Rotating the second time 45 degrees, the object type changes to a VECTOR_POLYDRAW.
L_INT LVectorObject__UnlockObjectExample_2(HWND hWnd, LVectorBase *pVector)
{
UNREFERENCED_PARAMETER(hWnd);
VECTORRECTANGLE Rectangle;
L_INT nRet;
L_TCHAR *pszType;
//Create Rectangle Object
Rectangle.Point[0].x = 30;
Rectangle.Point[0].y = 30;
Rectangle.Point[0].z = 10;
Rectangle.Point[1].x = 80;
Rectangle.Point[1].y = 50;
Rectangle.Point[1].z = 10;
Rectangle.Brush.nSize = sizeof(VECTORBRUSH);
Rectangle.Brush.VectorBrushStyle = VECTORBRUSH_STANDARD;
Rectangle.Brush.BrushType.StandardBrush.LogBrush.lbColor = RGB(0,128,0);
Rectangle.Brush.BrushType.StandardBrush.LogBrush.lbStyle = BS_SOLID;
Rectangle.Pen.nSize = sizeof( VECTORPEN );
Rectangle.Pen.bExtPen = FALSE;
Rectangle.Pen.NewPen.LogPen.lopnStyle = PS_SOLID;
Rectangle.Pen.NewPen.LogPen.lopnWidth.x = 2;
Rectangle.Pen.NewPen.LogPen.lopnWidth.y = 2;
Rectangle.Pen.NewPen.LogPen.lopnColor = RGB(255,0,0);
LVectorRectangle VectorRectangle(&Rectangle);
nRet = pVector->AddObject(&VectorRectangle);
if(nRet != SUCCESS)
return nRet;
//Rotate 90 degrees along the Z-Axis--it stays a VECTOR_RECTANGLE
MessageBox(NULL, TEXT("Rotating 90 degrees along the Z-axis"), TEXT(""), MB_OK);
VECTORPOINT pointRotation;
pointRotation.x = 0;
pointRotation.y = 0;
pointRotation.z = 90;
VECTORRECTANGLE RectangleTemp;
nRet = VectorRectangle.LockObject(&RectangleTemp);
if (nRet == SUCCESS)
{
RectangleTemp.Pen.NewPen.LogPen.lopnColor = RGB(0,0,255);
nRet = VectorRectangle.UnlockObject(&RectangleTemp);
if(nRet != SUCCESS)
return nRet;
}
else
return nRet;
//Rotate rectangle 45 degrees--it becomes an VECTOR_POLYDRAW object
pointRotation.x = 0;
pointRotation.y = 0;
pointRotation.z = 45;
nRet = VectorRectangle.SetRotation(&pointRotation);
if(nRet != SUCCESS)
return nRet;
//Cannot call LockObject/UnlockObject here, but can still change properties
//Object type is still a Rectangle
pszType = VectorRectangle.IsTypeValid() ?
TEXT("Valid Type--can call LockObject()/UnlockObject() and SetObjectAttributes() to change object properties") :
TEXT("Invalid Type--can call SetObjectAttributes() to change object properties");
MessageBox(NULL, pszType, TEXT(""), MB_OK);
//Change color with SetObjectAttributes()
VECTORBRUSH brush;
brush.VectorBrushStyle = VECTORBRUSH_STANDARD;
brush.BrushType.StandardBrush.LogBrush.lbColor = RGB(128,128,0);
return SUCCESS;
}