WEB开发网
开发学院软件开发VC 如何在ActiveX控件中使用字体 阅读

如何在ActiveX控件中使用字体

 2008-02-26 20:27:03 来源:WEB开发网   
核心提示:例程4:LabelEx.ocx例程4的控件名称为LabelEx.ocx,它是例程3代码的优化,如何在ActiveX控件中使用字体(11),实现与例程3完全相同的功能,打开Visual C++ 6.0,以求共勉,还望方家指教,新建LabelEx工程,接受所有默认设置,完成LabelEx工程创建

例程4:LabelEx.ocx

例程4的控件名称为LabelEx.ocx,它是例程3代码的优化,实现与例程3完全相同的功能。打开Visual C++ 6.0,新建LabelEx工程,接受所有默认设置,完成LabelEx工程创建。完成所有与例程3完全相同的操作,完成后再作如下改动和补充:

向控件头文件(CLabelExCtrl.H)中添加下列代码

DECLARE_INTERFACE_MAP() //声明接口映射
BEGIN_INTERFACE_PART(FontUpNotify,IPropertyNotifySink)
INIT_INTERFACE_PART(CLabelExCtrl,FontUpNotify)
   STDMETHOD(OnRequestEdit)(DISPID);
   STDMETHOD(OnChanged)(DISPID);
END_INTERFACE_PART(FontUpNotify)
   BEGIN_INTERFACE_PART(FontMiddleNotify,IPropertyNotifySink)
   INIT_INTERFACE_PART(CLabelExCtrl,FontMiddleNotify)
   STDMETHOD(OnRequestEdit)(DISPID);
   STDMETHOD(OnChanged)(DISPID);
   END_INTERFACE_PART(FontMiddleNotify)
   BEGIN_INTERFACE_PART(FontDownNotify,IPropertyNotifySink)
   INIT_INTERFACE_PART(CLabelExCtrl,FontDownNotify)
   STDMETHOD(OnRequestEdit)(DISPID);
   STDMETHOD(OnChanged)(DISPID);
   END_INTERFACE_PART(FontDownNotify)
在CLabelExCtrl的实现文件中加入该嵌套类的实现
BEGIN_INTERFACE_MAP(CLabelExCtrl,COleControl)
INTERFACE_PART(CLabelExCtrl,IID_IPropertyNotifySink,FontUpNotify)
INTERFACE_PART(CLabelExCtrl,IID_IPropertyNotifySink,FontMiddleNotify)
INTERFACE_PART(CLabelExCtrl,IID_IPropertyNotifySink,FontDownNotify)
END_INTERFACE_MAP()
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontUpNotify::AddRef()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontUpNotify)
     return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontUpNotify::Release()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontUpNotify)
     return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP CLabelExCtrl::XFontUpNotify::QueryInterface(REFIID iid,LPVOID FAR* ppvObj)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontUpNotify)
     return (HRESULT)pThis->ExternalQueryInterface(&iid,ppvObj);
}
STDMETHODIMP CLabelExCtrl::XFontUpNotify::OnChanged(DISPID)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontUpNotify)
     pThis->InvalidateControl();
   return NOERROR;
}
STDMETHODIMP CLabelExCtrl::XFontUpNotify::OnRequestEdit(DISPID)
{
   return NOERROR;
}
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontMiddleNotify::AddRef()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontMiddleNotify)
     return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontMiddleNotify::Release()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontMiddleNotify)
     return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP CLabelExCtrl::XFontMiddleNotify::QueryInterface(REFIID iid,LPVOID FAR* ppvObj)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontMiddleNotify)
     return (HRESULT)pThis->ExternalQueryInterface(&iid,ppvObj);
}
STDMETHODIMP CLabelExCtrl::XFontMiddleNotify::OnChanged(DISPID)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontMiddleNotify)
     pThis->InvalidateControl();
   return NOERROR;
}
STDMETHODIMP CLabelExCtrl::XFontMiddleNotify::OnRequestEdit(DISPID)
{
   return NOERROR;
}
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontDownNotify::AddRef()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontDownNotify)
     return (ULONG)pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CLabelExCtrl::XFontDownNotify::Release()
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontDownNotify)
     return (ULONG)pThis->ExternalRelease();
}
STDMETHODIMP CLabelExCtrl::XFontDownNotify::QueryInterface(REFIID iid,LPVOID FAR* ppvObj)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontDownNotify)
     return (HRESULT)pThis->ExternalQueryInterface(&iid,ppvObj);
}
STDMETHODIMP CLabelExCtrl::XFontDownNotify::OnChanged(DISPID)
{
   METHOD_PROLOGUE_EX(CLabelExCtrl,FontDownNotify)
     pThis->InvalidateControl();
   return NOERROR;
}
STDMETHODIMP CLabelExCtrl::XFontDownNotify::OnRequestEdit(DISPID)
{
   return NOERROR;
}
CLabelExCtrl类的构造函数的代码作如下改动 CLabelExCtrl::CLabelExCtrl():m_fontUp(&m_xFontUpNotify),
m_fontMiddle(&m_xFontMiddleNotify),m_fontDown(&m_xFontDownNotify)
{
   InitializeIIDs(&IID_DLabelEx, &IID_DLabelExEvents);
   // TODO: Initialize your control''s instance data here.
}
 

 对项目执行完这些更改后,重新生成项目,并使用测试容器测试接口。本人初学VC++,所学粗浅,发表此文,以求共勉,还望方家指教。

e-mail:han_yao_xu@163.com 或 han_yao_xu@126.com。

上一页  6 7 8 9 10 11 

Tags:如何 ActiveX 控件

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接