樣式掛鉤消息從WndProc
分支TWinControl
。如果樣式掛鉤報告處理了消息,則返回WndProc
並且不調度該消息。這就是爲什麼表單樣式的WM_NCHITTEST
消息處理程序在樣式化時未被觸發的原因。
因此,一種選擇是覆蓋表格的WndProc
。
type
TTestForm = class(TForm)
protected
procedure WndProc(var Message: TMessage); override;
...
procedure TTestForm.WndProc(var Message: TMessage);
begin
inherited;
if (Message.Msg = WM_NCHITTEST) and (Message.Result in [HTLEFT, HTRIGHT]) then
Message.Result := HTBORDER;
end;
另一種選擇是使用使用的樣式鉤重寫消息的處理的後裔。
type
TTestForm = class(TForm)
...
end;
implementation
uses
themes;
type
TTestFormStyleHook = class(TFormStyleHook)
protected
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
end;
procedure TTestFormStyleHook.WMNCHitTest(var Message: TWMNCHitTest);
begin
inherited;
case Message.Result of
HTLEFT, HTRIGHT: Message.Result := HTBORDER;
HTTOPLEFT, HTTOPRIGHT: Message.Result := HTTOP;
HTBOTTOMLEFT, HTBOTTOMRIGHT: Message.Result := HTBOTTOM;
end;
end;
initialization
TCustomStyleEngine.RegisterStyleHook(TTestForm, TTestFormStyleHook);
end.
它被觸發它只是永遠不會到達你的處理程序。您將不得不調查樣式引擎源並查找它在哪裏偵聽或掛接WM_NCHITTEST –