.MHT files on webgadget

Just starting out? Need help? Post your questions and find answers here.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

.MHT files on webgadget

Post by Christian Uceda »

Hi,

This is a question about the "webgadget"

HTML code can be written on a webgadget using:

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, PeekS(?page))

DataSection
  page:
    IncludeBinary "resources\page.html"
EndDataSection
That works fine and dandy

But if instead a simple html page if I try to use an embedded .mht file (html + images) like:

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, PeekS(?mht))

DataSection
  mht:
    IncludeBinary "resources\pageplusimages.mht"
EndDataSection

What I obtain is the same behaviour as if I had pushed plain html to the webgadget. it doesn't display the data as mht but still tries to render the data as html which means that all the mht headers and graphics are displayed as alphanumeric data inside the webgadget and not as a mht file will do displaying an entire page.

This could be a limitation of the webgadget or me not having a clue as usual.

If anyone could help me I'll be eternally grateful as this will be immensely useful to me.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: .MHT files on webgadget

Post by Christian Uceda »

I made another test;

if I do:

Code: Select all

If OpenWindow(#Window_Preview, 287, 304, int_WindowWidth, int_WindowHeight, "Preview...",  #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_SizeGadget)
    WebGadget(#Web_Control, 10, 10, 640, 310, "mhtml:file://D:\Users\chumboman\Desktop\Test.mht")
It renders the file perfectly.

I guess I can always write the embedded file to the HD and open it this way, but being able to embed the .mht file will always be the best solution as I could pack all I need nicely inside the executable (feature that I love)

So this is a partial solution.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: .MHT files on webgadget

Post by Trond »

I have tried to do this too, without any luck.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: .MHT files on webgadget

Post by Seymour Clufley »

Another solution would be to abandon MHT and use the DataURI scheme instead. If you're interested, this thread may be useful. But beware: IE can't handle DataURI packs of greater than 32kb each, though this will change to 4gb with IE9.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: .MHT files on webgadget

Post by Christian Uceda »

@Seymour Clufley

Thanks, I had no idea that the DataURI scheme existed. Three points for you mate!

The only real problem I see with it is support, it is only supported in IE 8 and onwards, which in my case renders this useless as I need IE 6/7 support.

Also it makes something that is mostly a four step stroke: compose page, display page in browser, save page as HTM, open it in webgadget into a new DataURI codding effort that requires me to write a new parser for my already mime-formatted existing data.

That could be time consuming, there is the IE 6/7 limitation, and the fact that I'm using the demo with code size limits doesn't help either.

So this is a no solution for me at this time...

I'm wondering if the developers could have a look and implement .mht support for the webgadget in a future revision of PB?

I think I will post a wish on the wishlist :)
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: .MHT files on webgadget

Post by Perkin »

I'm using Firefox at mo, so haven't got a mht file to test, but do the mht files have binary data in?
So whe doing the PeekS, it gets to the firts 0 byte, you may have to add a length, or put in into buffer first.

something like...

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, PeekS(?mht,?mhtend-?mht))

DataSection
  mht:
    IncludeBinary "resources\pageplusimages.mht"
  mhtend:
EndDataSection
%101010 = $2A = 42
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Re: .MHT files on webgadget

Post by hallodri »

Create an empty file and call it "mhtTest.rc. Add to that file the following:

Code: Select all

file.mht HTML "pageplusimages.mht"
Compile the script with "\PureBasic\compilers\porc.exe mhtTest.rc".
Porc created file "mhtTest.res. Import this file into your program with:

Code: Select all

Import "mhtTest.res"
EndImport

module.s = ProgramFilename()

If OpenWindow (0, 287, 304, 300, 300, "Preview ...")
  WebGadget (0, 10, 10, 640, 310, "mhtml:res://"+ module +"/file.mht")
  
  Repeat
  Until WaitWindowEvent () = 16
  
EndIf
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: .MHT files on webgadget

Post by Seymour Clufley »

Christian Uceda wrote:Thanks, I had no idea that the DataURI scheme existed. Three points for you mate!
Yes, it exists and it's a lot better than MHT, because all the browsers can read it!
The only real problem I see with it is support, it is only supported in IE 8 and onwards, which in my case renders this useless as I need IE 6/7 support.
Perhaps you could use the Mozilla version of the webgadget? And wouldn't that mean cross-platform support for your program?
Also it makes something that is mostly a four step stroke: compose page, display page in browser, save page as HTM, open it in webgadget into a new DataURI codding effort that requires me to write a new parser for my already mime-formatted existing data.
If I'm understanding the situation correctly, it's a 3-step stroke: compose page, internalise it (using my code), then display it in the webgadget.
That could be time consuming, there is the IE 6/7 limitation, and the fact that I'm using the demo with code size limits doesn't help either.
1. I don't see how it would be time-consuming. The code I linked to does everything for you. Just give it the source HTML file, and the destination name, and it'll do it.
2. IE 6/7... can I ask why you need compatibility with those versions of IE?
3. Demo limitations... easy: buy PB! Honestly, you won't regret it.
So this is a no solution for me at this time...
From where I'm standing it looks like the only problem is IE 6/7 compatibility.
I'm wondering if the developers could have a look and implement .mht support for the webgadget in a future revision of PB?
I have successfully opened MHTs in the webgadget, but not for a while since I discovered DataURI. It may be that a newer version of PB has introduced a problem with MHTs, but I doubt it as surely things hinge on the ATL dll from Microsoft, not anything at the PB end?
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: .MHT files on webgadget

