gps/GPSResources/tcpmp/MusicPlayer/BmpButton.cpp

135 lines
2.6 KiB
C++
Executable File

// BmpButton.cpp : 实现文件
//
#include "stdafx.h"
#include "MusicPlayer.h"
#include "BmpButton.h"
// CBmpButton
IMPLEMENT_DYNAMIC(CBmpButton, CButton)
CBmpButton::CBmpButton()
{
m_InitDC = FALSE;
m_NormalDC.CreateCompatibleDC(NULL);
m_DisableDC.CreateCompatibleDC(NULL);
m_DownDC.CreateCompatibleDC(NULL);
m_ButType = BT_NORMAL;
}
CBmpButton::~CBmpButton()
{
m_DisableDC.DeleteDC();
m_DownDC.DeleteDC();
m_NormalDC.DeleteDC();
}
BEGIN_MESSAGE_MAP(CBmpButton, CButton)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
// CBmpButton 消息处理程序
void CBmpButton::LoadBitmaps(UINT nIDBitmapResource, UINT nIDBitmapResourceSel, UINT nIDBitmapResourceDisabled)
{
CBitmap bmp;
bmp.LoadBitmap(nIDBitmapResource);
m_NormalDC.SelectObject(&bmp);
bmp.DeleteObject();
if (nIDBitmapResourceSel != 0)
{
bmp.LoadBitmap(nIDBitmapResourceSel);
m_DownDC.SelectObject(&bmp);
bmp.DeleteObject();
m_ButType |= BT_DOWN;
}
if (nIDBitmapResourceDisabled != 0)
{
bmp.LoadBitmap(nIDBitmapResourceDisabled);
m_DisableDC.SelectObject(&bmp);
bmp.DeleteObject();
m_ButType |= BT_DISABLE;
}
m_InitDC = TRUE;
}
void CBmpButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 添加您的代码以绘制指定项
CRect rect;
GetClientRect(&rect);
UINT status = lpDrawItemStruct->itemState;
CClientDC dc(this);
m_Status = BTS_NORMAL;
dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_NormalDC,0,0,SRCCOPY);
if (status & ODS_DISABLED)
{
dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_DisableDC,0,0,SRCCOPY);
m_Status = BTS_DISABLE;
}
else if (status & ODS_SELECTED)
{
m_Status = BTS_DOWN;
dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_DownDC,0,0,SRCCOPY);
}
}
void CBmpButton::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CButton::OnPaint()
if (m_InitDC)
{
CRect rect;
GetClientRect(&rect);
if (IsWindowEnabled())
{
dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_NormalDC,0,0,SRCCOPY);
}
else
{
dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_DisableDC,0,0,SRCCOPY);
}
}
}
BOOL CBmpButton::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return FALSE;
// return CButton::OnEraseBkgnd(pDC);
}
void CBmpButton::PreSubclassWindow()
{
// TODO: 在此添加专用代码和/或调用基类
// 在此设置按钮样式为自绘按钮
ModifyStyle(0, GetStyle()|BS_OWNERDRAW);
CButton::PreSubclassWindow();
}
void CBmpButton::SetButType(int nType)
{
m_ButType |= nType;
}