孙鑫CButtonST 下载本文

内容发布更新时间 : 2024/12/28 12:06:35星期一 下面是文章的全部内容请认真阅读。

BtnST.cpp

// BtnST.cpp : implementation file //

#include \ #include \ #ifdef _DEBUG

#define new DEBUG_NEW #undef THIS_FILE

static char THIS_FILE[] = __FILE__; #endif

///////////////////////////////////////////////////////////////////////////// // CButtonST

CButtonST::CButtonST() {

m_MouseOnButton = FALSE; m_hIconIn = NULL; m_hIconOut = NULL; m_cxIcon = 0; m_cyIcon = 0;

m_hCursor = NULL;

// Default type is \ m_bIsFlat = TRUE;

// By default draw border in \ m_bDrawBorder = TRUE;

// By default icon is aligned horizontally m_nAlign = ST_ALIGN_HORIZ;

// By default show the text button m_bShowText = TRUE;

// By default, for \ m_bDrawFlatFocus = FALSE; SetDefaultInactiveBgColor(); SetDefaultInactiveFgColor(); SetDefaultActiveBgColor(); SetDefaultActiveFgColor(); } // End of CButtonST CButtonST::~CButtonST() {

// Destroy the icons (if any)

if (m_hIconIn != NULL) ::DeleteObject(m_hIconIn); if (m_hIconOut != NULL) ::DeleteObject(m_hIconOut); // Destroy the cursor (if any)

if (m_hCursor != NULL) ::DestroyCursor(m_hCursor); } // End of ~CButtonST

BEGIN_MESSAGE_MAP(CButtonST, CButton)

//{{AFX_MSG_MAP(CButtonST) ON_WM_CAPTURECHANGED() ON_WM_SETCURSOR() ON_WM_KILLFOCUS() ON_WM_MOUSEMOVE() //}}AFX_MSG_MAP

END_MESSAGE_MAP()

void CButtonST::SetIcon(int nIconInId, int nIconOutId, BYTE cx, BYTE cy) {

HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId),RT_GROUP_ICON); // Set icon when the mouse is IN the button m_hIconIn = (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0); // Set icon when the mouse is OUT the button m_hIconOut = (nIconOutId == NULL) ? m_hIconIn : (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);

m_cxIcon = cx; m_cyIcon = cy;

RedrawWindow(); } // End of SetIcon

BOOL CButtonST::SetBtnCursor(int nCursorId) {

HINSTANCE hInstResource; // Destroy any previous cursor

if (m_hCursor != NULL) ::DestroyCursor(m_hCursor); m_hCursor = NULL; // If we want a cursor if (nCursorId != -1) {

hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId),RT_GROUP_CURSOR); // Load icon resource m_hCursor = (HCURSOR)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0); // If something wrong then return FALSE if (m_hCursor == NULL) return FALSE; }

return TRUE;

} // End of SetBtnCursor

void CButtonST::SetFlat(BOOL bState) {

m_bIsFlat = bState; Invalidate();

} // End of SetFlat BOOL CButtonST::GetFlat()

{ return m_bIsFlat; } // End of GetFlat void CButtonST::SetAlign(int nAlign) {

switch (nAlign) {

case ST_ALIGN_HORIZ: m_nAlign = ST_ALIGN_HORIZ; break;

case ST_ALIGN_VERT:

m_nAlign = ST_ALIGN_VERT; break; }

Invalidate();

} // End of SetAlign

int CButtonST::GetAlign()

{ return m_nAlign; } // End of GetAlign

void CButtonST::DrawBorder(BOOL bEnable)

{ m_bDrawBorder = bEnable; } // End of DrawBorder

const char* CButtonST::GetVersionC() { return \ } // End of GetVersionC

const short CButtonST::GetVersionI() { return 23; // Divide by 10 to get actual version } // End of GetVersionI

void CButtonST::SetShowText(BOOL bShow) { m_bShowText = bShow; Invalidate(); } // End of SetShowText

BOOL CButtonST::GetShowText() { return m_bShowText; } // End of GetShowText void CButtonST::OnMouseMove(UINT nFlags, CPoint point) { CWnd* pWnd; // Finestra attiva

CWnd* pParent; // Finestra che contiene il bottone CButton::OnMouseMove(nFlags, point);

// If the mouse enter the button with the left button pressed