Post by Christian Uceda »

hallodri wrote:Create an empty file and call it "mhtTest.rc. Add to that file the following:

Code: Select all

file.mht HTML "pageplusimages.mht"
Compile the script with "\PureBasic\compilers\porc.exe mhtTest.rc".
Porc created file "mhtTest.res. Import this file into your program with:

Code: Select all

Import "mhtTest.res"
EndImport

module.s = ProgramFilename()

If OpenWindow (0, 287, 304, 300, 300, "Preview ...")
  WebGadget (0, 10, 10, 640, 310, "mhtml:res://"+ module +"/file.mht")
  
  Repeat
  Until WaitWindowEvent () = 16
  
EndIf
@hallodri

This is quite good, many thanks.

I do not want to be picky, but it has a disadvantage compared to having a datasection:

When using a regular PB include in a datasection you can peeks() it to a regular string, perform changes (IE: replacements) and then feed the changed data to the webgadget, all easily with standard PB commands. This approach works well with plain HTML files. using

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, peeks(?html)
As per using resources as you point out, it works great until you have to read, modify and update the resource, from here it is all WIN32 API which will require time for me to do some MSDN reading and experiment with.

So for now this method is ok only if the pages to be included are static.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: .MHT files on webgadget

Post by Christian Uceda »

@Seymour Clufley
Perhaps you could use the Mozilla version of the webgadget? And wouldn't that mean cross-platform support for your program?
Nope, the app is IE only for now, has to do with IE rendering engine and Outlook.
If I'm understanding the situation correctly, it's a 3-step stroke: compose page, internalise it (using my code), then display it in the webgadget.
No offence, but before I use someone else's code I have to review and understand it.
2. IE 6/7... can I ask why you need compatibility with those versions of IE?
Do not ask, the world is an ugly place full of incompatible software.
3. Demo limitations... easy: buy PB! Honestly, you won't regret it.
I know, I want to, I plan to... It is just I do not have the €€€ right now, maybe on a week or two.
From where I'm standing it looks like the only problem is IE 6/7 compatibility.
Agreed
I have successfully opened MHTs in the webgadget, but not for a while since I discovered DataURI. It may be that a newer version of PB has introduced a problem with MHTs, but I doubt it as surely things hinge on the ATL dll from Microsoft, not anything at the PB end?
Yes, as I mentioned before if I use a standard file uri with a .mht file ie:

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, "mhtml://file://c:\test.mht" )
it works like a champion, when it doesn't work is when using the data inline as:

Code: Select all

SetGadgetItemText(#Web_Control, #PB_Web_HtmlCode, peeks(?mht))
I suspect that it could be a matter of passing some structure to the activex under the hood to interpret the inline code as mhtml and not html.
Christian Uceda
User
User
Posts: 67
Joined: Thu Jul 29, 2010 10:53 am

Re: .MHT files on webgadget

Post by Christian Uceda »

Hi all,

I have been spending some time on the MSDN this weekend, pretty much there is no obvious way to use MHT files other than saving the file somewhere on the HD and invoke it from the webgadget as "mhtml:file://<path>\<filename.mht>"

This is a limitation of the underlying ActiveX component in IE, (the Unicode problems some other people mention in other posts in the forum are also the ActiveX wrongoings)

I do not see how the PB developers could improve the webgadget situation unless they roll out their own embedded browser implementation as a PB lib... (maybe for Purebasic v10?, hey the geckko code is LGPL licensed, one can dream, can't I? :mrgreen: )

So to close this thread for posterity (at least for now! :lol: )

So the working options are:

1) Save .mht files to the hard drive and load them afterwards. This works in IE6/7/8 and allow you to change anything in the page as you see fit.

2) Use embedded .html files on datasections. This works on IE6/7/8 and allows you to change anything in the page as you see fit. However no images can be used.

3) Use embedded .html files on datasections containing embedded images in DataURI (Base64) format. This only works on IE 8/9? allows you to change the HTML code in memory as you see fit, but the embedded DataURI elements can not exceed 32kb.

4) Use embedded .mht files in resource format, use the res protocol: "mhtml:res://"+<exename>+"/file.mht" on the web gadget to load it. This format support images and works in IE6/7/8 but doesn't allow you to change the embedded html code in memory, (I do not know how to), so this is good only for static content.
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: .MHT files on webgadget

Post by Seymour Clufley »

Option #3: the 32kb limit only applies to IE, and will be done away with when IE9 comes out (the limit then will be, IIRC, 4gb). All other browsers will read DataURI aswell, although I'm not sure of their individual maximum sizes for a DataURI block.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply