问题
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