From: bob on
Hi,

I need to render html (mainly text) on top of a background image in a
CView-derived class. I use IWebBrowser2 control to render the text. I've
read some post related to .NET and it seems like WebBrowser control can be
used to do that. Unfortunately all examples are for WinForms and I'm not
quite sure how to translate them to MFC. They basically set TransparencyKey
and BackgroundColor of a form to the same color and then use WebBrowser
control to render the text.

I tried IViewObject with DVASPECT_TRANSPARENT but the mode was not valid for
IWebBrowser2. I also tried SetBkMode(hdc, TRANSPARENT) before calling
IViewObject::Draw() but it had no affect on the background.

Can someone please point me in the right direction?

Thanks.



From: Pete Delgado on

"bob" <robert(a)robert.org> wrote in message
news:OjqwVCV5KHA.3576(a)TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I need to render html (mainly text) on top of a background image in a
> CView-derived class. I use IWebBrowser2 control to render the text. I've
> read some post related to .NET and it seems like WebBrowser control can be
> used to do that. Unfortunately all examples are for WinForms and I'm not
> quite sure how to translate them to MFC. They basically set
> TransparencyKey and BackgroundColor of a form to the same color and then
> use WebBrowser control to render the text.
>
> I tried IViewObject with DVASPECT_TRANSPARENT but the mode was not valid
> for IWebBrowser2. I also tried SetBkMode(hdc, TRANSPARENT) before calling
> IViewObject::Draw() but it had no affect on the background.
>
> Can someone please point me in the right direction?

It seems to me that since you are already using the browser to render the
text, it would make sense to use browser technologies such as CSS to render
your background image. Simply set the background property of the appropriate
node to an image of your choosing. If you are using HTML embedded as a
resource, the syntax gets a little strange, but it does indeed work.

-Pete


From: bob on

"Pete Delgado" <Peter.Delgado(a)NoSpam.com> wrote in message
news:eL6AQMW5KHA.1924(a)TK2MSFTNGP06.phx.gbl...
>
> "bob" <robert(a)robert.org> wrote in message
> news:OjqwVCV5KHA.3576(a)TK2MSFTNGP05.phx.gbl...
>> Hi,
>>
>> I need to render html (mainly text) on top of a background image in a
>> CView-derived class. I use IWebBrowser2 control to render the text.
>> I've read some post related to .NET and it seems like WebBrowser control
>> can be used to do that. Unfortunately all examples are for WinForms and
>> I'm not quite sure how to translate them to MFC. They basically set
>> TransparencyKey and BackgroundColor of a form to the same color and then
>> use WebBrowser control to render the text.
>>
>> I tried IViewObject with DVASPECT_TRANSPARENT but the mode was not valid
>> for IWebBrowser2. I also tried SetBkMode(hdc, TRANSPARENT) before
>> calling IViewObject::Draw() but it had no affect on the background.
>>
>> Can someone please point me in the right direction?
>
> It seems to me that since you are already using the browser to render the
> text, it would make sense to use browser technologies such as CSS to
> render your background image. Simply set the background property of the
> appropriate node to an image of your choosing. If you are using HTML
> embedded as a resource, the syntax gets a little strange, but it does
> indeed work.
>
> -Pete

Pete,

Thanks for the reply.
I was considering the approach that you are suggesting and it could be that
I'm going to end up with it. Unfortunately it is not going to be as simple
as drawing transparently (which might not be possible afterall). In my app,
I have a background image - which might be either loaded from a file or
generated at runtime - and I need to render html text at a specific location
in a specific rectangular area on the image. I think that in order to use
CSS I would have to 'cut-out' the target rectangle from the background
image, save it in a disk file, set its uri as body background, and then ask
web browser control to render the html. There is quite an overhead (file
io: write/read, encoding image, etc.) on each paragraph of text. The app
receives html text from a remote host at a predefined frequency.

Would you know if there is a way to instruct web browser to get an image
from memory instead of file/internet? I vaguely remember that there is a
way to get images from resource (using res://) but I'm not sure if that can
also be done from memory.

Is there an alternative to using web browser control?

Thanks.



From: Pete Delgado on

"bob" <robert(a)robert.org> wrote in message
news:%23gXeNyW5KHA.5880(a)TK2MSFTNGP04.phx.gbl...
>
> "Pete Delgado" <Peter.Delgado(a)NoSpam.com> wrote in message
> news:eL6AQMW5KHA.1924(a)TK2MSFTNGP06.phx.gbl...
>>
>> "bob" <robert(a)robert.org> wrote in message
>> news:OjqwVCV5KHA.3576(a)TK2MSFTNGP05.phx.gbl...
>>> Hi,
>>>
>>> I need to render html (mainly text) on top of a background image in a
>>> CView-derived class. I use IWebBrowser2 control to render the text.
>>> I've read some post related to .NET and it seems like WebBrowser control
>>> can be used to do that. Unfortunately all examples are for WinForms and
>>> I'm not quite sure how to translate them to MFC. They basically set
>>> TransparencyKey and BackgroundColor of a form to the same color and then
>>> use WebBrowser control to render the text.
>>>
>>> I tried IViewObject with DVASPECT_TRANSPARENT but the mode was not valid
>>> for IWebBrowser2. I also tried SetBkMode(hdc, TRANSPARENT) before
>>> calling IViewObject::Draw() but it had no affect on the background.
>>>
>>> Can someone please point me in the right direction?
>>
>> It seems to me that since you are already using the browser to render the
>> text, it would make sense to use browser technologies such as CSS to
>> render your background image. Simply set the background property of the
>> appropriate node to an image of your choosing. If you are using HTML
>> embedded as a resource, the syntax gets a little strange, but it does
>> indeed work.
>>
>> -Pete
>
> Pete,
>
> Thanks for the reply.
> I was considering the approach that you are suggesting and it could be
> that I'm going to end up with it.

Given the limited amout of information that you have shared, it seems like a
reasonable approach.


>Unfortunately it is not going to be as simple as drawing transparently
>(which might not be possible afterall).

I'm not sure why you think this would be required???

>In my app, I have a background image - which might be either loaded from a
>file or generated at runtime - and I need to render html text at a specific
>location in a specific rectangular area on the image.

You could simply use absolute or percentage-based positioning for your text.
Please see http://www.alistapart.com/ . It is a wonderful resource for
learning some of the finer points of CSS as it relates to design. Also take
a look at http://www.csszengarden.com/ to see what can be done just by
modifying the CSS and underlying resources.

> I think that in order to use CSS I would have to 'cut-out' the target
> rectangle from the background image, save it in a disk file, set its uri
> as body background, and then ask web browser control to render the html.

No. There are variety of ways you can accomplish what you want with CSS and
they are all far more easily done than what you have suggested! :)


>There is quite an overhead (file io: write/read, encoding image, etc.) on
>each paragraph of text. The app receives html text from a remote host at a
>predefined frequency.
>
> Would you know if there is a way to instruct web browser to get an image
> from memory instead of file/internet? I vaguely remember that there is a
> way to get images from resource (using res://) but I'm not sure if that
> can also be done from memory.

The res: protocol is one of the first places to start once you begin coding,
but you really need to get your page design first and ensure that your
dynamic modifications give you the effect that you want.

>
> Is there an alternative to using web browser control?

I'm not sure as I've never needed one. I've written several applications
that used the IE engine to display the interface for the application and
have never needed anything more. YMMV.

-Pete