问一个使用SetWindowPos制作逃跑按钮的问题

shotgun79 2005-03-09 05:26:56

使用MFC生成一个对话框,在上面放一个按钮,并将其关联到一个自定义的派生于CButton的button类(即我的CMyBtn类)的对象,在其中响应OnMouseMove,其中代码如下:
void CMyBtn2::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
GetParent()->GetWindowRect(&m_dlgRect); //获取对话框父窗口尺寸
GetWindowRect(&m_btnRect); //获取对话框尺寸
m_btnWidth=m_btnRect.Width();
m_btnRect.left=m_btnRect.left+m_btnWidth;
m_btnRect.right=m_btnRect.right+m_btnWidth; //重新计算button尺寸
// SetWindowPos(NULL,m_btnRect.left,m_btnRect.right,m_btnRect.Width(),m_btnRect.Height(),SWP_SHOWWINDOW);
MoveWindow(m_btnRect.left,m_btnRect.right,m_btnRect.Width(),m_btnRect.Height(),true);
CButton::OnMouseMove(nFlags, point);
}

问题是当我的鼠标移动到button上时,button就消失了,却没有在别的地方出现,经检查button的新位置没有超出其父窗口(即对话框)范围。我试用了setwindowpos和MoveWindow两个函数都是如此,不知道是怎么回事。请各位指教。
...全文
138 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nik_Amis 2005-03-10
  • 打赏
  • 举报
回复
up
shotgun79 2005-03-10
  • 打赏
  • 举报
回复
谢谢各位,已经知道是screentoclient的问题。
菜牛 2005-03-09
  • 打赏
  • 举报
回复
MoveWindow(
int x,
int y,
int nWidth,
int nHeight,
BOOL bRepaint = TRUE
);
For a top-level CWnd object, the x and y parameters are relative to the upper-left corner of the screen. For a child CWnd object, they are relative to the upper-left corner of the parent window's client area.
billy145533 2005-03-09
  • 打赏
  • 举报
回复
试试客户与屏幕坐标的转换一下
screentoclient
pomelowu 2005-03-09
  • 打赏
  • 举报
回复
后面加个ShowWindow试试看?
其实还不如重载Dialog的OnMouseMove

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