一种全新的软件界面设计方法[5]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 aweay 的 blog

可以看到只是简单返回了mycommandhandler对象,mycommandhandler必须继承自idispatch接口来实现支持自动化的调用方式,它是这样实现的:

class mycommandhandler : public idispatch

{

  long refcount;

public:

  mycommandhandler() :refcount(1){ }

  virtual hresult stdmethodcalltype gettypeinfocount(

            /* [out] */ uint *pctinfo){

    return s_ok;

  }

  virtual hresult stdmethodcalltype gettypeinfo(

      /* [in] */ uint itinfo,

      /* [in] */ lcid lcid,

      /* [out] */ itypeinfo **pptinfo){

      return s_ok;

  }

        virtual hresult stdmethodcalltype getidsofnames(

            /* [in] */ refiid riid,

            /* [size_is][in] */ lpolestr *rgsznames,

            /* [in] */ uint cnames,

            /* [in] */ lcid lcid,

            /* [size_is][out] */ dispid *rgdispid){

            *rgdispid=1;

            return s_ok;

        }

        virtual /* [local] */ hresult stdmethodcalltype invoke(

            /* [in] */ dispid dispidmember,

            /* [in] */ refiid riid,

            /* [in] */ lcid lcid,

            /* [in] */ word wflags,

            /* [out][in] */ dispparams *pdispparams,

            /* [out] */ variant *pvarresult,

            /* [out] */ excepinfo *pexcepinfo,

            /* [out] */ uint *puargerr){

            if(dispidmember==1)

            {

              messagebox(0,"hello world","hello",0); //place your code here

              frmweb->edit1->text="hello world(这也可以?)";

            }

            return s_ok;

        }

  virtual hresult stdmethodcalltype queryinterface(refiid classid, void** intf) {

    if (classid == iid_idispatch)

    {

      *intf = (idispatch*)this;

      addref();

    }

    else

      return e_nointerface;

    return s_ok;

  }

  virtual ulong stdmethodcalltype addref() {

    interlockedincrement(&refcount);

    return refcount;

  }

  virtual ulong stdmethodcalltype release() {

    interlockeddecrement(&refcount);

    if (refcount == 0)

      delete this;

    return refcount;

  }

};

本文关键:一种全新的软件界面设计方法
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top