令人沮丧的处理窗口消息(WM_XX)
我正在尝试使用普通的 WinAPI 为自己创建一个 GUI 库。但我发现处理 Window Message 真的很令人沮丧。
例如,我可以看到,当我将鼠标移到窗口上时,WM_NCHITTEST 将在 WM_MOUSEMOVE 之前发送给我。 但是,如果我按下左按钮,四处移动,然后释放左按钮。然后我只收到 WM_MOUSEMOVE 之后。可能是因为我在收到 WM_LBUTTONDOWN 时调用 SetFocus(HWND)、SetCapture(HWND) 和在收到 WM_LBUTTONUP 时调用 ReleaseCapture(HWND)
这些不同的行为对我来说似乎很模糊。我想知道是否有任何文档/文章解释有关这些窗口消息的详细信息。至少告诉我应该注意什么。 (Charles的“Programming Windows”对我不起作用,因为它只介绍了这些消息的基础,但没有告诉我像我提到的WM_NCHITTEST / WM_MOUSEMOVE那样的陷阱)
I'm trying to make myself a GUI library using plain WinAPI. But I found that dealing with Window Message really frustrating.
For example, I can see that when I move my mouse over my window, WM_NCHITTEST will send to me before WM_MOUSEMOVE.
But if I press down the left button, move around, then release the left button. Then I only receive WM_MOUSEMOVE afterward. Possibly it was because I call SetFocus(HWND), SetCapture(HWND) when receive WM_LBUTTONDOWN and ReleaseCapture(HWND) when receive WM_LBUTTONUP
These different behaviors seem like a mist to me. I wonder is there any documentation / article explaining the details about these Window Message. At least, tell me what I should pay attention to. (Charles's "Programming Windows" doesn't work for me, because it only introduce the basis about those messages, but not telling me traps like I mention about the WM_NCHITTEST / WM_MOUSEMOVE)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过说
SetCapture(HWND)
,您要求系统将所有鼠标消息重定向到您的窗口,直到您调用ReleaseCapture(HWND)
。当某个窗口捕获鼠标输入(因此所有消息都重定向到那里)时,无需发送WM_NCHITTEST
。如果需要,您可以自行向鼠标下的窗口发送WM_NCHITTEST。
By saying
SetCapture(HWND)
you asking system to redirect all mouse messages to your window until you callReleaseCapture(HWND)
. When mouse input is captured (so all messages redirected there) by some window there is no need to sendWM_NCHITTEST
.If needed you can send WM_NCHITTEST to windows under the mouse by yourself.
http://msdn.microsoft.com/en-us/库/ms645618(VS.85).aspx
http://blogs.msdn.com/b/oldnewthing/archive/2011/02/18/10131176.aspx
WM_NCHITTEST 用于命中测试。它仅在需要时发送。 MSDN 上有每条消息的文档。还有关于鼠标输入的部分 http:// msdn.microsoft.com/en-us/library/ms645533(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms645618(VS.85).aspx
http://blogs.msdn.com/b/oldnewthing/archive/2011/02/18/10131176.aspx
WM_NCHITTEST is for hit-testing. It only gets sent when needed. MSDN has documentation on each message. There is also a section on mouse input http://msdn.microsoft.com/en-us/library/ms645533(v=VS.85).aspx