我在MapX中添加一个UserLayer,功能是添加个比例尺显示在地图左上角,那段代码是从别人的源码考过来的,地图单位和我的不一样,我的是Km,运行后可以显示比例尺,但弹出个对话框说Property or Method not supported by layers of this type.点击确定又弹出,就这样不断地弹出来,程序没法使用了,那位知道这是怎么回事,帮帮忙啊,谢谢了!!
下面是代码
void CWLDispView::OnDrawUserLayer(LPDISPATCH Layer, long hOutputDC, long hAttributeDC, 
  LPDISPATCH RectFull, LPDISPATCH RectInvalid)
{
float barWidth =(float)0.5, barHeight =(float)0.08;
float startX =(float).3, startY =(float).3;
long x1, y1;
int i; // attach to dc that mapx passed us so we can use 
// mfc CDC object. (we will detach before exiting this method
CDC dc;
CPen pen;
CBrush brushRed, brushWhite, *pOldBrush;
CFont *pOldFont;

pen.CreatePen(0,1,(COLORREF)0);
brushRed.CreateSolidBrush(255);
brushWhite.CreateSolidBrush(16777215); dc.Attach((HDC)hOutputDC);
dc.SetAttribDC((HDC)hAttributeDC); //Set map mode to HI-English
dc.SetMapMode(MM_HIENGLISH);
//Set pen to black
CPen *pOldPen = dc.SelectObject(&pen);
pOldBrush = dc.SelectObject(&brushRed); //convert to HiEnglish, Conversion needed because one HIENGLISH unit is .001 inch
x1=(long)(startX*1000);
y1=(long)(startY*1000);
barWidth*=1000;
barHeight*=1000; for (i=0; i<=1; i++) {
long x2 =(long)(barWidth+x1);
long y2 =(long)(barHeight+y1);

/*** First Section  ***/
if (i==0) {
dc.SelectObject(&brushRed); //Red
}
else {
dc.SelectObject(&brushWhite); //White
} // with mapMode HIENGLISH, positive is x to the right, positive y is up
dc.Rectangle(x1, -y1, x2, -y2); /*** Second Section ***/
x1=x2;
x2=(long)(barWidth+x1);
if (i==0) {
dc.SelectObject(&brushWhite); //White
}
else {
dc.SelectObject(&brushRed); //Red
}
dc.Rectangle(x1, -y1, x2, -y2); /*** Third Section ***/
x1=x2;
x2=(long)(barWidth*2+x1);
if (i==0) {
dc.SelectObject(&brushRed); //Red
}
else {
dc.SelectObject(&brushWhite); //White
}
dc.Rectangle(x1, -y1, x2, -y2);

/*** Reset Values for bottom bar pass***/
x1=(long)(startX*1000);
y1=y2;
}  // End For // Calculate Pixels Per Inch
CPoint pt(1000, 1000); // In HIENGLISH 1000 units = 1 inch
dc.LPtoDP(&pt);  // Convert inch to pixel
long lPixPerInch = pt.x; CRect rc;
CView::GetClientRect(&rc); float screenX, screenY;
double mapX1, mapY1;
// subtract lPixPerInch from center to get 1 inch to left of Center
screenX = (float)(rc.right/2-lPixPerInch);
screenY = (float)(rc.bottom/2);
try { 
m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX1, &mapY1, miScreenToMap);
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}

double mapX2, mapY2;
// add lPixPerInch to center to get 1 inch to right of Center
screenX = (float)(rc.right/2+lPixPerInch);
screenY = (float)(rc.bottom/2);
try {
m_ctrlMapX.ConvertCoord(&screenX, &screenY, &mapX2, &mapY2, miScreenToMap);
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}
CFont font;
font.CreatePointFont(100, "Arial", &dc); pOldFont = dc.SelectObject(&font);
dc.SetTextColor(0); //Black
dc.SetBkMode(TRANSPARENT); // Output ScaleBar start Label = 0
x1=(long)(startX*1000);
y1=(long)((startY-.2)*1000);
dc.TextOut(x1,-y1,"0"); // Output label for distance of 1 inch
x1=(long)(barWidth*2+startX*1000); CString str;
str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2)/2);
// Need to center text over center line.  will move it 60 units for each character
int iCenterAdjustment = 60*str.GetLength();
dc.TextOut(x1-iCenterAdjustment,-y1,str); // Output label for distance of 2 inches
x1=(long)(barWidth*4+startX*1000); str.Format("%.0f",m_ctrlMapX.Distance(mapX1, mapY1, mapX2, mapY2));
// Need to center text over end line.  will move it 60 units for each character
iCenterAdjustment = 60*str.GetLength();
dc.TextOut(x1-iCenterAdjustment,-y1,str); // Output label for Units "Miles"
x1=(long)(barWidth*2+startX*1000);
y1=(long)((startY+.2)*1000);
// Need to center text over center line.  will move it 60 units for each character
str.Format("Miles");
iCenterAdjustment = 60*str.GetLength();
dc.TextOut(x1-iCenterAdjustment,-y1,str); dc.SelectObject(pOldBrush);
dc.SelectObject(pOldPen);
dc.SelectObject(pOldFont); // detach dc so destructore won't call Release it
dc.ReleaseAttribDC();
dc.Detach();
}