封装按钮
2015-04-28 15:58
141 查看
// SkinButton.cpp : 实现文件
//
#include "stdafx.h"
#include "project.h"
#include "SkinButton.h"
// SkinButton
IMPLEMENT_DYNAMIC(SkinButton, CButton)
SkinButton::SkinButton()
{
m_bMouseLeave = FALSE;
m_BitmapNormal = NULL;
m_BitmapHot = NULL;
m_BitmapPress = NULL;
m_BitmapDisnable = NULL;
}
SkinButton::~SkinButton()
{
}
BEGIN_MESSAGE_MAP(SkinButton, CButton)
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// SkinButton 消息处理程序
LRESULT SkinButton::OnMouseLeave(WPARAM Wparam, LPARAM Lparam)
{
Invalidate();
m_bMouseLeave = FALSE;
return 0;
}
LRESULT SkinButton::OnMouseHover(WPARAM Wparam, LPARAM Lparam)
{
Invalidate();
m_bMouseLeave = TRUE;
return 0;
}
void SkinButton::LoadBitmaps(HBITMAP hLeave, HBITMAP hHonver, HBITMAP hClick, HBITMAP hDisable)
{
m_BitmapNormal = hLeave;
m_BitmapHot = hHonver;
m_BitmapPress = hClick;
m_BitmapDisnable = hDisable;
}
void SkinButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 添加您的代码以绘制指定项
if ( GetStyle() == WS_VISIBLE )
{
return ;
}
HBITMAP bitmap;
if (lpDrawItemStruct->itemState == ODS_DISABLED)
{
bitmap = m_BitmapDisnable;
}
else if( lpDrawItemStruct->itemState == ODS_SELECTED)
{
bitmap = m_BitmapPress;
}
else
{
if (!m_bMouseLeave)
{
bitmap = m_BitmapNormal;
}
else
{
bitmap = m_BitmapHot;
}
}
HDC dc = CreateCompatibleDC(lpDrawItemStruct->hDC);
HBITMAP OldBitmap = (HBITMAP)SelectObject(dc, bitmap);
RECT rect = lpDrawItemStruct->rcItem;
//BitBlt(lpDrawItemStruct->hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dc, 0, 0, SRCCOPY);
BITMAP bmp;
::GetObject(bitmap, sizeof(BITMAP), &bmp);
SetStretchBltMode(lpDrawItemStruct->hDC,COLORONCOLOR/*HALFTONE*/);
StretchBlt(lpDrawItemStruct->hDC,rect.left, rect.top,rect.right-rect.left,rect.bottom-rect.top, dc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
CString text;
GetWindowText(text);
SetBkMode(lpDrawItemStruct->hDC, TRANSPARENT);
DrawText(lpDrawItemStruct->hDC, text, text.GetLength(), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
SelectObject(dc, OldBitmap);
DeleteDC(dc);
}
void SkinButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!m_bMouseLeave)
{
Invalidate();
TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, 0};
m_bMouseLeave = TrackMouseEvent(&tme);
}
CButton::OnMouseMove(nFlags, point);
}
//
#include "stdafx.h"
#include "project.h"
#include "SkinButton.h"
// SkinButton
IMPLEMENT_DYNAMIC(SkinButton, CButton)
SkinButton::SkinButton()
{
m_bMouseLeave = FALSE;
m_BitmapNormal = NULL;
m_BitmapHot = NULL;
m_BitmapPress = NULL;
m_BitmapDisnable = NULL;
}
SkinButton::~SkinButton()
{
}
BEGIN_MESSAGE_MAP(SkinButton, CButton)
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// SkinButton 消息处理程序
LRESULT SkinButton::OnMouseLeave(WPARAM Wparam, LPARAM Lparam)
{
Invalidate();
m_bMouseLeave = FALSE;
return 0;
}
LRESULT SkinButton::OnMouseHover(WPARAM Wparam, LPARAM Lparam)
{
Invalidate();
m_bMouseLeave = TRUE;
return 0;
}
void SkinButton::LoadBitmaps(HBITMAP hLeave, HBITMAP hHonver, HBITMAP hClick, HBITMAP hDisable)
{
m_BitmapNormal = hLeave;
m_BitmapHot = hHonver;
m_BitmapPress = hClick;
m_BitmapDisnable = hDisable;
}
void SkinButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 添加您的代码以绘制指定项
if ( GetStyle() == WS_VISIBLE )
{
return ;
}
HBITMAP bitmap;
if (lpDrawItemStruct->itemState == ODS_DISABLED)
{
bitmap = m_BitmapDisnable;
}
else if( lpDrawItemStruct->itemState == ODS_SELECTED)
{
bitmap = m_BitmapPress;
}
else
{
if (!m_bMouseLeave)
{
bitmap = m_BitmapNormal;
}
else
{
bitmap = m_BitmapHot;
}
}
HDC dc = CreateCompatibleDC(lpDrawItemStruct->hDC);
HBITMAP OldBitmap = (HBITMAP)SelectObject(dc, bitmap);
RECT rect = lpDrawItemStruct->rcItem;
//BitBlt(lpDrawItemStruct->hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, dc, 0, 0, SRCCOPY);
BITMAP bmp;
::GetObject(bitmap, sizeof(BITMAP), &bmp);
SetStretchBltMode(lpDrawItemStruct->hDC,COLORONCOLOR/*HALFTONE*/);
StretchBlt(lpDrawItemStruct->hDC,rect.left, rect.top,rect.right-rect.left,rect.bottom-rect.top, dc,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
CString text;
GetWindowText(text);
SetBkMode(lpDrawItemStruct->hDC, TRANSPARENT);
DrawText(lpDrawItemStruct->hDC, text, text.GetLength(), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
SelectObject(dc, OldBitmap);
DeleteDC(dc);
}
void SkinButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!m_bMouseLeave)
{
Invalidate();
TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, 0};
m_bMouseLeave = TrackMouseEvent(&tme);
}
CButton::OnMouseMove(nFlags, point);
}
相关文章推荐
- 项目中封装了一个弹出框但是点击上面的按钮就崩溃,尽在iOS9.0以下版本出现
- 项目中封装了一个弹出框但是点击上面的按钮就崩溃,尽在iOS9.0以下版本出现
- iOS开发 - 封装一个自己的按钮
- 短信发送倒计时按钮封装,退出再进入可继续倒计时,绝对时间倒计时
- 封装按钮
- 对安卓获取验证码倒计时60秒Button按钮的简单封装
- VC 封装按钮
- iOS (UIButton封装)仿糯米首页缩放“按钮”效果
- 参考了一些获取验证码的方式,再次封装一下获取验证码按钮,以及手机号码的正则处理
- iOS按钮封装
- easyui treegrid 封装(不用分页,用加载更多按钮)延迟加载加加载更多
- 跨浏览器按钮兼容+封装浏览器的按键
- WPF控件库:文字按钮的封装
- ios-新浪微博开发-22-封装标题按钮
- cocos2dx 自定义按钮封装(支持CCMenu批量管理),很久以前的代码
- 点击按钮控制div前后运动——函数封装1
- 简单封装一个组件:购买数量,带减少增加按钮AmountView
- PB数据窗口中按钮的封装
- 稻草人的程序之路--自绘按钮的类封装
- 点击按钮控制div上下运动——函数封装2