-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStopJumpAroundPluginDataModule.pas
More file actions
129 lines (105 loc) · 3.65 KB
/
Copy pathStopJumpAroundPluginDataModule.pas
File metadata and controls
129 lines (105 loc) · 3.65 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit StopJumpAroundPluginDataModule;
interface
uses
ToolsAPI, VCL.Menus, VCL.ActnList,VCL.Forms,Winapi.Messages, Vcl.Dialogs,
Winapi.Windows, System.SysUtils, System.Classes, Winapi.ActiveX, System.TypInfo, DockForm, DesignIntf,
Vcl.Graphics, Vcl.ImgList, Vcl.Controls, Vcl.ComCtrls, Vcl.Themes, Xml.XMLIntf, System.IniFiles,
System.Types, PersonalityConst, System.ImageList, Vcl.AppEvnts, Vcl.ExtCtrls;
type
TMainPlugin = class(TDataModule)
SubclassTimer: TTimer;
procedure SubclassTimerTimer(Sender: TObject);
private
FOrigWndProc: TWndMethod;
FSubclassed: Boolean;
FLastAllowedWindowChangingTimestamp:TDateTime;
procedure SubclassMainForm;
procedure UnsubclassMainForm;
procedure CustomWndProc(var Message: TMessage);
public
destructor Destroy; override;
end;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
procedure TMainPlugin.SubclassMainForm;
begin
if FSubclassed then exit;
if Application = nil then exit;
if Application.MainForm = nil then exit;
FOrigWndProc := Application.MainForm.WindowProc;
Application.MainForm.WindowProc := CustomWndProc;
FSubclassed := True;
end;
procedure TMainPlugin.UnsubclassMainForm;
begin
if not FSubclassed then exit;
if Application = nil then exit;
if Application.MainForm = nil then exit;
Application.MainForm.WindowProc := FOrigWndProc;
FSubclassed := False;
end;
destructor TMainPlugin.Destroy;
begin
UnsubclassMainForm;
inherited;
end;
procedure TMainPlugin.CustomWndProc(var Message: TMessage);
function IsWindowsPosChangingMessageToBeStopped:boolean;
begin
result := false;
if IsIconic(Application.MainForm.Handle) then exit;
// workaround for when the window gets frozen and invisible with its "iconized" size, even if it isn't iconic anymore
if Application.MainForm.Width<200 then exit;
if Application.MainForm.Height<200 then exit;
if (GetKeyState(VK_LWIN)<0) or (GetKeyState(VK_LBUTTON) < 0) then begin
// if I am allowing the movement because user is using the mouse or using windows+left/right/top/bottom shortcuts
// i allow subsequents moves for a couple of seconds in order to allow the movements caused by "window snapping"
// to the screen borders done the operating system
FLastAllowedWindowChangingTimestamp := now;
exit; //user could be dragging the window
end;
if (now - FLastAllowedWindowChangingTimestamp) < (2/24/60/60) then
exit;
result := true;
end;
procedure WindowPosChanging(var message:TWMWindowPosChanging);
begin
message.WindowPos.flags := message.WindowPos.flags or SWP_NOMOVE or SWP_NOSIZE;
message.Result := 0;
end;
begin
case message.Msg of
WM_WINDOWPOSCHANGING:
if IsWindowsPosChangingMessageToBeStopped then begin
WindowPosChanging(TWMWindowPosChanging(Message));
exit;
end;
WM_SYSCOMMAND:
begin
var cmd := message.WParam;
if (cmd = SC_MINIMIZE) or (cmd = SC_MAXIMIZE) or (cmd = SC_RESTORE) then
FLastAllowedWindowChangingTimestamp := now;
end;
WM_NCLBUTTONDOWN:
begin
var hit := Message.WParam;
if (hit = HTMAXBUTTON) or (hit = HTMINBUTTON) or (hit = HTCAPTION) then
FLastAllowedWindowChangingTimestamp := now;
end;
end;
FOrigWndProc(message);
end;
var thePlugin:TMainPlugin =nil;
procedure TMainPlugin.SubclassTimerTimer(Sender: TObject);
begin
// i try multiple times until the main form has been created
SubclassMainForm;
if FSubclassed then
SubclassTimer.Enabled:=false;
end;
initialization
thePlugin:= TMainPlugin.create(nil);
finalization
FreeAndNil(thePlugin);
end.