技术员
Network change life, change t
- 积分
- 17879
|
继承CGisView类的技巧
1. OnDraw函数如下:
void CccView::OnDraw(CDC* pDC)
{
CW32_tstDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(!pDC->IsPrinting())
CGisView::OnDraw(pDC);
}
2. _OwnerDraw函数如下:
void CccView::_OwnerDraw(MyDC myDC)
{
short ti,i;
short *pLst;
short type;
_GetAreaList(&pLst);
if(pLst==NULL)
return;
for(ti=0;ti<4;ti++) //循环4次,依次显示 区,线,点,网
{
switch(ti)
{
case 0: type=REG; break;
case 1: type=NET; break;
case 2: type=LIN; break;
case 3: type=PNT; break;
}
for(i=1;i<=pLst[0];i++)
{
if(type!=_GetAreaType(pLst))
continue;
switch(type)
{
case PNT: _DispPntArea(myDC,pLst); break;
case LIN: _DispLinArea(myDC,pLst); break;
case REG: _DispRegArea(myDC,pLst); break;
case NET: _DispLinArea(myDC,pLst); break;
default: break;
}
}
}
}
3. 工作区实例最好放在CccApp类中:
class CccApp : public CWinApp
{
public:
AREA_HINST m_AHInst;
......
}
在CccApp类的初始化函数中进行初始化:
BOOL CccApp::InitInstance()
{
AfxEnableControlContainer();
......
m_AHInst=_InitWorkArea(NULL); //初始化工作区实例
return TRUE;
}
在CccApp类的结束函数中进行关闭:
int CccApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
_FreeWorkArea(m_AHInst); //释放工作区实例,功能与_CloseAllArea相同
return CWinApp::ExitInstance();
}
4. “装入点文件”、“装入线文件”、“装入区文件”功能如下:
void CccView:oadAFile(short fType)
{
CccApp *ptApp;
short ai,i;
short *pOldLst;
short *pNewLst;
ptApp=(CccApp *)AfxGetApp(); //取当前应用程序对象地址
ai=_OpenArea(ptApp->m_AHInst,fType); //打开一个fType类型的空工作区
if(ai<=0) //失败则返回
return;
if(!_LoadFile(ai)) //装入文件到ai工作区,若失败则关闭工作区,然后返回
{
_CloseArea(ai);
return;
}
_GetAreaList(&pOldLst); //取当前视窗口对应的工作区,若没有,则pOldLst返回NULL
if(pOldLst) //pOldLst!=NULL,说明当前视窗口已经有对应的工作区,保存原来对应的工作区
{
pNewLst=new short [pOldLst[0]+2];
pNewLst[0]=pOldLst[0]+1;
for(i=1;i<=pOldLst[0];i++)
pNewLst=pOldLst;
}
else
{
pNewLst=new short [2];
pNewLst[0]=1;
i=1;
}
pNewLst=ai; //再添加新的工作区
_SetAreaList(pNewLst); //重新设置当前视窗口对应的工作区
delete[] pNewLst;
_RestoreWindow(); //复位当前视窗口
return;
}
void CccView::OnLoadPnt()
{
// TODO: Add your command handler code here
LoadAFile(PNT);
}
void CccView::OnLoadLin()
{
// TODO: Add your command handler code here
LoadAFile(LIN);
}
void CccView::OnLoadReg()
{
// TODO: Add your command handler code here
LoadAFile(REG);
}
void CDbs_demoView::OnRButtonDown(UINT nFlags, CPoint point)
{
HMENU hmn;
if(dbsView<=0) return;
GetCursorPos(&point);
//添加右键弹出菜单
hmn=CreatePopupMenu();
AppendMenu(hmn,MF_ENABLED,ID_DBS_ROVE,"允许图库漫游");
AppendMenu(hmn,MF_ENABLED,ID_RESTORE_WIN,"复位窗口");
AppendMenu(hmn,MF_ENABLED,ID_ENLARGE_WIN,"开窗口");
AppendMenu(hmn,MF_ENABLED,ID_LAST_WIN,"上级窗口");
AppendMenu(hmn,MF_ENABLED,ID_UPDATE_WIN,"更新窗口");
AppendMenu(hmn,MF_ENABLED,ID_CLEAR_WIN,"清窗口");
TrackPopupMenu(hmn,NULL,point.x,point.y,NULL,m_hWnd,NULL);
DestroyMenu(hmn);
CView::OnRButtonDown(nFlags, point);
} |
|