// HoverButton.cpp : implementation file
//
#include "stdafx.h"
#include "hovbutt.h"
#include "HoverButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHoverButton
BEGIN_MESSAGE_MAP(CHoverButton, CBitmapButton)
//{{AFX_MSG_MAP(CHoverButton)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHoverButton construction / destruction
CHoverButton::CHoverButton()
{
// To start with, the button is switched off and we are NOT tracking the mouse
m_ButtonState = BUTTON_OFF;
m_bMouseTracking = FALSE;
}
CHoverButton::~CHoverButton()
{
}
/////////////////////////////////////////////////////////////////////////////
// CHoverButton message handlers
void CHoverButton::OnMouseMove(UINT nFlags, CPoint point)
{
CBitmapButton::OnMouseMove(nFlags, point);
// 1. Mouse has moved and we are not tracking this button, or
// 2. mouse has moved and the cursor was not above this window
// == Is equivalent to WM_MOUSEENTER (for which there is no message)
if((!m_bMouseTracking || GetCapture()!=this) && (m_ButtonState == BUTTON_OFF))
{
OnMouseEnter();
}
else
{
if(m_ButtonState == BUTTON_OVER)
{
CRect rc;
GetClientRect(&rc);
if(!rc.PtInRect(point)) // The mouse cursor is no longer above this button
OnMouseLeave();
}
}
}
void CHoverButton::OnMouseEnter(void)
{
// We are now tracking the mouse, OVER this button
m_bMouseTracking = TRUE;
m_ButtonState = BUTTON_OVER;
// Ensure that mouse input is sent to the button
SetCapture();
Invalidate();
UpdateWindow();
}
void CHoverButton::OnMouseLeave(void)
{
// We are not tracking the mouse, this button is OFF.
m_ButtonState = BUTTON_OFF;
m_bMouseTracking = FALSE;
// Release mouse capture from the button and restore normal mouse input
Invalidate();
UpdateWindow();
ReleaseCapture();
}
void CHoverButton::OnLButtonUp(UINT nFlags, CPoint point)
{
SetButtonState(BUTTON_ON); // Highlight button
CBitmapButton::OnLButtonUp(nFlags, point);
}
// Purpose: Set the new state of the button
// Return: Returns the old state of the button
// Parameters: nState = Either ON or OFF. The default is OFF. This is NOT tri-state button!
BUTTON_STATE CHoverButton::SetButtonState(BUTTON_STATE nState)
{
BUTTON_STATE nOldState = (BUTTON_STATE)GetCheck();
m_ButtonState = nState;
switch(m_ButtonState)
{
case BUTTON_ON:
EnableWindow(TRUE);
SetState(BUTTON_ON);
break;
case BUTTON_GREYED:
EnableWindow(FALSE);
break;
case BUTTON_OVER:
EnableWindow(TRUE);
SetState(BUTTON_OVER);
break;
default:
EnableWindow(TRUE);
SetState(BUTTON_OFF);
m_ButtonState = BUTTON_OFF;
break;
}
return(nOldState);
}
// Draws the buttons in their relevant state, and text labels
void CHoverButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC memDC;
CBitmap* pOld=NULL;
CBitmap* pBitmap=NULL;
CDC* pDC;
CRect rc;
int iSaveDC;
pDC= CDC::FromHandle(lpDrawItemStruct->hDC);
memDC.CreateCompatibleDC(pDC);
VERIFY(pDC);
iSaveDC=pDC->SaveDC();
rc.CopyRect(&lpDrawItemStruct->rcItem);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(GetSysColor(COLOR_WINDOWFRAME));// Black text color
switch(m_ButtonState)
{
case BUTTON_ON:
pBitmap=&m_bmpButtonDown;
break;
case BUTTON_OVER:
pBitmap=&m_bmpButtonFocussed;
break;
case BUTTON_GREYED:
pBitmap=&m_bmpButtonDisabled;
break;
default:
pBitmap=&m_bmpButtonUp;
break;
}
CString strTitle;
GetWindowText(strTitle);
if (pBitmap->m_hObject)
{
CRect rcBitmap(rc);
BITMAP bmpInfo;
CSize size;
// Text
size = pDC->GetTextExtent(strTitle);
rcBitmap.OffsetRect(size.cx+5,0);
// Draw bitmap
if(!pBitmap->GetBitmap(&bmpInfo))
return;
pOld=memDC.SelectObject((CBitmap*) pBitmap);
if (pOld==NULL)
return; //Destructors will clean up
if(!pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &memDC, 0, 0, SRCCOPY))
return;
memDC.SelectObject(pOld);
if(memDC==NULL)
return;
}
CRect rcText(rc);
UINT nFormat = DT_CENTER;
if(m_ButtonState == BUTTON_GREYED)
{
rcText.OffsetRect(1,1);
pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT));
pDC->DrawText(strTitle,rcText,nFormat);
rcText.OffsetRect(-1,-1);
pDC->SetTextColor(GetSysColor(COLOR_BTNSHADOW));
pDC->DrawText(strTitle,rcText,nFormat);
}
else
pDC->DrawText(strTitle,rcText,nFormat);
pDC->RestoreDC(iSaveDC);
}
BOOL CHoverButton::LoadBitmaps(UINT nBitmapUp, UINT nBitmapDown,
UINT nBitmapFocus, UINT nBitmapDisabled)
{
return LoadBitmaps(MAKEINTRESOURCE(nBitmapUp),
MAKEINTRESOURCE(nBitmapDown),
MAKEINTRESOURCE(nBitmapFocus),
MAKEINTRESOURCE(nBitmapDisabled));
}
BOOL CHoverButton::LoadBitmaps(LPCSTR lpszBitmapUp, LPCSTR lpszBitmapDown,
LPCSTR lpszBitmapFocus, LPCSTR lpszBitmapDisabled)
{
BOOL bAllLoaded=TRUE;
//Delete old ones
m_bmpButtonDown.DeleteObject();
m_bmpButtonFocussed.DeleteObject();
m_bmpButtonUp.DeleteObject();
m_bmpButtonDisabled.DeleteObject();
if (!m_bmpButtonUp.LoadBitmap(lpszBitmapUp))
{
TRACE0("Failed to load up bitmap of bitmap button\n");
return FALSE;
}
if (lpszBitmapDown!=NULL)
{
if (!m_bmpButtonDown.LoadBitmap(lpszBitmapDown))
{
TRACE0("Failed to load down bitmap of bitmap button\n");
return bAllLoaded=FALSE;
}
}
if (lpszBitmapFocus!=NULL)
{
if (!m_bmpButtonFocussed.LoadBitmap(lpszBitmapFocus))
{
TRACE0("Failed to load focussed bitmap of bitmap button\n");
return bAllLoaded=FALSE;
}
}
if (lpszBitmapDisabled!=NULL)
{
if (!m_bitmapDisabled.LoadBitmap(lpszBitmapDisabled))
{
TRACE0("Failed to load disabled bitmap of bitmap button\n");
return bAllLoaded=FALSE;
}
}
return bAllLoaded;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
bottonColor.zip (34个子文件)
变色按钮
coding
hovbutt
hovbutt.h 1KB
hovbuttDlg.h 1KB
HoverButton.h 2KB
HoverButton.cpp 6KB
hovbutt.cpp 2KB
StdAfx.cpp 205B
resource.h 911B
hovbutt.001 5KB
hovbuttDlg.cpp 3KB
hovbutt.ncb 41KB
Debug
hovbutt.res 9KB
vc60.pdb 116KB
hovbutt.pdb 257KB
hovbuttDlg.obj 17KB
vc60.idb 145KB
HoverButton.obj 25KB
hovbutt.obj 13KB
hovbutt.ilk 206KB
hovbutt.exe 112KB
StdAfx.obj 52KB
hovbutt.rc 5KB
StdAfx.h 928B
hovbutt.opt 48KB
Release
hovbutt.exe 25KB
res
rbs.bmp 1KB
rbu.bmp 1KB
rbo.bmp 1KB
rbx1.bmp 1KB
rbx.bmp 230B
hovbutt.rc2 399B
hovbutt.ico 3KB
hovbutt.plg 2KB
hovbutt.dsw 739B
hovbutt.dsp 5KB
共 34 条
- 1
maweiqi
- 粉丝: 29
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0