Not receiving WM_NCHitTest on title bar

删除回忆录丶 提交于 2020-01-05 05:26:09

问题


I noticed that the message WM_NCHitTest isn't sent to a form when the cursor is inside the caption bar (not on the border).

I tried to intercept it using either

procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;

or

procedure WndProc(var Message: TMessage); override;

According to MSDN I was expecting to receive it for any point, with no blind spots.

Did I miss something or this is the intended behaviour?

I'm using Delphi 2010 on Windows 7, with Aero on.


回答1:


Yes -- that's expected. Unless you disable the DWM, you won't get WM_NCHITTEST messages when the cursor is in the title bar. Basically, when the DWM is on, the title bar "belongs" to the DWM, not your application.

If you really need those messages, you can disable the DWM -- but keep in mind that when/if you do this, it does not just disable it for your application. If you disable it, it's disabled for the whole system (until it's re-enabled again, of course).




回答2:


There might be an alternative message you can listen to... see http://social.msdn.microsoft.com/Forums/en-US/windowsuidevelopment/thread/9a8a63c8-79b5-43a8-82eb-f659be947add




回答3:


You can always use the WM_NCMOUSEMOVE message and test for its HitTest property:

procedure WMNCMouseMove(var Message: TWMNCMouseMove); message WM_NCMOUSEMOVE;  

[...]

procedure TForm11.WMNCMouseMove(var Message: TWMNCMouseMove);
begin
  with Message do
    if HitTest = HTCAPTION then
      Caption := Format('%d:%d',[XCursor,YCursor]);
end;


来源:https://stackoverflow.com/questions/3631831/not-receiving-wm-nchittest-on-title-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!