Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Resize WebBrowser control ...

238 views
Skip to first unread message

Michael Tissington

unread,
Oct 27, 2008, 11:16:08 PM10/27/08
to
I have a CDialog which has a single WebBrowser control.

After loading navigating to a url how can I determine the required size of
the browser to show the page without any scroll bars.

I'd then like to resize the Dialog and WebBrowser control to show the
complete page.

Tom Serface

unread,
Oct 28, 2008, 9:51:33 AM10/28/08
to
I think this may be difficult. Many, maybe most, web pages are set up to
reposition text and graphics based on the current browser window. So it
will be difficult to tell how large the screen would need to be or how small
it could be before the elements stop repositioning.

I guess you could look through the HTML for table or div specifiers and try
to determine the widest point, but that would be hit and miss in my opinion.
You will also not like be able to do anything vertically since many pages
can go on for several screens.

Are you using a specific page or list of pages that you know something
about?

Tom

"Michael Tissington" <mic...@nospam.newsgroups.com> wrote in message
news:%23sw3GuK...@TK2MSFTNGP02.phx.gbl...

David Ching

unread,
Oct 28, 2008, 10:26:33 AM10/28/08
to
"Michael Tissington" <mic...@nospam.newsgroups.com> wrote in message
news:%23sw3GuK...@TK2MSFTNGP02.phx.gbl...

The following code is from a CDHTMLDialog derived class, but your WebBrowser
control also has an OnDocumentComplete() method. It uses the WIDTH and
HEIGHT attributes in the <body> of the HTML. I don't know if you can ensure
those are properly set, but if so:

void CDHtmlPopupDlg::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
// defaults to show a small window, but it probably won't be the right
size
long width = 320;
long height = 240;

// Read document's body for WIDTH and HEIGHT
CComQIPtr<IWebBrowser2> spWebBrowser2(pDisp);
if ( spWebBrowser2 )
{
CComPtr<IDispatch> spDocDispatch;
spWebBrowser2->get_Document(&spDocDispatch);
CComQIPtr<IHTMLDocument2> spDoc(spDocDispatch);
if ( spDoc )
{
// Find body.style.width and body.style.height
CComPtr<IHTMLElement> spBodyElement;
spDoc->get_body(&spBodyElement);
if ( spBodyElement )
{
// Get Body style
CComPtr<IHTMLStyle> spBodyStyle;
spBodyElement->get_style(&spBodyStyle);
if ( spBodyStyle )
{
// Finally get dimensions - both will be 0 the first
time through
spBodyStyle->get_pixelWidth (&width);
spBodyStyle->get_pixelHeight(&height);
}
}
}

// Resize dialog and web browser control based on width and height
}

-- David

Tom Serface

unread,
Oct 28, 2008, 11:17:52 AM10/28/08
to
Hi David,

Just curious, is this something that gets set automatically somewhere?
Aside from perhaps as part of a style tag I've never seen width or height
as part of the HTML body tag options. How is this calculated. I could
possibly use this if I understand what's going on .

Tom

"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:4B1216F6-4355-48C4...@microsoft.com...

Ajay Kalra

unread,
Oct 28, 2008, 1:44:08 PM10/28/08
to
On Oct 27, 11:16 pm, "Michael Tissington"

Use SetWindowPos to resize the dialog to whatever size you want. In
its OnSize handler, you can size the WebBrowserControl to the desired
size.

--
Ajay

David Ching

unread,
Oct 28, 2008, 1:59:38 PM10/28/08
to
"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:6AFA19B1-0EB1-4B27...@microsoft.com...

> Hi David,
>
> Just curious, is this something that gets set automatically somewhere?
> Aside from perhaps as part of a style tag I've never seen width or height
> as part of the HTML body tag options. How is this calculated. I could
> possibly use this if I understand what's going on .
>

I think you can specify in your HTML :

<body width="640" height="320">

and that is what I am accessing via the browser DOM.


-- David

Tom Serface

unread,
Oct 29, 2008, 12:46:55 AM10/29/08
to
OK, I didn't know height and width were tags in the body tag. If that's
true it would be handy, but I've never seen pages with that defined (or I
missed them). I know you can set the style in the body tag and in there you
have a number of options. Maybe people are doing that (I've just never
done it, but that does prove anything).

Tom

"David Ching" <d...@remove-this.dcsoft.com> wrote in message

news:AD0C21A8-77AA-4445...@microsoft.com...

David Ching

unread,
Oct 29, 2008, 1:33:46 AM10/29/08
to
"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:99D109FC-4782-460F...@microsoft.com...

> OK, I didn't know height and width were tags in the body tag. If that's
> true it would be handy, but I've never seen pages with that defined (or I
> missed them). I know you can set the style in the body tag and in there
> you have a number of options. Maybe people are doing that (I've just
> never done it, but that does prove anything).
>

Actually, the syntax is:

<body style="width: 600; height: 577">


Mostly I am showing HTML pages which I control (or can coordinate with the
web server people), so it's no problem to get things like this put in.

-- David

Tom Serface

unread,
Oct 29, 2008, 2:20:56 PM10/29/08
to
Yes, that makes more sense. Thanks.

Tom

"David Ching" <d...@remove-this.dcsoft.com> wrote in message

news:56704633-DFB2-4391...@microsoft.com...

0 new messages