gps/GPSProject/MediaPlayer/ThumbIcon.cpp

281 lines
6.0 KiB
C++
Raw Normal View History

2019-05-01 12:32:35 +00:00
// ThumbIcon.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "ThumbIcon.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CThumbIcon
CThumbIcon::CThumbIcon()
{
m_txtFont.CreateFont(12,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial"));
m_NormalID = 0;
m_DownID = 0;
m_ImageID = 0;
m_InitDC = false;
m_IsSelected = false;
m_Title.Empty();
m_ShowIcon = FALSE;
m_BmpSize = CSize(0,0);
m_txtColor = RGB(255,255,255);
m_IsDown = FALSE;
}
CThumbIcon::~CThumbIcon()
{
m_NormalDC.DeleteDC();
m_DownDC.DeleteDC();
m_BackgroundDC.DeleteDC();
m_txtFont.DeleteObject();
m_MemDC.DeleteDC();
}
BEGIN_MESSAGE_MAP(CThumbIcon, CButton)
//{{AFX_MSG_MAP(CThumbIcon)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_KILLFOCUS()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CThumbIcon message handlers
void CThumbIcon::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
}
void CThumbIcon::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
// <20>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ð<EFBFBD>ť<EFBFBD><C5A5>ʽΪ<CABD>Ի水ť
ModifyStyle(0, GetStyle()|BS_OWNERDRAW);
CButton::PreSubclassWindow();
}
BOOL CThumbIcon::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
if (!m_InitDC && m_ImageID)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>м<EFBFBD><D0BC><EFBFBD>ͼƬ
CDC tmpDC;
tmpDC.CreateCompatibleDC(NULL);
CBitmap tmpBmp;
tmpBmp.LoadBitmap(m_ImageID);
tmpDC.SelectObject(&tmpBmp);
tmpBmp.DeleteObject();
// <20><><EFBFBD>㰴ť<E3B0B4>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ڵ<EFBFBD>λ<EFBFBD><CEBB>
CRect rect;
GetClientRect(&rect);
// <20><>ȡ<EFBFBD><C8A1>ť<EFBFBD>Ŀ<EFBFBD><C4BF>͸<EFBFBD>
int cx = rect.Width();
int cy = rect.Height();
// <20><>/<2F>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CRect mainWnd;
CRect subWnd;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CWnd *pWnd = GetParent();
pWnd->GetWindowRect(&mainWnd);
// <20><>ȡ<EFBFBD><C8A1>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
GetWindowRect(&subWnd);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
CPoint tpLeft;
tpLeft.x = subWnd.TopLeft().x - mainWnd.TopLeft().x;
tpLeft.y = subWnd.TopLeft().y - mainWnd.TopLeft().y;
// <20><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
tmpBmp.CreateCompatibleBitmap(&tmpDC,cx,cy);
m_BackgroundDC.CreateCompatibleDC(NULL);
m_BackgroundDC.SelectObject(&tmpBmp);
m_BackgroundDC.BitBlt(0,0,cx,cy,&tmpDC,tpLeft.x,tpLeft.y,SRCCOPY);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
tmpBmp.DeleteObject();
tmpDC.DeleteDC();
tmpBmp.CreateCompatibleBitmap(pDC,cx,cy);
m_MemDC.CreateCompatibleDC(pDC);
m_MemDC.SelectObject(&tmpBmp);
m_MemDC.SelectObject(&m_txtFont);
m_MemDC.SetBkMode(TRANSPARENT);
tmpBmp.DeleteObject();
m_InitDC = true;
}
return FALSE;
//return CButton::OnEraseBkgnd(pDC);
}
void CThumbIcon::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rc;
GetClientRect(&rc);
if(m_ShowIcon)
{
if (m_NormalID && m_DownID)
{
if (!m_IsSelected)
{
m_MemDC.SetTextColor(RGB(255,255,255));
m_MemDC.BitBlt(0,0,rc.Width(),rc.Height(),&m_NormalDC,0,0,SRCCOPY);
}
else
{
m_MemDC.SetTextColor(RGB(10,0,0));
m_MemDC.BitBlt(0,0,rc.Width(),rc.Height(),&m_DownDC,0,0,SRCCOPY);
}
m_MemDC.DrawText(m_Title,&rc,DT_BOTTOM|DT_LEFT);
CDC tmpDC;
CBitmap tmpBmp;
tmpBmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
tmpDC.CreateCompatibleDC(&dc);
tmpDC.SelectObject(&tmpBmp);
tmpDC.BitBlt(0,0,rc.Width(),rc.Height(),&m_BackgroundDC,0,0,SRCCOPY);
TransparentImage(tmpDC.m_hDC,0,0,rc.Width(),rc.Height(),
m_MemDC.m_hDC,0,0,m_BmpSize.cx,m_BmpSize.cy,m_BgColor);
dc.BitBlt(0,0,rc.Width(),rc.Height(),&tmpDC,0,0,SRCCOPY);
tmpDC.DeleteDC();
tmpBmp.DeleteObject();
}
}
else
{
dc.BitBlt(0,0,rc.Width(),rc.Height(),&m_BackgroundDC,0,0,SRCCOPY);
}
// Do not call CButton::OnPaint() for painting messages
}
void CThumbIcon::LoadIcon(int nNormalID, int nDownID, int nImageID, COLORREF BgColor)
{
m_NormalID = nNormalID;
m_DownID = nDownID;
m_ImageID = nImageID;
m_BgColor = BgColor;
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
CBitmap tmpBmp;
BITMAP bmpInfo;
// <20><><EFBFBD><EFBFBD>Դ<EFBFBD>м<EFBFBD><D0BC>ر<EFBFBD><D8B1><EFBFBD>ͼƬ
tmpBmp.LoadBitmap(m_NormalID);
tmpBmp.GetBitmap(&bmpInfo);
m_BmpSize = CSize(bmpInfo.bmWidth,bmpInfo.bmHeight);
m_NormalDC.DeleteDC();
m_DownDC.DeleteDC();
m_NormalDC.CreateCompatibleDC(NULL);
m_NormalDC.SelectObject(&tmpBmp);
tmpBmp.DeleteObject();
tmpBmp.LoadBitmap(m_DownID);
m_DownDC.CreateCompatibleDC(NULL);
m_DownDC.SelectObject(&tmpBmp);
tmpBmp.DeleteObject();
}
void CThumbIcon::ShowIcon(bool bShow)
{
m_ShowIcon = bShow;
}
CString CThumbIcon::GetButtonTitle()
{
return m_Title;
}
void CThumbIcon::SetButtonTitle(CString sTitle)
{
m_Title = sTitle;
}
void CThumbIcon::SetChecked(bool bCheck)
{
m_IsSelected = bCheck;
Invalidate();
}
bool CThumbIcon::GetChecked()
{
return m_IsDown;
}
void CThumbIcon::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_IsSelected = !m_IsSelected;
if (m_IsSelected)
{
m_IsDown = true;
}
else
{
m_IsDown = false;
}
Invalidate();
CButton::OnLButtonDown(nFlags, point);
}
void CThumbIcon::OnKillFocus(CWnd* pNewWnd)
{
CButton::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
m_IsSelected = FALSE;
}
void CThumbIcon::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd* pWnd = GetParent();
COPYDATASTRUCT cpd;
cpd.dwData = 0;
cpd.cbData = sizeof(m_Title);
cpd.lpData = (void*)&m_Title;
pWnd->SendMessage(WM_COPYDATA,NULL,(LPARAM)&cpd);
CButton::OnLButtonDblClk(nFlags, point);
}