现在让我们来创建我们的MapX基石吧。
第一步:用VC++的程序向导来创建一个单文档程序MapXSample。
第二步:Project> Add To Project>Files,选择MapX.cpp和MapX.h。
第三步:定义一个CmapX对象。
class CMapxSampleView : public CView
{
……
protected:
CMapX m_ctrlMapX;
……
}
第四步:声明一个常量。View > Resource Symbols>New>name为IDC_MAP。
第五步:在类向导中为CMapXSampleView创建WM_SIZE 和 WM_CREATE的处理消息:
void CMapxSampleView::OnCreate(UINT nType, int cx, int cy)
{
m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0,0,100,100), this,IDC_MAP);
}
void CMapxSampleView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
m_ctrlMapX.MoveWindow(0,0,cx,cy,TRUE);
}
第六步:在类向导中为CMapXSampleView创建WM_SETFOCUS的处理消息,以确保当窗口处于活动状态时得到焦点。
void CMapxSampleView::OnSetFocus(CWnd* pOldWnd)
{
CView::OnSetFocus(pOldWnd);
m_ctrlMapX.SetFocus();
}
然后编译运行。看到了吗?这个就是一个最基本的MapX程序了,我把它称为“MapX的基石”,因为以后的程序都是在这个程序的基础上“缝缝补补”而来的。
本人超级菜鸟一个,在网上找了个教程,按上面做时,出现一点不同int CMapXSampleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_ctrlMapX.Create(NULL, WS_VISIBLE, CRect(0, 0, 100, 100), this, IDC_MAP);
return 0;
}
可以看到函数的参数和教程中的函数参数不一样的。
然后编译执行出现以下错误:
--------------------Configuration: MapXSample - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
MainFrm.cpp
MAPX.CPP
MapXSample.cpp
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2146: syntax error : missing ';' before identifier 'm_ctrlMapX'
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2501: 'CMapX' : missing storage-class or type specifiers
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2501: 'm_ctrlMapX' : missing storage-class or type specifiers
MapXSampleDoc.cpp
MapXSampleView.cpp
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2146: syntax error : missing ';' before identifier 'm_ctrlMapX'
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2501: 'CMapX' : missing storage-class or type specifiers
e:\microsoft\myproject\mapxsample\mapxsampleview.h(47) : error C2501: 'm_ctrlMapX' : missing storage-class or type specifiers
E:\Microsoft\MyProject\MapXSample\MapXSampleView.cpp(113) : error C2065: 'm_ctrlMapX' : undeclared identifier
E:\Microsoft\MyProject\MapXSample\MapXSampleView.cpp(113) : error C2228: left of '.Create' must have class/struct/union type
E:\Microsoft\MyProject\MapXSample\MapXSampleView.cpp(122) : error C2228: left of '.MoveWindow' must have class/struct/union type
E:\Microsoft\MyProject\MapXSample\MapXSampleView.cpp(130) : error C2228: left of '.SetFocus' must have class/struct/union type
Generating Code...
Error executing cl.exe.
MapXSample.exe - 10 error(s), 0 warning(s)
请前辈们指导指导,我弄了一个晚上,google,baidu了很多也没解决。