这是段判断鼠标是否在按钮上的代码,其中有些地方不明白???
void CColorButton::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd *pWnd;
CWnd *pParent; CButton::OnMouseMove(nFlags, point); pWnd=GetActiveWindow();
pParent=GetOwner(); if ((GetCapture() != this) && //这个GetCapture()是做什么的,为什么不等于this,鼠标却为TRUE???
pWnd != NULL && pParent != NULL)
{
m_MouseOnBtn = TRUE;
SetCapture(); //这个SetCapture()干吗???
Invalidate();
}
else
{
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(point))
{
if (m_MouseOnBtn == TRUE)
{
m_MouseOnBtn = FALSE;
Invalidate();
}
if (!(nFlags & MK_LBUTTON)) ReleaseCapture(); //??
}
}
}
void CColorButton::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd *pWnd;
CWnd *pParent; CButton::OnMouseMove(nFlags, point); pWnd=GetActiveWindow();
pParent=GetOwner(); if ((GetCapture() != this) && //这个GetCapture()是做什么的,为什么不等于this,鼠标却为TRUE???
pWnd != NULL && pParent != NULL)
{
m_MouseOnBtn = TRUE;
SetCapture(); //这个SetCapture()干吗???
Invalidate();
}
else
{
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(point))
{
if (m_MouseOnBtn == TRUE)
{
m_MouseOnBtn = FALSE;
Invalidate();
}
if (!(nFlags & MK_LBUTTON)) ReleaseCapture(); //??
}
}
}
标识了捕获鼠标的窗口。如果没有窗口捕获鼠标则返回NULL,这个函数获得捕获了鼠标的窗口。在一个给定的时刻只能有一个窗口捕获鼠标。当调用了SetCapture成员函数之后,窗口将接收鼠标捕获。这个窗口将接收所有的鼠标输入,不管光标是否位于它的边界内。SetCapture
原来接收所有鼠标输入的窗口的指针。如果没有这样的窗口,则返回值为NULL。返回的指针可能是临时的,不能被保存以供将来使用。
这个函数使随后的所有鼠标输入都被发送到当前的CWnd对象,并不考虑光标的位置。当CWnd不再需要所有的鼠标输入时,应用程序应当调用ReleaseCapture函数以使其它窗口能够接收鼠标输入。When CWnd no longer requires all mouse input, the application should call theReleaseCapture function so that other windows can receive mouse input.