-
Notifications
You must be signed in to change notification settings - Fork 14
/
Mouse.WheelRouting.pas
54 lines (42 loc) · 1.21 KB
/
Mouse.WheelRouting.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
unit Mouse.WheelRouting;
interface
uses
Winapi.Windows, Winapi.Messages, Vcl.Forms;
type
TMouseWheelRouting = class
private class var
FOnMessage: TMessageEvent;
FCurrentProcessId: DWORD;
protected
class procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
class procedure Init;
public
class property OnMessage: TMessageEvent read FOnMessage write FOnMessage;
end;
implementation
{ TMouseWheelRouting }
class procedure TMouseWheelRouting.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
Wnd: HWND;
ProcessId: DWORD;
begin
if (Msg.message = WM_MOUSEWHEEL) or (Msg.message = WM_MOUSEHWHEEL) then begin
Wnd := WindowFromPoint(Msg.pt);
if Wnd <> 0 then begin
GetWindowThreadProcessId(Wnd, ProcessId);
if ProcessId = FCurrentProcessId then
SendMessage(Wnd, Msg.message, Msg.wParam, Msg.lParam);
end;
Handled := True;
end;
if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
end;
class procedure TMouseWheelRouting.Init;
begin
FCurrentProcessId := GetCurrentProcessId;
FOnMessage := nil;
Application.OnMessage := AppMessage;
end;
initialization
TMouseWheelRouting.Init;
end.