Call this member function to change the size, position, and Z-order of child, pop-up, and top-level windows. BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
这个也可以~~~
kikikind(可乐):感谢回答,但我问的不是这个问题,
从CButton类继承自己的按钮类CMyButton 加入三个成员变量: BOOL m_bCapture; CPoint m_pt; CRect m_rect;然后映射WM_LBUTTONDOWN/WM_LBUTTONUP/WM_MOUSEMOVE消息,象下面这样就可以了. void CMyButton::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CButton::OnMouseMove(nFlags, point); if (!m_bCapture) return;
ClientToScreen(&point); int x=point.x-m_pt.x+m_rect.left; int y=point.y-m_pt.y+m_rect.top; CRect rect(x,y,x+m_rect.Width(),y+m_rect.Height());
BOOL SetWindowPos(
const CWnd* pWndInsertAfter,
int x,
int y,
int cx,
int cy,
UINT nFlags
);
这个也可以~~~
加入三个成员变量: BOOL m_bCapture;
CPoint m_pt;
CRect m_rect;然后映射WM_LBUTTONDOWN/WM_LBUTTONUP/WM_MOUSEMOVE消息,象下面这样就可以了.
void CMyButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CButton::OnMouseMove(nFlags, point);
if (!m_bCapture) return;
ClientToScreen(&point);
int x=point.x-m_pt.x+m_rect.left;
int y=point.y-m_pt.y+m_rect.top; CRect rect(x,y,x+m_rect.Width(),y+m_rect.Height());
MoveWindow(&rect);
}void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CButton::OnLButtonDown(nFlags, point);
SetCapture();
m_bCapture=TRUE;
m_pt=point;
ClientToScreen(&m_pt);
GetWindowRect(&m_rect);
GetParent()->ScreenToClient(&m_rect);
}void CMyButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CButton::OnLButtonUp(nFlags, point);
ReleaseCapture();
m_bCapture=FALSE;
}