如何让一个控件支持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);
};
类似这个

解决方案 »

  1.   

    这个是我们专业gis的ocx,我想知道其原理,  这个是如何实现的?
      

  2.   

    CWnd就是从CCmdTarget派生的,你写的代码看上去像是从一个ocx生成的代理类。
      

  3.   

    代理类是编译器自动产生的。至于这个ocx,不知道都有什么功能,实现方法很多的。可以使用atl,mfc,sdk来实现。
      

  4.   

    使用mfc activex appwizard一路默认。
      

  5.   

    但是我操作后,只有继承 cwnd,没有COleDispatchDriver ,这个如何写,用mfc方式,
    实现
    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,即可以
      

  6.   

    使用mfc activex appwizard一路默认,得到的是一个ActiveX控件,你编译之后可以得到一个注册过的ocx.
    然后,你需要创建另外一个工程,譬如一个基于对话框的应用程序,然后在菜单中找到
    Project->Add to project->Components and controls,在其中找到你的ocx文件,然后就可以了。
      

  7.   

    但是没有class CMapX : public COleDispatchDriver 这个
    后面的其他操作没有