🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9259

Re: How to evoke browser for local file relative to exe dir?

#9259
From: Remy Lebeau (TeamB)
Date: Tue, 20 Jul 2004 21:32
53 lines
3054 bytes
"Randall Parker" <STOPtechiepundit@EVILfuturePOXpunditSPAM.com> wrote in
message news:40fd8196$1@newsgroups.borland.com...

> Suppose one is running an app. The app started from
> some directory. From that app how to evoke the default
> browser and pass it the path to a file that is relative to
> the dir that the exe is in?

    #include <shellapi>

    AnsiString File = "file://" + ExtractFilePath(Application->ExeName) +
"somefile.html";
    ::ShellExecute(NULL, "open", File.c_str(), 0, 0, SW_SHOWNORMAL);

> 1) Can I assume that any path passed to a browser will
> be interpreted as being a relative path to the current exe?

No, because the browser has no concept of where the calling exe is located
to begin with.  You have to give the browser a full path to the actual file
that it will be loading..

> 2) Is there a syntax for a local file URL that all browsers
> recognize? I see that IE doesn't do file:/// for files you open locally

Yes, it does.  It may not appear in the main address bar, but IE definately
supports the "file://" protocol, and if you right-click on a loaded file and
look at its properties then you will see the filename displayed using the
"file://" protocol.

> 4) How to convert the local path to URL format with
> the backslashes converted to forward slashes?

Look at StringReplace() in the VCL.

> 5) Is it necessary to do double quoting escapes for paths
> that have spaces in dir names?

Spaces and other special-case characters should be encoded to hex strings,
not wrapped in quotes.  Spaces would be encoded as "%20", for exactly
"C:\\Program%20Files\\Some%20Folder\\Some%20File.ext".  20 is the hex value
of decimal 32, which is the ASCII value for a space character.

> 6) Is there a way to tell the browser to open a new instance/window/tab
> rather than replace the current page of the browser with the new page?

For that, you have to actually communicate with the existing browser
instance.  Have a look at DDE for that.  Most browsers support the
WWW_OpenURL command, which has a parameter for the window name to open the
URL in.


Gambit
Technical Details
Message-ID: <40fd8f46$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40fd8196$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,cc0cc83f65df649b
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40fd8196$1@newsgroups.borland.com>
Subject: Re: How to evoke browser for local file relative to exe dir?
Date: Tue, 20 Jul 2004 14:32:47 -0700
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <40fd8f46$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090359110 68.69.17.41 (20 Jul 2004 14:31:50 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail