把 enum 写到 typelib 定义文件中去
举例:(我自己编的控件代码)
// HoverButton.odl : type library source for ActiveX Control project.// This file will be processed by the Make Type Library (mktyplib) tool to
// produce the type library (HoverButton.tlb) that will become a resource in
// HoverButton.ocx.#include <olectl.h>
#include <idispids.h>[ uuid(A6B9C705-C1B5-11D2-AB5E-0000E82A9730), version(1.0),
  helpfile("HoverButton.hlp"),
  helpstring("HoverButton ActiveX Control module"),
  control ]
library HOVERBUTTONLib
{
importlib(STDOLE_TLB);
importlib(STDTYPE_TLB); //  Primary dispatch interface for CHoverButtonCtrl
typedef
[ uuid(CD470FA1-CB0F-11d2-AB5E-0000E82A9730),
  helpstring("Dispatch interface for HoverButton Control Style") ]
enum tagBtnStyle
{
[helpstring("Simple")] BS_NONE = 0,
[helpstring("Flat Button")] BS_FLAT = 1,
[helpstring("Spot Light")] BS_SPOT = 2,
}BTNSTYLE; [ uuid(A6B9C706-C1B5-11D2-AB5E-0000E82A9730),
  helpstring("Dispatch interface for HoverButton Control"), hidden ]
dispinterface _DHoverButton
{
properties:
// NOTE - ClassWizard will maintain property information here.
//    Use extreme caution when editing this section.
//{{AFX_ODL_PROP(CHoverButtonCtrl)
[id(DISPID_CAPTION), bindable, requestedit] BSTR Caption;
[id(DISPID_FONT), bindable] IFontDisp* Font;
[id(DISPID_BACKCOLOR), bindable, requestedit] OLE_COLOR BackColor;
[id(DISPID_FORECOLOR), bindable, requestedit] OLE_COLOR ForeColor;
[id(3)] IPictureDisp* Picture;
[id(1)] OLE_COLOR SpotBackColor;
[id(2)] OLE_COLOR SpotForeColor;
[id(4)] BTNSTYLE Style;
//}}AFX_ODL_PROP methods:
// NOTE - ClassWizard will maintain method information here.
//    Use extreme caution when editing this section.
//{{AFX_ODL_METHOD(CHoverButtonCtrl)
//}}AFX_ODL_METHOD [id(DISPID_ABOUTBOX)] void AboutBox();
}; //  Event dispatch interface for CHoverButtonCtrl [ uuid(A6B9C707-C1B5-11D2-AB5E-0000E82A9730),
  helpstring("Event interface for HoverButton Control") ]
dispinterface _DHoverButtonEvents
{
properties:
//  Event interface has no properties methods:
// NOTE - ClassWizard will maintain event information here.
//    Use extreme caution when editing this section.
//{{AFX_ODL_EVENT(CHoverButtonCtrl)
[id(DISPID_CLICK)] void Click();
[id(DISPID_DBLCLICK)] void DblClick();
//}}AFX_ODL_EVENT
}; //  Class information for CHoverButtonCtrl [ uuid(A6B9C708-C1B5-11D2-AB5E-0000E82A9730),
  helpstring("HoverButton Control"), control ]
coclass HoverButton
{
[default] dispinterface _DHoverButton;
[default, source] dispinterface _DHoverButtonEvents;
};
//{{AFX_APPEND_ODL}}
//}}AFX_APPEND_ODL}}
};

解决方案 »

  1.   

    如果我用MFC模板,又该如何?程序中是否还要定义此枚举类型,我要对属性进行操作。
      

  2.   

    程序中不必定义为枚举类型,只要是 int 形就可以了。
    至于MFC模板?请贴源代码,以及标示以下哪个地方要改成枚举类型
      

  3.   

    是这样。我要写一个串口通讯的控件,控件的属性中有串口的波特率、停止位等等。我想在用户使用控件时,该属性显示的值为有意义的值。比如:停止位属性显示为STOP_1。可不可以说的详细些,最好再附上源代码。谢谢。
      

  4.   

    请问solomon在.odl中枚举类型的定义是怎样加进去的,直接修改.odl文件吗?还是有别的途径。另外,如果我要做一个属性页,我怎样定义属性页中相应属性的类型,如何使属性的显示和在DELPHI中的Inspect中的一样。
      

  5.   

    是直接修改.odl文件。
    属性在old 是对外部程序而言的。属性页可以是任何类型,只要匹配byte
    比如,枚举型 = int
    Inspect 的树状显示好像是delphi 特有的,ocx 不支持。
      

  6.   

    solomon,谢谢你的帮助。不过我现在还是有些迷糊。能不能E我一个简单的控件(含属性页)包含枚举类型属性。或者推荐基本书。