Closed changguangyu closed 6 years ago
I already answered this question on G+. However I'm going to re-post the example.
uses DDetours;
type
TTrampolineWMActivate = procedure(Control: TControl; var Message: TWMActivate);
TCustomFormHack = type TCustomForm;
var
TrampolineWMActivate: TTrampolineWMActivate = nil;
procedure WMActivateHook(Control: TControl; var Message: TWMActivate);
const
Bool2Str: array [Boolean] of string = ('False', 'True');
begin
Main.Caption := Format('WMActivate(%s).Active=%s', [Control.Name, Bool2Str[Message.Active <> WA_INACTIVE]]);
TrampolineWMActivate(Control, Message);
end;
procedure TMain.FormCreate(Sender: TObject);
begin
@TrampolineWMActivate := InterceptCreate(@TCustomFormHack.WMActivate, @WMActivateHook);
end;
Thanks. It works. But why TTrampolineWMActivate = procedure(const Self; var Message: TWMActivate); doesn't work?
That's because Self operand will be passed by ref (normally it defaults to by val).
I want to hook WMActivate.