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
|
////////////////////////////////////////////////////////////////////////////////
// All code below is exclusively owned by author of Chess4Net - Pavel Perminov
// (packpaul@mail.ru, packpaul1@gmail.com).
// Any changes, modifications, borrowing and adaptation are a subject for
// explicit permition from the owner.
unit NonMainFormStayOnTopUnit;
// Inclusion of this unit enables all non-main forms with FormStyle = fsStayOnTop
// to stay on top even if application is deactivated
interface
implementation
uses
Forms, SysUtils, Classes, Messages, Windows;
type
TApplicationObjSubclasser = class
private
m_NewObj, m_OldObj: pointer;
procedure FWndProc(var Message: TMessage);
public
constructor Create;
destructor Destroy; override;
end;
var
g_ApplicationObjSubclasserInstance: TApplicationObjSubclasser = nil;
////////////////////////////////////////////////////////////////////////////////
// TApplicationObjSubclasser
constructor TApplicationObjSubclasser.Create;
begin
inherited Create;
m_NewObj := Classes.MakeObjectInstance(FWndProc);
m_OldObj := Pointer (SetWindowLong(Application.Handle, GWL_WNDPROC,
Cardinal(m_NewObj)));
end;
destructor TApplicationObjSubclasser.Destroy;
begin
SetWindowLong(Application.Handle, GWL_WNDPROC, Cardinal(m_OldObj));
Classes.FreeObjectInstance(m_NewObj);
inherited;
end;
procedure TApplicationObjSubclasser.FWndProc(var Message: TMessage);
begin
Message.Result := CallWindowProc (m_OldObj, Application.Handle,
Message.Msg, Message.wParam, Message.lParam);
case Message.Msg of
WM_ACTIVATEAPP:
begin
if (not TWMActivateApp(Message).Active) then
Application.RestoreTopMosts;
end;
end;
end;
initialization
g_ApplicationObjSubclasserInstance := TApplicationObjSubclasser.Create;
finalization
FreeAndNil(g_ApplicationObjSubclasserInstance);
end.
|