-
Notifications
You must be signed in to change notification settings - Fork 17
/
TrackInf.pas
128 lines (102 loc) · 2.52 KB
/
TrackInf.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
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
{
This is part of Vortex Tracker II project
Version 2.0 and later
(c)2017-2021 Ivan Pirog, [email protected]
https://github.com/ivanpirog/vortextracker
}
unit TrackInf;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, RichEdit, ShellAPI, trfuncs;
type
TRichEdit = class(ComCtrls.TRichEdit)
private
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
protected
procedure CreateWnd; override;
end;
TTrackInfoForm = class(TForm)
Info: TRichEdit;
OK: TButton;
procedure OKClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SetRTFText(RTFText: String);
procedure Init(VTMP: PModule);
end;
var
TrackInfoForm: TTrackInfoForm;
implementation
uses Main;
{$R *.dfm}
procedure TRichEdit.CreateWnd;
var
mask: LResult;
begin
inherited;
mask := SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
SendMessage(Handle, EM_AUTOURLDETECT, 1, 0);
end;
procedure TRichEdit.CNNotify(var Message: TWMNotify);
type
PENLink = ^TENLink;
var
p: PENLink;
tr: TEXTRANGE;
url: array of Char;
begin
if (Message.NMHdr.code = EN_LINK) then begin
p := PENLink(Message.NMHdr);
if (p.Msg = WM_LBUTTONDOWN) then begin
try
SetLength(url, p.chrg.cpMax - p.chrg.cpMin + 1);
tr.chrg := p.chrg;
tr.lpstrText := PChar(url);
SendMessage(Handle, EM_GETTEXTRANGE, 0, LPARAM(@tr));
ShellExecute(Handle, nil, PChar(url), nil, nil, SW_SHOWNORMAL);
except
{ignore}
end;
Exit;
end;
end;
inherited;
end;
procedure TTrackInfoForm.SetRTFText(RTFText: String);
var
ss: TStringStream;
emptystr: string;
begin
emptystr := '';
ss := TStringStream.Create(emptystr);
try
ss.WriteString(RTFText);
ss.Position := 0;
Info.PlainText := False;
Info.Lines.BeginUpdate;
Info.Lines.LoadFromStream(ss);
Info.Lines.EndUpdate;
finally
ss.Free;
end;
end;
procedure TTrackInfoForm.Init(VTMP: PModule);
var Title: String;
begin
SetRTFText(VTMP.Info);
Title := 'Track Info';
if Trim(VTMP.Title) <> '' then Title := VTMP.Title;
if Trim(VTMP.Author) <> '' then Title := Title + ' by ' + VTMP.Author;
Caption := Title;
Left := MainForm.Left + (MainForm.Width div 2) - (Width div 2);
Top := MainForm.Top + (MainForm.Height div 2) - (Height div 2);
end;
procedure TTrackInfoForm.OKClick(Sender: TObject);
begin
Hide;
end;
end.