-
Notifications
You must be signed in to change notification settings - Fork 4
/
frmOpenURL.pas
147 lines (130 loc) · 3.88 KB
/
frmOpenURL.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
unit frmOpenURL;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.ListBox, registry, windows, FMX.Controls.Presentation, FMX.StdCtrls,
System.ImageList, FMX.ImgList;
type
TfrmBrowserChooser = class(TForm)
FBrowserListBox: TListBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FBrowserListBoxDblClick(Sender: TObject);
private
{ Private declarations }
FURL : String;
FProgramPathList : TStringList;
procedure LoadListBox(inKey: HKEY; inListbox: TListBox);
procedure AddEdge(inListbox: TListBox);
public
{ Public declarations }
procedure OpenUrl(url:String);
end;
procedure OpenURL(inURL: string);
implementation
{$R *.fmx}
uses Winapi.ShellAPI;
procedure OpenURL(inURL: string);
var
frmBrowserChooser : TfrmBrowserChooser;
begin
frmBrowserChooser := TfrmBrowserChooser.Create(nil);
try
frmBrowserChooser.OpenUrl('https://www.tysontechnology.com.au');
finally
FreeAndNil(frmBrowserChooser);
end;
end;
procedure TfrmBrowserChooser.AddEdge(inListbox:TListBox);
var
listboxItem : TListboxItem;
programPath : String;
begin
listboxItem := TListBoxItem.Create(inListbox);
listboxItem.Text := 'Microsoft Edge';
programPath := 'shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge';
listboxItem.TagString := programPath;
inListbox.AddObject(listboxItem);
FProgramPathList.Add(programPath);
end;
procedure TfrmBrowserChooser.FormCreate(Sender: TObject);
begin
FProgramPathList := TStringList.Create;
LoadListBox(HKEY_CURRENT_USER,FBrowserListBox);
LoadListBox(HKEY_LOCAL_MACHINE,FBrowserListBox);
OutputDebugString(PChar(TOSVersion.ToString));
if TOSVersion.Major >= 10 then // Add Microsoft Edge if Windows 10
AddEdge(FBrowserListBox);
end;
procedure TfrmBrowserChooser.FormDestroy(Sender: TObject);
begin
FreeAndNil(FProgramPathList);
end;
procedure TfrmBrowserChooser.LoadListBox(inKey : HKEY;inListbox:TListBox);
var
names : TStringList;
i : Integer;
reg : TRegistry;
regName : TRegistry;
regOpen : TRegistry;
listboxItem : TListboxItem;
programPath : string;
begin
reg := nil;
names := nil;
try
reg := TRegistry.Create;
names := TStringList.Create;
reg.RootKey := inKey;
if reg.OpenKeyReadOnly('SOFTWARE\Clients\StartMenuInternet') then
begin
reg.GetKeyNames(names);
for i := 0 to names.Count - 1 do
begin
regName := nil;
regOpen := nil;
try
regName := TRegistry.Create;
regName.RootKey := inKey;
regOpen := TRegistry.Create;
regOpen.RootKey := inKey;
if regName.OpenKeyReadOnly('SOFTWARE\Clients\StartMenuInternet\'+names[i]) and
regOpen.OpenKeyReadOnly('SOFTWARE\Clients\StartMenuInternet\'+names[i]+'\Shell\Open\Command') then
begin
programPath := regOpen.ReadString('');
if FProgramPathList.IndexOf(programPath)<0 then
begin
listboxItem := TListBoxItem.Create(inListbox);
listboxItem.Text := regName.ReadString('');
listboxItem.TagString := programPath;
inListbox.AddObject(listboxItem);
FProgramPathList.Add(programPath);
end;
end;
finally
FreeAndNil(regName);
FreeAndNil(regOpen);
end;
end;
end;
finally
FreeAndNil(reg);
FreeAndNil(names);
end;
end;
procedure TfrmBrowserChooser.FBrowserListBoxDblClick(Sender: TObject);
var
programPath : String;
begin
programPath := FBrowserListBox.Selected.TagString;
ShellExecute(0,'open',PChar(programPath), PChar(FURL),'',SW_SHOWNORMAL);
Close;
end;
procedure TfrmBrowserChooser.OpenUrl(url: String);
begin
FURL := url;
ShowModal;
end;
end.