Page 1 of 1

Editable inline HTML-Code on Windows 7

Posted: Sat May 11, 2024 4:16 pm
by flashbob
"SetGadgetItemText" does not work with WebViewGadget on Windows 7.
A message always appears that the gadget is not initialized.
It would be nice to use inline HTML code on Windows 7 too ...

Re: Inline HTML Code on Windows 7

Posted: Sat May 11, 2024 5:15 pm
by r-i-v-e-r
On Windows, the WebViewGadget depends on the WebView2 runtime being present.

All Windows 11 installations will have this, as will most (up-to-date) Windows 10 installations.

If you're distributing an app targeting Windows versions older than 11, it's safest to run the WebView2 installer as part of your app's own installation process, to ensure presence of this required component.

Please note: Microsoft has discontinued WebView2 support for Windows 7/8/8.1 following WebView2 v109. The Evergreen Bootstrapper should handle this at present, and simply download the appropriate older version on these operating systems, but that support may be subject to change in the future.

Re: Inline HTML Code on Windows 7

Posted: Sat May 11, 2024 5:23 pm
by flashbob
Thanks for the info. I know about the new Windows versions ...
It would have been nice if I didn't have to specify a URL using the old "WebGadget" command, but could stream an inline code..

Re: Inline HTML Code on Windows 7

Posted: Sat May 11, 2024 5:39 pm
by r-i-v-e-r
flashbob wrote: Sat May 11, 2024 5:23 pm It would have been nice if I didn't have to specify a URL using the old "WebGadget" command, but could stream an inline code..
For Windows and the old IE-based WebGadget, you should definitely be able to set HTML via simple string using SetGadgetItemText, e.g.:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, "Inline HTML", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 400, 300, "")

SetGadgetItemText(0, #PB_Web_HtmlCode, "<html><body>Hello World (from inline HTML)</body></html>")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
(Worth noting this also works on macOS, despite the docs describing it as Windows-only)

Re: Inline HTML Code on Windows 7

Posted: Sat May 11, 2024 5:48 pm
by flashbob
Thx for your reply and the sample. You're right. Sample is working. In this case it would be possible, for example, to display an HTML-based email. That would help me for now - I think.

The next step would be an editor that can also be used to create HTML text including formatting (e.g. in response to an email). I know, I'm hoping for too much and I'm spoiled by other programming languages ​​;-)

Re: Inline HTML Code on Windows 7

Posted: Sat May 11, 2024 6:17 pm
by r-i-v-e-r
flashbob wrote: Sat May 11, 2024 5:48 pm The next step would be an editor that can also be used to create HTML text including formatting (e.g. in response to an email). I know, I'm hoping for too much and I'm spoiled by other programming languages ​​;-)
The easiest approach, IMO, would be to ship the WebView2 runtime alongside your app on Windows, so you can escape from Internet Explorer compatibility woes.

Then you could relatively simply embed something like Quill or CKEditor with good cross-platform consistency and pretty much any feature you might want here. Reinventing the wheel would be a major pain, especially when you start to go past basic features (and need to add things like accessibility, IME, BiDi, image, table, etc. support).

If you really wanted to reinvent things while using the IE-based gadget, looking into the contenteditable element attribute may be a good start, e.g.:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, "Inline HTML", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 400, 300, "")

SetGadgetItemText(0, #PB_Web_HtmlCode, "<html><body><div contenteditable>Hello World (from inline HTML)</div></body></html>")

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
(With that, you should be able to edit the inner content and use shortcuts like Ctrl+B, Ctrl+I, Ctrl+U, etc. for bolding, italicising, underlining respectively. It's of course extremely barebones, but if you plug in some UI, event listeners, and deal with some browser-specific weirdness, you can get a decent basic editing experience with most of the nitty-gritty handled by the browser.)

Re: Inline HTML Code on Windows 7

Posted: Mon May 13, 2024 11:58 am
by flashbob
The problem is, that i cannot read the changed html-code if I add some text.

EDIT:
I solved the problem (workaround) using Windows/MAC-API.
See example https://www.purebasic.fr/english/viewtopic.php?t=84271