15,979
社区成员
发帖
与我相关
我的任务
分享
void CBtnPng::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* if(m_bOver == FALSE)
{
m_bOver = TRUE;
InvalidateRect(NULL,FALSE);
}*/
TRACKMOUSEEVENT t_MouseEvent;
t_MouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
t_MouseEvent.dwFlags = TME_LEAVE | TME_HOVER;
t_MouseEvent.hwndTrack = m_hWnd;
t_MouseEvent.dwHoverTime = 1;
::_TrackMouseEvent(&t_MouseEvent);
if(m_bSend_MouseMove_Flag)
{
////////////////////移动控件 2017-07-04 /////////
CRect rc;
GetWindowRect(&rc); //获取控件尺寸
((CDelayCtrlDlg*)GetParent())->ScreenToClient(&rc); //转化为对话框坐标
CRect rcClient;
BOOL bActive = TRUE;
if (GetDlgCtrlID() == IDC_B_DELAY_FOCUS1) //指定控件
{
if (nFlags==1) //鼠标按下
{
rcClient = ((CDelayCtrlDlg*)GetParent())->GetFrontActiveArea(); //对话框设置的区域
if (bActive)
{
m_nLastMoveRect = rc;
ReleaseCapture();
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0); //鼠标拖动控件部分
}
}
}
/////////////////////////////////////////////////////
if(m_nMovePoint != point)
{
m_nMovePoint = point;
(GetParent())->SendMessage(WM_VOLUME_MOUSEMOVE,nFlags,GetDlgCtrlID());
}
}
else
{
CButton::OnMouseMove(nFlags, point);
}
}
void CBtnPng::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* if(m_bOver == FALSE)
{
m_bOver = TRUE;
InvalidateRect(NULL,FALSE);
}*/
TRACKMOUSEEVENT t_MouseEvent;
t_MouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
t_MouseEvent.dwFlags = TME_LEAVE | TME_HOVER;
t_MouseEvent.hwndTrack = m_hWnd;
t_MouseEvent.dwHoverTime = 1;
::_TrackMouseEvent(&t_MouseEvent);
// ClientToScreen(&point);
// ((CDelayCtrlDlg*)GetParent())->ScreenToClient(&point);
// ClientToScreen(&m_nMovePoint);
// ((CDelayCtrlDlg*)GetParent())->ScreenToClient(&m_nMovePoint);
if(m_bSend_MouseMove_Flag)
{
////////////////////移动控件 2017-07-04 /////////
CRect rc;
GetWindowRect(&rc); //获取控件尺寸
((CDelayCtrlDlg*)GetParent())->ScreenToClient(&rc); //转化为对话框坐标
int nWidth = rc.right - rc.left;
int nHight = rc.bottom - rc.top;
CRect rcClient;
BOOL bActive = TRUE;
if (GetDlgCtrlID() == IDC_B_DELAY_FOCUS1) //指定控件
{
if (nFlags==1) //鼠标按下
{
rcClient = ((CDelayCtrlDlg*)GetParent())->GetFrontActiveArea(); //对话框设置的区域
CPoint ptTemp = point - m_nMovePoint;
rc.OffsetRect(ptTemp.x, ptTemp.y);
if (rc.left < rcClient.left)
{
rc.left = rcClient.left;
rc.right = rc.left+nWidth;
}
if (rc.top < rcClient.top)
{
rc.top = rcClient.top;
rc.bottom = rc.top + nHight;
}
if (rc.right > rcClient.right)
{
rc.right = rcClient.right;
rc.left = rc.right - nWidth;
}
if (rc.bottom > rcClient.bottom)
{
rc.bottom = rcClient.bottom;
rc.top = rc.bottom - nHight;
}
MoveWindow(&rc);
return;
//计算偏移量
// if (point.x < rcClient.left)
// {
// bActive = FALSE;
// rc.left = rcClient.left;
// }
// int shift_x = point.x-m_nMovePoint.x;
// int shift_y = point.y-m_nMovePoint.y;
// rc.left += shift_x;
// rc.top += shift_y;
// rc.right += shift_x;
// rc.bottom += shift_y;
// //判断有没有超出范围
// if (rc.left < rcClient.left)
// {
// bActive = FALSE;
// rc.left = rcClient.left;
// }
// if (rc.top < rcClient.top)
// {
// bActive = FALSE;
// rc.top = rcClient.top;
// }
// if (rc.right > rcClient.right)
// {
// bActive = FALSE;
// rc.left = rcClient.right - nWidth;
// }
// if (rc.bottom > rcClient.bottom)
// {
// bActive = FALSE;
// rc.top = rcClient.bottom - nHight;
// }
// ((CDelayCtrlDlg*)GetParent())->m_png_Front_DelayFocus.MoveWindow(rc.left,rc.top,nWidth,nHight);
// ((CDelayCtrlDlg*)GetParent())->InvalidateRect(&rcClient);
// if (bActive)
// {
// m_nLastMoveRect = rc;
// ReleaseCapture();
// SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0); //鼠标拖动控件部分
// rc.right = rc.left+nWidth;
// rc.bottom = rc.top+nHight;
// ((CDelayCtrlDlg*)GetParent())->PostMessage(WM_CTRL_MOVE,(WPARAM)&rc,GetDlgCtrlID());
// }
// else
// {
// SendMessage(WM_LBUTTONDOWN, HTCAPTION, 0); //鼠标拖动控件部分
// rc.right = rc.left+nWidth;
// rc.bottom = rc.top+nHight;
// ((CDelayCtrlDlg*)GetParent())->PostMessage(WM_CTRL_MOVE,(WPARAM)&rc,GetDlgCtrlID());
// //((CDelayCtrlDlg*)GetParent())->m_png_Front_DelayFocus.MoveWindow(rc.left,rc.top,nWidth,nHight);
// //((CDelayCtrlDlg*)GetParent())->m_png_Front_DelayFocus.SetWindowPos(&CWnd::wndTop,rc.left,rc.top,nWidth,nHight,SWP_SHOWWINDOW);
// }
// //((CDelayCtrlDlg*)GetParent())->Invalidate(&rcClient);
}
}
// ClientToScreen(&point);
// ClientToScreen(&m_nMovePoint);
// ScreenToClient(&point);
// ScreenToClient(&m_nMovePoint);
/////////////////////////////////////////////////////
if(m_nMovePoint != point)
{
m_nMovePoint = point;
(GetParent())->SendMessage(WM_VOLUME_MOUSEMOVE,nFlags,GetDlgCtrlID());
}
}
else
{
CButton::OnMouseMove(nFlags, point);
}
}
问题解决了,谢谢各位。void CBtnPng::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/* if(m_bOver == FALSE)
{
m_bOver = TRUE;
InvalidateRect(NULL,FALSE);
}*/
TRACKMOUSEEVENT t_MouseEvent;
t_MouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
t_MouseEvent.dwFlags = TME_LEAVE | TME_HOVER;
t_MouseEvent.hwndTrack = m_hWnd;
t_MouseEvent.dwHoverTime = 1;
::_TrackMouseEvent(&t_MouseEvent);
if(m_bSend_MouseMove_Flag)
{
////////////////////移动控件 2017-07-04 /////////
CRect rc;
GetWindowRect(&rc); //获取控件尺寸
((CDelayCtrlDlg*)GetParent())->ScreenToClient(&rc); //转化为对话框坐标
int nWidth = rc.right - rc.left;
int nHight = rc.bottom - rc.top;
CRect rcClient;
BOOL bActive = TRUE;
if (GetDlgCtrlID() == IDC_B_DELAY_FOCUS1) //指定控件
{
if (nFlags==1) //鼠标按下
{
rcClient = ((CDelayCtrlDlg*)GetParent())->GetFrontActiveArea(); //对话框设置的区域
//计算偏移量
int shift_x = point.x-m_nMovePoint.x;
int shift_y = point.y-m_nMovePoint.y;
rc.left += shift_x;
rc.top += shift_y;
rc.right += shift_x;
rc.bottom += shift_y;
//判断有没有超出范围
if (rc.left < rcClient.left)
{
bActive = FALSE;
rc.left = rcClient.left;
}
if (rc.top < rcClient.top)
{
bActive = FALSE;
rc.top = rcClient.top;
}
if (rc.right > rcClient.right)
{
bActive = FALSE;
rc.left = rcClient.right - nWidth;
}
if (rc.bottom > rcClient.bottom)
{
bActive = FALSE;
rc.top = rcClient.bottom - nHight;
}
ClientToScreen(&rcClient);
ClipCursor(&rcClient);
// ((CDelayCtrlDlg*)GetParent())->m_png_Front_DelayFocus.MoveWindow(rc.left,rc.top,nWidth,nHight);
// CButton::OnMouseMove(nFlags, point);
//Invalidate();
if (bActive)
{
m_nLastMoveRect = rc;
ReleaseCapture();
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0); //鼠标拖动控件部分
}
ClipCursor(NULL);
}
}
/////////////////////////////////////////////////////
if(m_nMovePoint != point)
{
m_nMovePoint = point;
(GetParent())->SendMessage(WM_VOLUME_MOUSEMOVE,nFlags,GetDlgCtrlID());
}
}
else
{
CButton::OnMouseMove(nFlags, point);
}
}