如何让一个控件支持CCmdTarget类,
class CMapX : public CWnd
{
protected:
DECLARE_DYNCREATE(CMapX)
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }#elseclass CMapX : public COleDispatchDriver
{
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
#endif //of #ifdef CWND_MAPX // default bAddRef is false because you don't need to addref
// when passing result to Feature.Attach();
LPDISPATCH GetDispatch(BOOL bAddRef=FALSE);// Attributes
public:
CString GetVersion();
OLE_HANDLE GetHWnd();
CMapXAnnotations GetAnnotations();
CMapXLayers GetLayers();
BOOL GetAutoRedraw();
void SetAutoRedraw(BOOL);
double GetZoom();
void SetZoom(double);
double GetCenterX();
void SetCenterX(double);
double GetCenterY();
void SetCenterY(double);
CString GetGeoSet();
void SetGeoSet(LPCTSTR);
double GetGeoSetWidth();
double GetMapPaperHeight();
double GetMapPaperWidth();
short GetMaxSearchTime();
void SetMaxSearchTime(short);
long GetPaperUnit();
void SetPaperUnit(long);
BOOL GetPreferCompactLegends();
void SetPreferCompactLegends(BOOL);
CMapXStyle GetDefaultStyle();
void SetDefaultStyle(LPDISPATCH);
CString GetGeoDictionary();
// this method currently will not work in 'run' mode. which
// is the only mode MFC Control containers support, so don't bother calling it.
void SetGeoDictionary(LPCTSTR); long GetDataSetTheme();
void SetDataSetTheme(long);
};
类似这个
class CMapX : public CWnd
{
protected:
DECLARE_DYNCREATE(CMapX)
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }#elseclass CMapX : public COleDispatchDriver
{
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
#endif //of #ifdef CWND_MAPX // default bAddRef is false because you don't need to addref
// when passing result to Feature.Attach();
LPDISPATCH GetDispatch(BOOL bAddRef=FALSE);// Attributes
public:
CString GetVersion();
OLE_HANDLE GetHWnd();
CMapXAnnotations GetAnnotations();
CMapXLayers GetLayers();
BOOL GetAutoRedraw();
void SetAutoRedraw(BOOL);
double GetZoom();
void SetZoom(double);
double GetCenterX();
void SetCenterX(double);
double GetCenterY();
void SetCenterY(double);
CString GetGeoSet();
void SetGeoSet(LPCTSTR);
double GetGeoSetWidth();
double GetMapPaperHeight();
double GetMapPaperWidth();
short GetMaxSearchTime();
void SetMaxSearchTime(short);
long GetPaperUnit();
void SetPaperUnit(long);
BOOL GetPreferCompactLegends();
void SetPreferCompactLegends(BOOL);
CMapXStyle GetDefaultStyle();
void SetDefaultStyle(LPDISPATCH);
CString GetGeoDictionary();
// this method currently will not work in 'run' mode. which
// is the only mode MFC Control containers support, so don't bother calling it.
void SetGeoDictionary(LPCTSTR); long GetDataSetTheme();
void SetDataSetTheme(long);
};
类似这个
实现
class CMapX : public CWnd
{
protected:
DECLARE_DYNCREATE(CMapX)
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); } BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); } #else class CMapX : public COleDispatchDriver
{
public:
CLSID const& GetClsid()
{
static CLSID const clsid =
{ 0x9d6ed188, 0x5910, 0x11d2, { 0x98, 0xa6, 0x0, 0xa0, 0xc9, 0x74, 0x2c, 0xca } };
return clsid;
}
#endif //of #ifdef CWND_MAPX // default bAddRef is false because you don't need to addref
// when passing result to Feature.Attach();
LPDISPATCH GetDispatch(BOOL bAddRef=FALSE); // Attributes
public:
CString GetVersion();
}
j这样一个简单的ocx,即可以
然后,你需要创建另外一个工程,譬如一个基于对话框的应用程序,然后在菜单中找到
Project->Add to project->Components and controls,在其中找到你的ocx文件,然后就可以了。
后面的其他操作没有