关于如何用vc开放MO扩展符号库见“VC中custom symbol的方法(For MO)”一文。

关键代码如下:
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;
               
                //求箭头的一个终点
                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;
                }

                //求箭头的另外一个终点
                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;
        }

posted on 2005-10-09 15:12  刘民  阅读(1010)  评论(2编辑  收藏  举报