本文以实例形式讲解了VC++中HTControl控件类的CHTButton按钮控件类用法,相信对大家更好的理解VC++有一定的帮助。具体内容如下:
一般了解VC++的朋友都知道,VC++ 按钮控件CHTButton隶属HTControl控件组,直接由WIN32 API实现,你可以在SDK,MFC,wxWidget等环境下使用它。支持生成各种类型的按钮,比如:普通按钮,PNG透明按钮,复选框按钮,单选按钮等。使用时请注意,窗体必须动态创建,代码段如下:
m_HTBtnClose.Create(758, 0, 39, 20, m_hWnd, iChildId++); m_HTBtnClose.SetAllBitmap(m_hBmpBtnCloseNormal, m_hBmpBtnCloseDown,m_hBmpBtnCloseHover); m_HTBtnClose.SetParentBgMemDC(m_hdcMemBuf);
CHTButton.h控件核心代码及注释说明如下:
#if !defined(__CHTBUTTON_H__)
#define __CHTBUTTON_H__
#include "CHTTip.h"
class CMyButton;
class AFX_CLASS_EXPORT CHTButton
{
public:
CHTButton();
~CHTButton();
HWND Create(int x, int y, int iWidth, int iHeight, HWND hParent, int iBtnId,
TCHAR* szLabel = NULL, DWORD dwStyle = NULL);
void MoveWindow(int x, int y, int iWidth = -1, int iHeight = -1, BOOL bRepaint = TRUE);
void SetToolTip(CHTTip* pclTip);
void SetTipText(TCHAR* szTipText);
HWND GetHandle();
HWND GetParent();
void SetFont(HFONT hFont);
void SetBtnTextColor(COLORREF CRText);
void SetHoverFont(HFONT hFont);
void SetHoverBtnTextColor(COLORREF CRText);
void Disable();
void Enable();
void SetLabel(TCHAR* szLabel, POINT* point = NULL, BOOL bTextMove = TRUE);
TCHAR* GetLabel();
int GetState();
void SetLongPressTime(WORD wLongPressTime);
void SetCheck(BOOL bCheck);
BOOL GetCheck();
void SetNormalBitmap(HBITMAP hBitmap, int iNormalLeftLen = 0, int iNormalRightLen = 0);
void SetLBtnDownBitmap(HBITMAP hBitmap);
void SetHoverBitmap(HBITMAP hBitmap);
void SetDisableBitmap(HBITMAP hBitmap);
void SetAllBitmap(HBITMAP hBitmapNormal, HBITMAP hBitmapLBtnDown, HBITMAP hBitmapHover,
int iNormalLeftLen = 0, int iNormalRightLen = 0);
void SetIcon(HBITMAP hBitmap, RECT* pIconRect);
void SetTransparency(int iTransparency);
void SetParentBgMemDC(HDC hParentBgMemDC, int x = 0, int y = 0);
void SetParentBgBitmap(HBITMAP hParentBgBitmap, int x = 0, int y = 0);
void SetParentBgColor(COLORREF CRParentBg = RGB(236, 233, 216));
void DrawWindow(HDC hdcDest, int x = 0, int y = 0);
CMyButton* GetCMyButton();
private:
CMyButton* m_pclBtn;
};
#endif //!__CHTBUTTON_H__
此类支持窗体以任意透明度显示,操作很简单,使用下面接口即可实现:
void SetTransparency(int iTransparency);
CHTButton类同时也实现了PNG透明按钮,感兴趣的读者可以自己测试一下。



