关于 WM_NCHITTEST 消息 的疑问?

BOYGUARD110 2004-10-15 11:06:18

通过 发 WM_NCHITTEST 可以获得 鼠标 的位置信息,但是下面的代码没有反应

// mfc 框架 CDialog based framework
void CCSDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
POINT pt;

// 发消息,或直接 用 ::DefWindowProc
//UINT where = ::SendMessage(this->m_hWnd,WM_NCHITTEST,0,(LPARAM)&pt);
UINT where = ::DefWindowProc(this->m_hWnd,WM_NCHITTEST,0,(LPARAM)&pt);

// 用鼠标单击窗口客户区,应该得到 HTCLIENT 吧?
if(where == HTCLIENT)
{
AfxMessageBox("HTCLIENT"); //
}

CDialog::OnLButtonDown(nFlags, point);
}

//////////////////////////////////////////////////////////////
//
问题:

1. 关于 WM_NCHITTEST 消息,我的理解是否有误,

2. 不想只是被动的接受 WM_NCHITTEST 消息,
谁给一个 自己发送WM_NCHITTEST 消息 消息的 实例,

谢谢



...全文
219 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangjs720 2004-10-17
  • 打赏
  • 举报
回复
OnNcHitTest中的坐标参数是屏幕坐标,而OnLButton中的坐标是客户区坐标,.
roger_ding 2004-10-17
  • 打赏
  • 举报
回复
lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

这是WM_NCHITTEST lParam的说明,就是传入的坐标是相对屏幕的,改为:

CPoint pt(point);
ClientToScreen(&pt);
UINT where = ::DefWindowProc(m_hWnd,WM_NCHITTEST,0,(LPARAM)&pt);
BOYGUARD110 2004-10-17
  • 打赏
  • 举报
回复
up
BOYGUARD110 2004-10-16
  • 打赏
  • 举报
回复
我贴的代码 中 DefWindowProc 的返回值 总是 HTNOWHERE (0),不对劲呀

菜牛 2004-10-15
  • 打赏
  • 举报
回复
DefWindowProc 的返回值是什么?
BOYGUARD110 2004-10-15
  • 打赏
  • 举报
回复

谢谢楼上 ,我知道 GetCursorPos 函数 ,

现在主要是想了解 WM_NCHITTEST 消息的 用法,

因为msdn上说 默认情况是 DefWindowProc 在处理这个消息 并返回一个位置信息,

但是上面的代码总是返回 0 ,就是HTNOWHERE,



try876 2004-10-15
  • 打赏
  • 举报
回复
要得到鼠标的位置用GetCursorPos()就行啦
必要时要ScreenToClient()一下

15,979

社区成员

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

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