CxSkinButton.h中增加两个宏定义
#define WM_MYLBTN_UP WM_USER + 0x1001
#define WM_MYLBTN_DOWM WM_USER + 0x1002
CxSkinButton.cpp中修改
void CxSkinButton::OnLButtonDown(UINT nFlags, CPoint point)
{
//Pass this message to the ToolTip control
RelayEvent(WM_LBUTTONDOWN,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
//If we are tracking this button, cancel it
if (m_tracking) {
TRACKMOUSEEVENT t = {
sizeof(TRACKMOUSEEVENT),
TME_CANCEL | TME_LEAVE,
m_hWnd,
0
};
if (::_TrackMouseEvent(&t)) {
m_tracking = false;
}
}
//Default-process the message
CButton::OnLButtonDown(nFlags, point);
GetParent()->SendMessage(WM_MYLBTN_DOWM, GetDlgCtrlID(), 0); //增加这行
m_button_down = true;
}
void CxSkinButton::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_Style)
{
//track mouse for radio & check buttons
POINT p2 = point;
::ClientToScreen(m_hWnd, &p2);
HWND mouse_wnd = ::WindowFromPoint(p2);
if (mouse_wnd == m_hWnd)
{
// mouse is in button
if (m_Style==BS_CHECKBOX) SetCheck(m_Checked ? 0 : 1);
if (m_Style==BS_RADIOBUTTON) SetCheck(1);
}
}
//Pass this message to the ToolTip control
RelayEvent(WM_LBUTTONUP,(WPARAM)nFlags,MAKELPARAM(LOWORD(point.x),LOWORD(point.y)));
//Default-process the message
m_button_down = false;
CButton::OnLButtonUp(nFlags, point);
GetParent()->SendMessage(WM_MYLBTN_UP, GetDlgCtrlID(), 0); //增加这行
}
使用方法 窗口头文件中引用
#include "xSkinButton.h"
定义变量:
CxSkinButton m_btnCenter;
窗口cpp文件中
控件与变量关联
void CHGVideoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CENTER, m_btnCenter);
}
//事件关联
BEGIN_MESSAGE_MAP(CHGVideoDlg, CDialog)
ON_MESSAGE(WM_MYLBTN_DOWM, OnLBtnDownPtzCtrl)//OnLBtnDownPtzCtrl中实现鼠标按下
ON_MESSAGE(WM_MYLBTN_UP, OnLBtnUpPtzCtrl)//鼠标抬起事件
END_MESSAGE_MAP()
//注:按钮添加图片
BOOL CHGVideoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);// 设置大图标
SetIcon(m_hIcon, FALSE);// 设置小图标
m_btnCenter.SetTextColor(RGB(255,0,0));
m_btnCenter.SetSkin(IDB_CENTER, IDB_CENTER, IDB_CENTER, IDB_CENTER, 0, IDB_CENTER, 0, 0, 0);
}
效果图:
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)