uses ShellAPI;
function Tform1.Regkey(Key: HKEY; Subkey: string; var Data: string): Longint;
var
H : HKEY;
tData: array[0..259] of Char;
dSize: Integer;
begin
Result := RegOpenKeyEx(Key, PChar(Subkey), 0, KEY_QUERY_VALUE, H);
if Result = ERROR_SUCCESS then
begin
dSize := Sizeof(tData);
RegQueryValue(H, nil, tData, dSize);
Data := StrPas(tData);
RegCloseKey(H);
end;
end;
procedure TFORM1.StartNewBrowserWindow(URL: string);
var
P : Integer;
Key,urlstr: string;
begin
if Regkey(HKEY_CLASSES_ROOT, '.htm', Key) = ERROR_SUCCESS then
begin
Key := Key + '\shell\open\command';
if Regkey(HKEY_CLASSES_ROOT, Key, Key) = ERROR_SUCCESS then
begin
P := Pos('"%1"', Key);
if P = 0 then
P := Pos('%1', Key);
if P <> 0 then
setlength(Key, P - 1);
urlstr := Key + ' ' + URL;
if WinExec(PChar(urlstr), SW_SHOWNORMAL) < 32 then
raise Exception.Create('Couldn''t launch default browser');
end;
end;
end;
然后只要
procedure TFORM1.BUTTON1Click(Sender: TObject);
begin
StartNewBrowserWindow('www.163.com');
end;
function Tform1.Regkey(Key: HKEY; Subkey: string; var Data: string): Longint;
var
H : HKEY;
tData: array[0..259] of Char;
dSize: Integer;
begin
Result := RegOpenKeyEx(Key, PChar(Subkey), 0, KEY_QUERY_VALUE, H);
if Result = ERROR_SUCCESS then
begin
dSize := Sizeof(tData);
RegQueryValue(H, nil, tData, dSize);
Data := StrPas(tData);
RegCloseKey(H);
end;
end;
procedure TFORM1.StartNewBrowserWindow(URL: string);
var
P : Integer;
Key,urlstr: string;
begin
if Regkey(HKEY_CLASSES_ROOT, '.htm', Key) = ERROR_SUCCESS then
begin
Key := Key + '\shell\open\command';
if Regkey(HKEY_CLASSES_ROOT, Key, Key) = ERROR_SUCCESS then
begin
P := Pos('"%1"', Key);
if P = 0 then
P := Pos('%1', Key);
if P <> 0 then
setlength(Key, P - 1);
urlstr := Key + ' ' + URL;
if WinExec(PChar(urlstr), SW_SHOWNORMAL) < 32 then
raise Exception.Create('Couldn''t launch default browser');
end;
end;
end;
然后只要
procedure TFORM1.BUTTON1Click(Sender: TObject);
begin
StartNewBrowserWindow('www.163.com');
end;
解决方案 »
- 谁能谈谈delphi 2010 的功能 与 delphi7 的区别?
- 怎样写一个判断用户离开电脑的代码,比喻像屏保一样n分钟没动就自动保护,要求不要占太多系统资源
- 怎样将一个EXE或DLL调至某一PANEL中运行?
- 莫名其妙的错误
- waveinopen的callback_function怎么用呀?
- 我的专家分刚过300分,三个绿星要多少分才行?
- ActiveX 控件怎么避开IE的安全检查的?
- 十万火急,高手求助
- Delphi.net Preview
- 局域网内,怎样得到访问你的用户的机器名、IP地址?
- SQL Server 2000中,数据库的事务日太大了时,可否进行部分清除的操作?
- 急急急!!!!!!!!!!!!!!!!
SW_SHOWNORMAL 改为 SW_HIDE。
用 shellExecute也一样的