终极无间
  • 注册日期
  • 发帖数
  • QQ
  • 铜币
  • 威望
  • 贡献值
  • 银元
阅读:2047回复:1

转贴----鼓励原创,也可以转贴~!

楼主#
更多 发布于:2003-07-28 10:21
其实做这个斑竹勉为其难啊
既然做了就做好他吧
将我所有的在网上下的东东都贴出来
欢迎大家指点的
喜欢0 评分0
终极无间
  • 注册日期
  • 发帖数
  • QQ
  • 铜币
  • 威望
  • 贡献值
  • 银元
1楼#
发布于:2003-07-28 10:22
转贴
数据绑定
CMapXBindLayer bLayer;
CMapXFields flds;

bLayer.CreateDispatch(bLayer.GetClsid());
flds.CreateDispatch(flds.GetClsid());

//Our source data in the correct tab-delimited form.
//In practice, this could come from a text file or some
//other source.
const char* tabifiedData =
"\"Cust1\"\t\"Loc1\"\t-72.40\t42.22\r\n"
"\"Cust2\"\t\"Loc2\"\t-75.40\t40.48\r\n"
"\"Cust3\"\t\"Loc3\"\t-76.40\t38.02\r\n";

bLayer.SetLayerName("Customer");
bLayer.SetRefColumn1(3);
bLayer.SetRefColumn2(4);
bLayer.SetLayerType(miBindLayerTypeXY);

flds.Add(1, "Customer");
flds.Add(2, "Location");
flds.Add(3, "X");
flds.Add(4, "Y");

//The global handle which will contain the actual data.
HGLOBAL hGlobalData=NULL;
//This temporarily points to the location of the locked
//handle's data

char* pHandleData=NULL;
COleVariant SourceData;

//Allocate space for the handle's data and copy the source
//data into it
hGlobalData = GlobalAlloc(GMEM_MOVEABLE, strlen(tabifiedData)+1);
pHandleData = (char*)GlobalLock(hGlobalData);
strcpy(pHandleData, tabifiedData);
GlobalUnlock(hGlobalData);
pHandleData = NULL;

//Point the SourceData variant at the global handle
SourceData.vt = VT_I4;
SourceData.lVal = (long)hGlobalData;

try {
//Now add the Dataset to the Datasets collection
COleVariant bindVt, fldsVt;
COptionalVariant optVt;

fldsVt.vt = VT_DISPATCH;
fldsVt.pdispVal = flds.m_lpDispatch;

bindVt.vt = VT_DISPATCH;
bindVt.pdispVal = bLayer.m_lpDispatch;

CMapXDataset ds = m_ctrlMapX.GetDatasets().Add(miDataSetGlobalHandle, SourceData, COleVariant("My Dataset"), COleVariant(1l), optVt, bindVt, fldsVt, optVt);

//Create a simple Theme from the data
ds.GetThemes().Add(COptionalVariant(), COptionalVariant(), COptionalVariant());
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}
举报 回复(0) 喜欢(0)     评分
游客

返回顶部