乌拉圭软件作者gonchuki开发的变色龙按钮非常漂亮,也非常著名。源代码公开的版本最新为2.0.6B,下载地址为:http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=37471&lngWId=1
由于该版本是VB开发的,在某些其它的IDE中有些属性不支持,比如说在VC中不支持ToolTipText。我将它改写为一个VC版本。但是该版本比2.0.6B有点删减,比如说gonchuki支持的按钮快捷键我改写的不支持。
另外,我新加了一种Graphic按钮类型,该类型按钮显示4个图片:通常状态图片、按下图片、鼠标移动在按钮上时的图片、Disable时图片,并且在这种类型下,没有按钮边框,可以让开发人员轻松灵活地制作各种按钮效果。
BLOG好像不能上传附件,我只好将接口定义文件及控件的H、CPP文件列出如下(我使用VC6创建的是MFC控件工程,工程名称是Chameleon)
(最后:重发布请注明原作者gonchuki):
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Chameleon.odl
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Chameleon.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 (Chameleon.tlb) that will become a resource in
// Chameleon.ocx.
#include <olectl.h>
#include <idispids.h>
[ uuid(56102E2F-1E92-4CE0-9007-507506A21492), version(1.0),
helpfile("Chameleon.hlp"),
helpstring("ChameleonButton,based on gonchuki's work"),
control ]
library CHAMELEONLib
{
importlib(STDOLE_TLB);
importlib(STDTYPE_TLB);
// Primary dispatch interface for CChameleonCtrl
[ uuid(CBD15FBF-9BA7-46C5-B013-5F75A5750E31),
helpstring("Dispatch interface for Chameleon Control"), hidden ]
dispinterface _DChameleon
{
properties:
// NOTE - ClassWizard will maintain property information here.
// Use extreme caution when editing this section.
//{{AFX_ODL_PROP(CChameleonCtrl)
[id(DISPID_BACKCOLOR), bindable, requestedit] OLE_COLOR BackColor;
[id(DISPID_TEXT), bindable, requestedit] BSTR Text;
[id(DISPID_ENABLED), bindable, requestedit] boolean Enabled;
[id(DISPID_FONT), bindable] IFontDisp* Font;
[id(DISPID_FORECOLOR), bindable, requestedit] OLE_COLOR ForeColor;
[id(DISPID_HWND)] OLE_HANDLE hWnd;
[id(1)] long MousePointer;
[id(2)] IPictureDisp* MouseIcon;
[id(3)] IPictureDisp* Picture;
[id(4)] long ButtonType;
[id(5)] long ColorScheme;
[id(6)] boolean Press;
[id(7)] boolean ShowFocusRect;
[id(8)] boolean Stretch;
[id(9)] BSTR ToolTipText;
[id(10)] OLE_COLOR BackOverColor;
[id(11)] OLE_COLOR ForeOverColor;
[id(12)] long TextEffect;
[id(13)] boolean HandPointer;
[id(14)] IPictureDisp* DownPicture;
[id(15)] IPictureDisp* OverPicture;
[id(16)] IPictureDisp* DisablePicture;
//}}AFX_ODL_PROP
methods:
// NOTE - ClassWizard will maintain method information here.