所有的头文件类CBtnST.h
//
// Class: CButtonST
//
// Compiler: Visual C++
// Tested on: Visual C++ 5.0
// Visual C++ 6.0
//
// Version: See GetVersionC() or GetVersionI()
//
// Created: xx/xxxx/1998
// Updated: 03/March/2003
//
// Author: Davide Calabro' davide_calabro@yahoo.com
// http://www.softechsoftware.it
//
// Note: Code for the PreSubclassWindow and OnSetStyle functions
// has been taken from the COddButton class
// published by Paolo Messina and Jerzy Kaczorowski
//
// Disclaimer
// ----------
// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
// RISK OF USING THIS SOFTWARE.
//
// Terms of use
// ------------
// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
// ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:
//
// Davide Calabro'
// P.O. Box 65
// 21019 Somma Lombardo (VA)
// Italy
//
#ifndef _BTNST_H
#define _BTNST_H
// Uncomment the following 2 lines to enable support for BCMenu class
#define BTNST_USE_BCMENU
// Uncomment the following line to enable support for sound effects
#define BTNST_USE_SOUND
class CButtonST : public CButton
{
public:
CButtonST();
~CButtonST();
enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right
ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom
ST_ALIGN_HORIZ_RIGHT, // Icon/bitmap on the right, text on the left
ST_ALIGN_OVERLAP // Icon/bitmap on the same space as text
};
enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside
BTNST_COLOR_FG_IN, // Text color when mouse is INside
BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside
BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside
BTNST_COLOR_BK_FOCUS, // Background color when the button is focused
BTNST_COLOR_FG_FOCUS, // Text color when the button is focused
BTNST_MAX_COLORS
};
enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual)
BTNST_PRESSED_TOPBOTTOM // Pressed style from top to bottom
};
// Create mask for bitmap In
m_csBitmaps[0].hMask = CreateBitmapMask(
hBitmapIn,
m_csBitmaps[0].dwWidth,
m_csBitmaps[0].dwHeight,
crTransColorIn
);
if (m_csBitmaps[0].hMask == NULL)
{
FreeResources();
return BTNST_FAILEDMASK;
}
if (hBitmapOut)
{
m_csBitmaps[1].hBitmap = hBitmapOut;
m_csBitmaps[1].crTransparent = crTransColorOut;
// Get bitmap size
nRetValue = ::GetObject(hBitmapOut, sizeof(csBitmapSize), &csBitmapSize);
if (nRetValue == 0)
{
FreeResources();
return BTNST_INVALIDRESOURCE;
} // if
m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth;
m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight;
// Create mask for bitmap Out
m_csBitmaps[1].hMask = CreateBitmapMask(
hBitmapOut,
m_csBitmaps[1].dwWidth,
m_csBitmaps[1].dwHeight,
crTransColorOut
);
if (m_csBitmaps[1].hMask == NULL)
{
FreeResources();
return BTNST_FAILEDMASK;
}
}
}
Invalidate();
return BTNST_OK;
}
// This function sets all colors to a default value.
//
// Parameters:
// [IN] bRepaint
// If TRUE the control will be repainted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CButtonST::SetDefaultColors(BOOL bRepaint)
{
m_crColors[BTNST_COLOR_BK_IN] = ::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_IN] = ::GetSysColor(COLOR_BTNTEXT);
m_crColors[BTNST_COLOR_BK_OUT] = ::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_OUT] = ::GetSysColor(COLOR_BTNTEXT);
m_crColors[BTNST_COLOR_BK_FOCUS] = ::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_FOCUS] = ::GetSysColor(COLOR_BTNTEXT);
if (bRepaint) Invalidate();
return BTNST_OK;
}
// This function enables the transparent mode.
// Note: this operation is not reversible.
// DrawTransparent should be called just after the button is created.
// Do not use trasparent buttons until you really need it (you have a bitmapped
// background) since each transparent button makes a copy in memory of its background.
// This may bring unnecessary memory use and execution overload.
//
// Parameters:
// [IN] bRepaint
// If TRUE the control will be repainted.
//
void CButtonST::DrawTransparent(BOOL bRepaint)
{
m_bDrawTransparent = TRUE;
// Restore old bitmap (if any)
if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
{
m_dcBk.SelectObject(m_pbmpOldBk);
}
m_bmpBk.DeleteObject();
m_dcBk.DeleteDC();
// Repaint the button
if (bRepaint)
{
Invalidate();
}
TRACE(_T("CButtonST::DrawTransparent\n"));
}
DWORD CButtonST::SetBk(CDC* pDC)
{
if (m_bDrawTransparent && pDC)
{
// Restore old bitmap (if any)
if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
{
m_dcBk.SelectObject(m_pbmpOldBk);
}
// This function is called every time the button border needs to be painted.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
{
// Draw pressed button
if (m_bIsPressed)
{
// pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
}
else
{
if (m_bMouseOnButton && m_bDrawBorder)
{
// pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
}
}