15,979
社区成员
发帖
与我相关
我的任务
分享
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
void CChildView::OnLButtonDown( UINT nFlags, CPoint point )
{
GetParent()->SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
void CChildView::OnRButtonDown( UINT nFlags, CPoint point )
{
GetParent()->SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
BOOL CChildView::PreTranslateMessage( MSG* pMsg )
{
if(pMsg->message == WM_RBUTTONDOWN)
{
pMsg->message = WM_LBUTTONDOWN;
pMsg->wParam = MK_LBUTTON;
}
if(pMsg->message == WM_MOUSEMOVE)
{
if(pMsg->wParam & MK_RBUTTON)
{
pMsg->wParam &= ~MK_RBUTTON;
pMsg->wParam |= MK_LBUTTON;
}
}
return 0;
}
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rcParent;
CWnd *pParent=GetParent();
pParent->GetClientRect(&rcParent);
//afxDump << rcParent << "\n";
if(m_Tracking)
{
if(MK_LBUTTON==nFlags)
{
if(Track(this,point))
{
MapWindowPoints(pParent,&m_rect);
//afxDump << m_rect << "\n";
if( (m_rect.left >= 0) &&
(m_rect.top >= 0) &&
(m_rect.right <= rcParent.right) &&
(m_rect.bottom <= rcParent.bottom))
{// limit moving in the parent
MoveWindow(&m_rect);// the button
}
CRect rc;
GetWindowRect(&rc);
rc.OffsetRect(-rc.left,-rc.top);
m_rect=rc;// re-init
//afxDump << rc << "\n";
}
}
}
else
{
CButton::OnLButtonDown(nFlags, point);
}
}