在VC中透明浮动按键的实现
2008-11-13 19:34:27 来源:WEB开发网void CDrawButton::OnMouseMove
(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code
here and/or call default
CRect rect;
GetClientRect(&rect);
if(rect.PtInRect(point)){
if (mBtnStats==BTN_NORMAL){
SetButtonMode(ODA_SELECT, ODS_FOCUS);
SetCapture();
}
}
else{
//AutoLoad(GetDlgCtrlID(),GetParent());
SetButtonMode(ODA_DRAWENTIRE,ODS_DEFAULT);
ReleaseCapture();
}
CButton::OnMouseMove(nFlags, point);
}
这里,mBtnStats是个UINT类型的成员变量,它可以有三种自定义状态:
BTN_NORMAL 正常状态
BTN_UP 鼠标移入按键区域或释放鼠标
BTN_DOWN 按下鼠标
(可以再加一种DISABLE状态)
当在按键区域释放鼠标时,必须发送WM_COMMAND消息:
void CDrawButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code
here and/or call default
CRect rect;
GetClientRect(&rect);
if(rect.PtInRect(point)){
if (mBtnStats==BTN_DOWN)
GetParent()- >SendMessage(WM_COMMAND,
MAKELPARAM(GetDlgCtrlID(),BN_CLICKED),
(LPARAM)GetSafeHwnd());
SetCapture();
}
else{
SetButtonMode(ODA_DRAWENTIRE,ODS_DEFAULT);
ReleaseCapture();
}
CButton::OnLButtonUp(nFlags, point);
}
更多精彩
赞助商链接