2004. január 11., vasárnap

How to run the Netscape Navigator automatically after closing a form


Problem/Question/Abstract:

How to run the Netscape Navigator automatically after closing a form

Answer:

Do you definitely want to start Netscape, or just the user's default browser? To start Netscape, in preference to anything else, something like this would work in the form's onclose handler (add registry and ShellAPI to your unit's uses list):


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  reg: TRegistry;
  NetscapeVer, NetscapeDir: string;
begin
  {This has a number of shortcomings, not least the lame error handlers}
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    if not reg.OpenKey('SOFTWARE\Netscape\Netscape Navigator', false) then
      exit;
    NetscapeVer := reg.ReadString('CurrentVersion');
    if not reg.OpenKey(NetscapeVer + '\Main', false) then
      exit;
    showmessage(reg.CurrentPath);
    NetscapeDir := reg.ReadString('Install Directory') + '\program\';
    ShellExecute(0, 'open', PChar(NetscapeDir + 'netscape.exe'), nil, nil, SW_NORMAL);
  finally
    reg.free;
  end;
end;


If you just wish to start the users browser you could do something like (having added ShellAPI
to your uses list):


ShellExecute(0, 'open', 'http://www.yahoo.com', nil, nil, SW_NORMAL);

Nincsenek megjegyzések:

Megjegyzés küldése