How to make a custom symbol in MapObject 2 with VC++?
Key Words: MapObject, VC++,ICustomLine
public:
CPen g_hPen;
// ICustomLine
STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)
{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
//CPen* g_hPen = CreatePen(pBaseSym->Style, pBaseSym->Size, pBaseSym->Color);
DISPID dispid;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
VARIANT FAR *PvarColor, *PvarSize;
CHAR *szMember = "Color";
pBaseSym->GetIDsOfNames(IID_NULL, (OLECHAR FAR **) &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
pBaseSym->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET,&dispparamsNoArgs,
PvarColor, NULL, NULL);
szMember = "Size";
pBaseSym->GetIDsOfNames(IID_NULL, (OLECHAR FAR **) &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
pBaseSym->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET,&dispparamsNoArgs,
PvarSize, NULL, NULL);
g_hPen.CreatePen(PS_SOLID, PvarSize->decVal.wReserved, PvarColor->decVal.Lo64);
m_oldPen =pcdc->SelectObject(&g_hPen);
//*/ m_oldPen =(CPen*)pcdc->SelectStockObject(BLACK_PEN);
return S_OK;
}
STDMETHOD(ResetDC)(LONG hDC)
{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
CPen* temp = pcdc->SelectObject(m_oldPen);
temp->DeleteObject();
return S_OK;
}
STDMETHOD(Draw)(LONG hDC, LONG * points, LONG * partCounts, LONG numParts)
{
POINT * P=(POINT *)points;
POINT MiddlePoint,ToPoint1,ToPoint2;
DOUBLE slope,TempSlope;
MiddlePoint.x=P->x;
MiddlePoint.y=P->y;
P++;
if (P->x!=MiddlePoint.x){
slope=(DOUBLE)(P->y-MiddlePoint.y)/(P->x-MiddlePoint.x);
slope=atan(slope);
}
else{
if(MiddlePoint.y>P->y)
slope=3.1415926/2.0;
else
slope=3.1415926*3.0/2.0;
}
MiddlePoint.x=(MiddlePoint.x+P->x)/2;
MiddlePoint.y=(MiddlePoint.y+P->y)/2;
//Get the end point of an Arrow
TempSlope=slope-inclination;
INT dx=(INT)(cos(TempSlope)*ArrowLEN);
INT dy=(INT)(sin(TempSlope)*ArrowLEN);
if(MiddlePoint.x<P->x){
ToPoint1.x=MiddlePoint.x-dx;
ToPoint1.y=MiddlePoint.y-dy;
}
else{
ToPoint1.x=MiddlePoint.x+dx;
ToPoint1.y=MiddlePoint.y+dy;
}
//Get the end point of another Arrow
TempSlope=slope+inclination;
dx=(INT)(cos(TempSlope)*ArrowLEN);
dy=(INT)(sin(TempSlope)*ArrowLEN);
if(MiddlePoint.x<P->x){
ToPoint2.x=MiddlePoint.x-dx;
ToPoint2.y=MiddlePoint.y-dy;
}
else{
ToPoint2.x=MiddlePoint.x+dx;
ToPoint2.y=MiddlePoint.y+dy;
}
CDC* pcdc=::CDC::FromHandle((HDC)hDC);
pcdc->MoveTo(ToPoint1);
pcdc->LineTo(MiddlePoint);
pcdc->LineTo(ToPoint2);
pcdc->PolyPolyline((POINT *)points,(DWORD *)partCounts,(int)numParts);
return S_OK;
}
public:
CPen g_hPen;
// ICustomLine
STDMETHOD(SetupDC)(LONG hDC, DOUBLE dpi, IDispatch * pBaseSym)
{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
//CPen* g_hPen = CreatePen(pBaseSym->Style, pBaseSym->Size, pBaseSym->Color);
DISPID dispid;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
VARIANT FAR *PvarColor, *PvarSize;
CHAR *szMember = "Color";
pBaseSym->GetIDsOfNames(IID_NULL, (OLECHAR FAR **) &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
pBaseSym->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET,&dispparamsNoArgs,
PvarColor, NULL, NULL);
szMember = "Size";
pBaseSym->GetIDsOfNames(IID_NULL, (OLECHAR FAR **) &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
pBaseSym->Invoke(dispid,IID_NULL,LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET,&dispparamsNoArgs,
PvarSize, NULL, NULL);
g_hPen.CreatePen(PS_SOLID, PvarSize->decVal.wReserved, PvarColor->decVal.Lo64);
m_oldPen =pcdc->SelectObject(&g_hPen);
//*/ m_oldPen =(CPen*)pcdc->SelectStockObject(BLACK_PEN);
return S_OK;
}
STDMETHOD(ResetDC)(LONG hDC)
{
CDC* pcdc = CDC::FromHandle((HDC)hDC);
CPen* temp = pcdc->SelectObject(m_oldPen);
temp->DeleteObject();
return S_OK;
}
STDMETHOD(Draw)(LONG hDC, LONG * points, LONG * partCounts, LONG numParts)
{
POINT * P=(POINT *)points;
POINT MiddlePoint,ToPoint1,ToPoint2;
DOUBLE slope,TempSlope;
MiddlePoint.x=P->x;
MiddlePoint.y=P->y;
P++;
if (P->x!=MiddlePoint.x){
slope=(DOUBLE)(P->y-MiddlePoint.y)/(P->x-MiddlePoint.x);
slope=atan(slope);
}
else{
if(MiddlePoint.y>P->y)
slope=3.1415926/2.0;
else
slope=3.1415926*3.0/2.0;
}
MiddlePoint.x=(MiddlePoint.x+P->x)/2;
MiddlePoint.y=(MiddlePoint.y+P->y)/2;
//Get the end point of an Arrow
TempSlope=slope-inclination;
INT dx=(INT)(cos(TempSlope)*ArrowLEN);
INT dy=(INT)(sin(TempSlope)*ArrowLEN);
if(MiddlePoint.x<P->x){
ToPoint1.x=MiddlePoint.x-dx;
ToPoint1.y=MiddlePoint.y-dy;
}
else{
ToPoint1.x=MiddlePoint.x+dx;
ToPoint1.y=MiddlePoint.y+dy;
}
//Get the end point of another Arrow
TempSlope=slope+inclination;
dx=(INT)(cos(TempSlope)*ArrowLEN);
dy=(INT)(sin(TempSlope)*ArrowLEN);
if(MiddlePoint.x<P->x){
ToPoint2.x=MiddlePoint.x-dx;
ToPoint2.y=MiddlePoint.y-dy;
}
else{
ToPoint2.x=MiddlePoint.x+dx;
ToPoint2.y=MiddlePoint.y+dy;
}
CDC* pcdc=::CDC::FromHandle((HDC)hDC);
pcdc->MoveTo(ToPoint1);
pcdc->LineTo(MiddlePoint);
pcdc->LineTo(ToPoint2);
pcdc->PolyPolyline((POINT *)points,(DWORD *)partCounts,(int)numParts);
return S_OK;
}