- Mon 03 March 2014
- misc
- Tero Koskinen
- #windows, #url, #browser
Here is how you can open a web page with the default browser on Windows:
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
procedure Browser is
Cmd : aliased char_array := To_C ("open");
Html_Path : aliased char_array := To_C ("http://ada.tips/");
Dir : aliased char_array := To_C ("\");
H : Long;
function Shell_Execute (Wnd : Int;
Operation, File, Parameters, Directory : chars_ptr;
ShowCmd : Interfaces.C.Int) return Long;
Pragma Import (Stdcall, Shell_Execute, "ShellExecuteA");
begin
-- ShellExecute(null, "open", htmlpath, NULL, "\", SW_SHOWNORMAL);
H := Shell_Execute
(0,
To_Chars_Ptr (Cmd'Unchecked_Access),
To_Chars_Ptr (Html_Path'Unchecked_Access),
Null_Ptr,
To_Chars_Ptr (Dir'Unchecked_Access), 1);
end Browser;
As you can see, you need only need to import Shell_Execute and call it with "open" parameter and the url you want to see.