📄 advbutton.cpp
字号:
// AdvButton.cpp : implementation file
//
#include "stdafx.h"
#include "MyQQClient.h"
#include "AdvButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAXCAPTIONLEN 64
/////////////////////////////////////////////////////////////////////////////
// CAdvButton
CAdvButton::CAdvButton()
{
//initialize member variable
m_ClientRect.left = 0;
m_ClientRect.top = 0;
m_ClientRect.right = 0;
m_ClientRect.bottom= 0;
m_ClientRgn.DeleteObject();
m_ClientRgn.CreateEllipticRgnIndirect(&m_ClientRect);
m_State = 0;
m_Point.x = m_Point.y = 0;
m_IsTimerOn = FALSE;
m_BtnType = 0;
m_iPicture = 0;
}
CAdvButton::~CAdvButton()
{
}
BEGIN_MESSAGE_MAP(CAdvButton, CButton)
//{{AFX_MSG_MAP(CAdvButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdvButton message handlers
BOOL CAdvButton::Create(LPCTSTR lpszCaption,DWORD dwStyle,const RECT& rect,CWnd *pParentWnd,UINT nID)
{
return CButton::Create(lpszCaption, dwStyle, rect, pParentWnd, nID);
}
void CAdvButton::PreSubclassWindow()
{
//modify style
ModifyStyle(0, BS_OWNERDRAW|BS_PUSHBUTTON);
CButton::PreSubclassWindow();
}
int CAdvButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CButton::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CAdvButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
//get client rect
GetClientRect(&m_ClientRect);
// m_ClientRgn.DeleteObject();
// m_ClientRgn.CreateEllipticRgnIndirect(&m_ClientRect);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if ( m_BtnType == 0) {
switch (m_State)
{
case 0:
pDC->FillRect(&m_ClientRect,new CBrush(RGB(225,225,255)));
break;
case 1:
pDC->FillRect(&m_ClientRect,new CBrush(RGB(192,192,255)));
break;
case 2:
pDC->FillRect(&m_ClientRect,new CBrush(RGB(225,225,255)));
break;
case 3:
pDC->FillRect(&m_ClientRect,new CBrush(RGB(128,128,255)));
break;
}
LPTSTR pCaption = new char[MAXCAPTIONLEN]; //
int iLen = GetWindowText(pCaption,MAXCAPTIONLEN);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(TextColor);
pDC->DrawText(pCaption,iLen,&m_ClientRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
else if ( m_BtnType == 1 ) {
pDC->FillRect(&m_ClientRect,new CBrush(RGB(192,192,255)));
LPTSTR pCaption = new char[MAXCAPTIONLEN]; //
int iLen = GetWindowText(pCaption,MAXCAPTIONLEN);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(TextColor);
pDC->DrawText(pCaption,iLen,&m_ClientRect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
else if ( m_BtnType == 2 ) {
CDC dcMemory;
CBitmap* pOldBmp = new CBitmap;
pOldBmp->LoadBitmap(m_iPicture+IDB_BITMAP1);
dcMemory.CreateCompatibleDC(pDC);
pOldBmp = dcMemory.SelectObject(pOldBmp);
// pDC->BitBlt(m_ClientRect.left, m_ClientRect.top,
// 32, 32, &dcMemory, 0, 0, SRCCOPY);
pDC->StretchBlt(m_ClientRect.left,m_ClientRect.top,
m_ClientRect.Width(),m_ClientRect.Height(),
&dcMemory,0,0,32,32,SRCCOPY);
dcMemory.SelectObject(pOldBmp);
}
}
void CAdvButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
GetCursorPos(&m_Point);
if((rect.PtInRect(m_Point))&&(m_State != 2))
{
m_State = 2; //2:select state
Invalidate();
}
CButton::OnLButtonDown(nFlags, point);
}
void CAdvButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
GetCursorPos(&m_Point);
if((rect.PtInRect(m_Point))&&(m_State != 1))
{
m_State = 1; //1:focus state
Invalidate();
}
CButton::OnLButtonUp(nFlags, point);
}
void CAdvButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!m_IsTimerOn)
{
SetTimer(1000,100,NULL);
m_IsTimerOn = TRUE;
}
CButton::OnMouseMove(nFlags, point);
}
void CAdvButton::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetWindowRect(&rect);
GetCursorPos(&m_Point);
if(rect.PtInRect(m_Point))
{
if((m_State != 1)&&(m_State != 2)) //
{
m_State = 1;
Invalidate();
}
}
else
{
if(m_State != 0)
{
m_State = 0;
Invalidate();
}
KillTimer(nIDEvent);
m_IsTimerOn = FALSE;
}
CButton::OnTimer(nIDEvent);
}
void CAdvButton::SetType(UINT piType)
{
m_BtnType = piType;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -