In VC++ HTControl CHTButton control class usage instance resolution

  • 2020-04-02 02:33:31
  • OfStack

This article in the form of an example to explain the HTControl control class in VC++ CHTButton control class class usage, I believe that we have a better understanding of VC++ has certain help. The specific contents are as follows:

Generally know VC++ friends know, VC++ button control CHTButton belongs to HTControl control control group, directly by WIN32 API, you can use it in the SDK, MFC, wxWidget and other environments. Support for generating various types of buttons, such as: normal buttons, PNG transparent buttons, checkbox buttons, radio buttons, etc. When using, please note that the form must be created dynamically. The code snippet is as follows:


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 control core code and comments are as follows:



#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__

This class supports the form to be displayed with arbitrary transparency. The operation is simple and can be realized by using the following interface:


void SetTransparency(int iTransparency);

The CHTButton class also implements PNG transparent buttons, which interested readers can test themselves.


Related articles: