How to use relative file:// protocol in html resource used by CDHTMLDialog?

Howdy,

I'm writing a C++ CDHTMLDialog based application in VS .net.  Of course I
have an HTML resource that contains the html code for display by
CDHTMLDialog (which wraps the Webrowser control).

I understand how to reference program resources in my HTML using the res:
protocol, but I'm having trouble getting the file: protocol to work with
relative references.

For example, if my embedded HTML resource includes this absolute path in my
htmlcode it works fine:

< IMG src="file:///C:\Documents and Settings\jim\My
Documents\temp\CHtmlApp\Debug\ugly2.bmp"  >

But if I put a copy of ugly2.bmp in the same folder with my main exe
executable I can't find the right relative URL to use.  For example, why
doesn't this work if I execute my application from the same folder that
ugly2.bmp resides in:

< img src="file:///ugly2.bmp">  I get a broken image for this tag.

What simple thing am I missing?

thanks

Jim Howard
jnhtx@spamcop.net


0
jnhtx (73)
11/5/2003 11:22:51 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
2337 Views

Similar Articles

[PageSpeed] 21

Hi, Jim.

For CDHTMLDialog you should place
<BASE href=file://yourfolderpath>
in the head section of your HTML document.

After that you can use relative URIs like <img src=myimage.gif>

Which will be resolved to file://yourfolderpath/myimage.gif .

The same rule applied to HTML loaded into HtmLayout (http://htmlayout.com).
(HtmLayout has also additional method SET_BASE while loading HTMLs from
memory buffers)

Best wishes,

Andrew Fedoniouk.
http://terrainformatica.com




"Jim Howard" <jnhtx@spamcop.net> wrote in message
news:OyC%238O$oDHA.2528@TK2MSFTNGP12.phx.gbl...
> Howdy,
>
> I'm writing a C++ CDHTMLDialog based application in VS .net.  Of course I
> have an HTML resource that contains the html code for display by
> CDHTMLDialog (which wraps the Webrowser control).
>
> I understand how to reference program resources in my HTML using the res:
> protocol, but I'm having trouble getting the file: protocol to work with
> relative references.
>
> For example, if my embedded HTML resource includes this absolute path in
my
> htmlcode it works fine:
>
> < IMG src="file:///C:\Documents and Settings\jim\My
> Documents\temp\CHtmlApp\Debug\ugly2.bmp"  >
>
> But if I put a copy of ugly2.bmp in the same folder with my main exe
> executable I can't find the right relative URL to use.  For example, why
> doesn't this work if I execute my application from the same folder that
> ugly2.bmp resides in:
>
> < img src="file:///ugly2.bmp">  I get a broken image for this tag.
>
> What simple thing am I missing?
>
> thanks
>
> Jim Howard
> jnhtx@spamcop.net
>
>


0
andrew5982 (15)
11/6/2003 1:41:16 AM
"Jim Howard" <jnhtx@spamcop.net> wrote in message
news:OyC%238O$oDHA.2528@TK2MSFTNGP12.phx.gbl...
> Howdy,
>
> I'm writing a C++ CDHTMLDialog based application in VS .net.  Of course I
> have an HTML resource that contains the html code for display by
> CDHTMLDialog (which wraps the Webrowser control).
>
> I understand how to reference program resources in my HTML using the res:
> protocol, but I'm having trouble getting the file: protocol to work with
> relative references.

The file: protocol does not work with relative references. You must specify
a full path.

> For example, if my embedded HTML resource includes this absolute path in
my
> htmlcode it works fine:
>
> < IMG src="file:///C:\Documents and Settings\jim\My
> Documents\temp\CHtmlApp\Debug\ugly2.bmp"  >
>
> But if I put a copy of ugly2.bmp in the same folder with my main exe
> executable I can't find the right relative URL to use.  For example, why
> doesn't this work if I execute my application from the same folder that
> ugly2.bmp resides in:
>
> < img src="file:///ugly2.bmp">  I get a broken image for this tag.

That's right.

> What simple thing am I missing?

This is tricky. There is no way at build time that you can tell what the
runtime path is going to be so you can not hard code this (like above) into
your HTML page.

What I do is actually include the image as a resource in my program. For a
start, reference the image as
<img src="ugly2.bmp">, compile your program and run it. Now you will be
looking at the HTML page. Right click on that page and select properties.
You will see the address is something like
res://c:\yourpath\prog.exe/142
where 142 (or whatever) is the ID of your HTML resource.

Now, right click>properties on the broken image and look at it's address.
This will be
res://c:\yourpath\prog/ugly2.bmp

With relative addresses the browser pulls the path out of the documents
location and sticks this in front of the relative path, the relative address
is actually referring to a resource in your program because that is where
the HTML page came from.

Now, to put the image in as a resource.

In your resource window add a new HTML resource. Look at the properties of
the new resource. Change the filename to "debug/ugly2.bmp"  (because that is
where you put the real image, you can change this to res/ugly2.bmp and move
your image to the res folder if you wish) and change the ID to "ugly2.bmp" -
include the quotation marks in the name. This way you have a resource with a
string name, not a number. It is this string name you have used in your HTML
to refer to the image.

I just noticed that the image is a BMP. You could make it a JPG to reduce
its size. The above method also works with JPGs. It even works with CSS
files. The HTML document will be able to <link> to a CSS file included as a
resource in the program.

I suppose you could include the BMP as a Bitmap resource too but my approach
keeps all the HTML things in the one place in the resources.

An added advantage is the bundling all the images etc into the on place, ie
in your program. You don't have to ship all those files and worry if they
are in the right folder or not.

Cheers
Richard.


0
11/6/2003 2:11:51 AM
Thomas & Andrew,

Thanks for your help, I'd forgot about the BASE tag.

I can get the res protocol to work with bitmaps, but if I try to add a gif
or jpg image as a resource then my Visual Studio .Net 2003 crashes!
Immediate warp-core breach followed by shutdown!

For the release version of my project I will have to get all the html
elements in as resources, but for now it would be easier to just read them
from the file system because the web designers gives me changes everyday,
and because I am procrastinating trouble-shooting this resource bug in my
copy Visual Studio.  I'll see if I can change the base tag to have the cwd
before loading it in my dialog window.

Jim Howard



"rf" <making.it.up@the.time> wrote in message
news:H5iqb.180407$bo1.80041@news-server.bigpond.net.au...
>
> "Jim Howard" <jnhtx@spamcop.net> wrote in message
> news:OyC%238O$oDHA.2528@TK2MSFTNGP12.phx.gbl...
> > Howdy,
> >
> > I'm writing a C++ CDHTMLDialog based application in VS .net.  Of course
I
> > have an HTML resource that contains the html code for display by
> > CDHTMLDialog (which wraps the Webrowser control).
> >
> > I understand how to reference program resources in my HTML using the
res:
> > protocol, but I'm having trouble getting the file: protocol to work with
> > relative references.
>
> The file: protocol does not work with relative references. You must
specify
> a full path.
>
> > For example, if my embedded HTML resource includes this absolute path in
> my
> > htmlcode it works fine:
> >
> > < IMG src="file:///C:\Documents and Settings\jim\My
> > Documents\temp\CHtmlApp\Debug\ugly2.bmp"  >
> >
> > But if I put a copy of ugly2.bmp in the same folder with my main exe
> > executable I can't find the right relative URL to use.  For example, why
> > doesn't this work if I execute my application from the same folder that
> > ugly2.bmp resides in:
> >
> > < img src="file:///ugly2.bmp">  I get a broken image for this tag.
>
> That's right.
>
> > What simple thing am I missing?
>
> This is tricky. There is no way at build time that you can tell what the
> runtime path is going to be so you can not hard code this (like above)
into
> your HTML page.
>
> What I do is actually include the image as a resource in my program. For a
> start, reference the image as
> <img src="ugly2.bmp">, compile your program and run it. Now you will be
> looking at the HTML page. Right click on that page and select properties.
> You will see the address is something like
> res://c:\yourpath\prog.exe/142
> where 142 (or whatever) is the ID of your HTML resource.
>
> Now, right click>properties on the broken image and look at it's address.
> This will be
> res://c:\yourpath\prog/ugly2.bmp
>
> With relative addresses the browser pulls the path out of the documents
> location and sticks this in front of the relative path, the relative
address
> is actually referring to a resource in your program because that is where
> the HTML page came from.
>
> Now, to put the image in as a resource.
>
> In your resource window add a new HTML resource. Look at the properties of
> the new resource. Change the filename to "debug/ugly2.bmp"  (because that
is
> where you put the real image, you can change this to res/ugly2.bmp and
move
> your image to the res folder if you wish) and change the ID to
"ugly2.bmp" -
> include the quotation marks in the name. This way you have a resource with
a
> string name, not a number. It is this string name you have used in your
HTML
> to refer to the image.
>
> I just noticed that the image is a BMP. You could make it a JPG to reduce
> its size. The above method also works with JPGs. It even works with CSS
> files. The HTML document will be able to <link> to a CSS file included as
a
> resource in the program.
>
> I suppose you could include the BMP as a Bitmap resource too but my
approach
> keeps all the HTML things in the one place in the resources.
>
> An added advantage is the bundling all the images etc into the on place,
ie
> in your program. You don't have to ship all those files and worry if they
> are in the right folder or not.
>
> Cheers
> Richard.
>
>


0
jnhtx (73)
11/6/2003 6:04:41 PM
"Jim Howard" <jnhtx@spamcop.net> wrote in message
news:eQtg2BJpDHA.360@TK2MSFTNGP12.phx.gbl...
> Thomas & Andrew,
>
> Thanks for your help, I'd forgot about the BASE tag.
>
> I can get the res protocol to work with bitmaps, but if I try to add a gif
> or jpg image as a resource then my Visual Studio .Net 2003 crashes!
> Immediate warp-core breach followed by shutdown!
>
> For the release version of my project I will have to get all the html
> elements in as resources, but for now it would be easier to just read them
> from the file system because the web designers gives me changes everyday,
> and because I am procrastinating trouble-shooting this resource bug in my
> copy Visual Studio.  I'll see if I can change the base tag to have the cwd
> before loading it in my dialog window.
>
> Jim Howard

You could use a reverse approach. In your OnInitDialog handler
Navigate(file://c:/yourpath/page.html), or rather a URL bult from the cwd.
That way the 'base' is correct without any change to the HTML (you don't
want to change the HTML back for the release build).

You could even put the Navigate() inside an #ifdef _DEBUG so a debug build
reads the raw HTML (you web designers can change and test the HTML without
you having to recompile) and a release build locks everything into
resources.

Cheers
Richard.


0
11/6/2003 9:24:28 PM
Reply:

Similar Artilces:

How to Filter cells and save the file with certain criteria?
Hello. I have a Excel file that contains a large list of Tracking Numbers. The tracking numbers are from two sets of order types- Internet orders and Mail Orders. Orders that are from the Internet are matched up with a order number such as "5678". Orders from the mail-order side are designated by initials "MO". So in Excel it'll look something like this: trackingnumber orderid 123365656666 5467 152155896345 5468 123365634567 MO 152134567789 5469 152151234563 MO Is there a way to eliminate the Mail-Order rows and save the Excel file to ...

file send to as attachment outlook 2007
When using in word or excel command "send a copy of the document in an e-mail message as an attachment", outlook creats a new e-mail message with the document attached as it should be done. Then I add text in message body, and send the mail. It arrives only with the attachment. The text in message body disappears. This happens only if I work in outlook chache mode. My os is winXp Pro, and my server is SBS 2003. It used to work correct, until somthing happened. Any idea to solve? Thank you Zipi ...

Can I use a Report expression for queries?
Is it possible to use the following expression that is used in reports on queries? =[Sales]/Sum([Sales])*100 Or some expression to get the result. Thank you. No. In your query, you can refer to text boxes on a form, but not on a report. That's because of the way reports are formatted (sequentially.) Forms have a current record, which identifies which value you want. Reports don't. In the context of a query, there are other ways to get totals, such as DLookup(): http://allenbrowne.com/casu-07.html or a subquery: http://allenbrowne.com/subquery-01.html -- Allen Browne ...

Dynamic List Box using VBA
I wasn't really sure how to phrase this one -- this isn't your Typical Drop-Down List. I have a SELECT statement which queries SQL Server 2005 and displays the data in Excel. Let's say that a database lists products that have been delivered to 4 different cities, on 3 seperate days -- without knowing (in advance) the delivery dates, how could I create an input/drop-down field to allow the user to specify a particular date? I envision something like this: VBA code produces a list box of delivery dates based on a particular product and city. The user selects a delivery date ...

If I accidently replace a saved file can I retrieve the old file?
No. PLEASE write your question in the body of the post and NOT just the subject. Have a look here: http://dts-l.org/goodpost.htm -- Gordon Burgess-Parker Interim Systems and Management Accounting www.gbpcomputing.co.uk "kamabiv" <kamabiv@discussions.microsoft.com> wrote in message news:2A547F5D-AA2C-44D7-AEC7-8961A81AC4E5@microsoft.com... > ...

Best Practises setup with AD or File Server
Hi, We have a scenario where we are retiring out dedicated backup server. Currently we are using Symantec Backup Exec 11d. However, instead of replacing the dedicated server, their is a suggestion that I use existing servers for Backup Exec Are their known issues installing backup exec on a DC which also holds FSMO roles (PDC etc)? The other option is to install backup exec (and tape drive) on a file server which hosts the H and S drives. what do you think? I would use the file server. Presumably it is being accessed during the day when no backups are running. The b...

Help with Html Help in MFC
Hi; I am using Visual Studio .net 2003. I have created a CDhtmldialog. I also created a html help file using Html help workshop. According to some source from web saying that I can call this method: BOOL HtmlHelp( HWND hWndMain, LPCTSTR lpszHelp, UINT uCommand, DWORD dwData ), directly from anywhere in my code. So I include the htmlhelp.h and htmlhelp.lib to the project. But I don't know how to call this method, since there is a another htmlhelp method in Cdialog too: HtmlHelp( DWORD_PTR dwData, UINT nCmd = 0x000F ); Please give me a hand. Thx in advance. Pan Wilson. ...

Using ExecuteQuery to get Listing of Cases
I'm attempting to programatically extract a listing of Cases (similar to the Cases listing in the Case Manager of the CRM app) using the Microsoft.Crm.Platform.Proxy.CRMQuery.ExecuteQuery() method. I can successfully extract Account and Contract info using ExecuteQuery, but I've been unsuccessful in locating a sample of a "QueryXML" string for listing Cases. This is my latest attempt, but I'm not even sure if "Incident" is the correct Entity for what I'm attempting. <fetch mapping='logical'> <entity name='Incident'> <order a...

OT: What tax software is everyone using this year?
TurboTax is too expensive ($40 + electronic filing fees), TaxCut is $30 and included filing fees, TaxAct is $20 for the same thing. Do Money 2006 Deluxe owners get any special offers on Taxcut? -- Aloke ---- to reply by e-mail remove 123 and change invalid to com Excel. I'll probably use the Quicken free efile and then put my own data in the free state online system. "Aloke Prasad" <aprasad123@columbus.rr.invalid> wrote in message news:esnx6uG$FHA.3564@TK2MSFTNGP10.phx.gbl... > TurboTax is too expensive ($40 + electronic filing fees), TaxCut is $30 > and i...

Question regarding the simultaneous use of tape drives
Hi folks, a customer of us wants to use DPM instead of their current Symantec solution. A question I coudn't answer was if they could use their 6-drive tape-robot to for example backing up and restoring at the same time. Thank you in advance for your support! -- Christoph Schmidt || IT Consultant @ TOP TECHNOLOGIES CONSULTING || MCITP EA If there 6 drives available in a library 6 tape related jobs can be run in parallel at any time. Thanks, Praveen D [MSFT] This posting is provided "AS IS" with no warranties, and confers no rights. "Christop...

Using a Button to increment numbers in a database among other things.
I know that it is difficult to assess and solve a problem without being able to look at it physically. Therefore I have included a download link to the database I am working on. http://rapidshare.com/files/41280411/logbook1.accdb.html I have been have some trouble with this database what I would like to do is set up the logdb form to increment the lab number field with the click of a button following a format of the last two digits of the year "-" "0000", otherwise I would just like the field to be entered with a format of "00"-"0000". I tried using a ...

Entourage without HTML-display
Hello NG, I am new to the Mac and in my compay we use office:mac Here's my problem: I compose eMails just using text, I do not use HTML to compose Messages. But if someone writes me a mail that is formatted in HTML Entourage shows the formatted Mail. The only thing that I found so far is to not allow "Complex-HTML" (whatever that means). But even when I turn off complex-HTML Entourage shows HTML. I was used (using Outlook Express 6) to turn off the display of HTML-Mails completly. Even Lotus Notes (v.5.0.9a) shows the eMails without HTML-Formatting. And if I send an eMail f...

Using Emit to Return a Value
Hello: I am trying to write a piece of code that can implement an interface's methods simply by returning a specified value. I am trying to see how Mock libraries are written. For instance, I have a piece of code that looks like this: MockFactory.CreateMock<ISomething>().Setup(something => something.Foo()).Returns("abc"); What I want to be able to do is somehow implement ISomething.Foo so that it returns "abc". However, I am having a hard time figuring out the Emit code for taking an arbitrary object and incorporating it. I've never want...

I have SQL Server installed on my workstation, can I not use MSDE
I have SQL Server Developer Edition on my workstation and I don't really want another instance of SQL on my box. Is there anyway for MS CRM 1.2 to use my existing installation? If you are referring to the MSDE datastore for the SFO client, then no, there isn't. It will install a new instance, but many of the underlying files are shared amongst the instances. Matt Parks ---------------------------------------- ---------------------------------------- On 23 Apr 2004 10:07:41 -0700, ramirez2sma@hotmail.com (Shawn Ramirez) wrote: I have SQL Server Developer Edition on my workstation ...

Starting with a new pst file
Hi, I would like to start with a blank pst file. I want to start again with no contacts, no emails, no appointments. How should I proceed to make this? Thanks for your help, Olivier Olivier Verdin <olivier.verdin@playcorporate.com> wrote: > I would like to start with a blank pst file. I want to start again > with no contacts, no emails, no appointments. Assuming Outlook 2002/2003, since you didn't think it important to mention your Outlook version, click File>New>Outlook Data File, Browse to where you want the new PST (or accept the default), give it a name ...

Intercept file download in IWebBrowser2
I have a MFC application host a webbrowser(IWebBrowser2).Basiclly ,I hope when user click a file download url(href="test.zip"),I can intercept the download message and process it by my own download component instead of IE itself. Is it possible? Any article will be help. Adv tks. http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/overview/downloadmgr.asp "L.J.S" <bconline2002@hotmail.com> д����Ϣ����:Oc7j%23OcAFHA.612@TK2MSFTNGP09.phx.gbl... > I have a MFC application host a webbrowser(IWebBrowser2).Basiclly ,I > hope ...

How can i use DAO Application
Hello freinds I have a software which is made in MFC and connected with MS Access 97 through DAO(Direct Access Object via MS jet Engine). Now i want to use same software for Postgresql and wanted to connected it through ODBC. Problem is that Old software has been developed for DAO,all main file like ,recordset,view doc r made for DAO. If i want to make it in ODBC,my classes like Set ,view Doc and other would be generated for ODBC. I dont know any option to use same software, Should i write whole software from the begining? I need ur help. thanks Sheikh ...

accidently deleted file
Somehow I deleted the file MSMONEY.EXE. It seems I did prior to a restore point on my system. Is there anyway to get it back? Thanks....Inker Reinstall Money from the CD. It won't affect your data - that is kept on the *.mny file. -- Regards Bob Peel, Microsoft MVP - Money Hints/Tips http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny UK Wishes/Suggestions mnyukwsh@microsoft.com "Inker" <anonymous@discussions.microsoft.com> wrote in message news:072c01c3d799$f6d99a90$a501280a@phx.gbl... > Somehow I deleted the file MSMONEY.EXE. It seems I di...

how can I get a publisher file to acrobat reader
I have a Regestration Form created in publisher 2003. When a confrence addtendee signs on to our web site they need to be able to click on a file (acrobat reader) Hopfuly, and download it and print it so they can fill out the form and mail it off. (I say acobat reader because that seems to be the most common way it's done. I dont see an export in publisher or a inport to acrobat. how can i make this happen You will need a third party program to create the pdf file. Adobe Acrobat but it's spendy or a freebee i.e., Primopdf or another commercial program of modest cost, i.e., PDF-XC...

put files together
Hi all, I have in a directory "summary" some 800 files with a number for a name, like 8, 23, 44, 124, 2045 up to somewhere in the 2500's. There is no list of all those file names. Each file is a workbook with only one sheet called "ABCD". I know that the last cell used will be a cell in column H. I also know that the content of that cell will be ==== (4 to 7 times =). Column H will contain text, blanks (empty cells), numbers and other characters (like f.i. =). The number of rows used will be at least 6 and could be as much as 200 or so (25 is typical). I need ...

Hide toolbars when file opens
Hi all, I have created a file for people to use to get quotes. When the file opens, I do not want them to have access to any toolbars. How can I hide these when the file is opened, but only for this file - not any others that the user may subsequently open. All that they may need to do, is print the page out after getting a quote. Many thanks. Rob You can use this in the Thisworkbook module Rob Private Sub Workbook_Activate() Dim bar As CommandBar For Each bar In Application.CommandBars bar.Enabled = False Next End Sub Private Sub Workbook_Deactivate() Dim bar As C...

Problems with Using Word as Email Editor
We use Hummingbird DM 5.1.0.5 for our document and record management. When using this program, it has a problem with Outlook using Word as an Email Editor. When this is turned on, it seems that Outlook opens a different instance of Word. When you try to open or create a word document, you lose the ability to save or print. These features return to normal when you uncheck Word as an Email Editor in Outlook. I have heard that Microsoft was taking this up with Hummingbird to have them fix it. I am just wondering if this was to be resolved, or if it is Hummingbird's problem to ...

Using OUTPUT TO in VBA, then how to modify the XLS from Access?
I'm using the simple "OUTPUTTO" command to send a query over to Excel, however we will have many users and we would like to programmatically add the header rows, date printed, turn on the auto filter and freeze panes, all of which I can do within a Macro in Excel, but how do I call that macro to run from Access and How to run it on the file that they just created? Current Code: DoCmd.OutputTo acOutputQuery, "MainRptWUser", acFormatXLS, , True "ThriftyFinanceGirl" wrote: > I'm using the simple "OUTPUTTO" command to send...

Inability to connect with exchange server using entourage
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Email Client: Exchange I have a 2008 version of entourage that I connect with my exchange server. I added a ms office home edition to my computer, and now I am unable to connect to my server. The error message now says that I must upgrade to a std edition of office in order to connect to an exchange server. If my previous version of entourage would connect and it is still on the computer, why won't it do it now with office installed? Any advice? <br> thanks What version of Microsoft Office 2008 entourage did you down...

How to best imitate using Word macros in Outlook 2007
In my previous Office 2003 setup, I used Word for email editing, allowing me to use Word macros to generate common sections of text in the emails, etc. I see that in Office 2007, the email editor does not support the Word object model. How do I program a macro that would allow me to enter a certain text in the Outlook message under 2007? Thank you. What happens when you try using the Outlook Macro editor? --=20 Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After furious head scratching, AMolotkov asked: | In my previous Office 2003 setup, ...