Resize WebBrowser control ...

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. 

0
michael876 (39)
10/28/2008 3:16:08 AM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
505 Views

Similar Articles

[PageSpeed] 30

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" <michael@nospam.newsgroups.com> wrote in message 
news:%23sw3GuKOJHA.1896@TK2MSFTNGP02.phx.gbl...
>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. 

0
tom.nospam (3240)
10/28/2008 1:51:33 PM
"Michael Tissington" <michael@nospam.newsgroups.com> wrote in message 
news:%23sw3GuKOJHA.1896@TK2MSFTNGP02.phx.gbl...
>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.

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 

0
dc2983 (3206)
10/28/2008 2:26:33 PM
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" <dc@remove-this.dcsoft.com> wrote in message 
news:4B1216F6-4355-48C4-B101-5F239ED683B9@microsoft.com...
> "Michael Tissington" <michael@nospam.newsgroups.com> wrote in message 
> news:%23sw3GuKOJHA.1896@TK2MSFTNGP02.phx.gbl...
>>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.
>
> 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 

0
tom.nospam (3240)
10/28/2008 3:17:52 PM
On Oct 27, 11:16=A0pm, "Michael Tissington"
<mich...@nospam.newsgroups.com> wrote:
> I have a CDialog which has a single WebBrowser control.
>
> After loading navigating to a url how can I determine the required size o=
f
> 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.

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
0
ajaykalra (6841)
10/28/2008 5:44:08 PM
"Tom Serface" <tom.nospam@camaswood.com> wrote in message 
news:6AFA19B1-0EB1-4B27-A02A-38BD5918012C@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 

0
dc2983 (3206)
10/28/2008 5:59:38 PM
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" <dc@remove-this.dcsoft.com> wrote in message 
news:AD0C21A8-77AA-4445-ACC4-5D7302DF7D61@microsoft.com...
> "Tom Serface" <tom.nospam@camaswood.com> wrote in message 
> news:6AFA19B1-0EB1-4B27-A02A-38BD5918012C@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 

0
tom.nospam (3240)
10/29/2008 4:46:55 AM
"Tom Serface" <tom.nospam@camaswood.com> wrote in message 
news:99D109FC-4782-460F-88AF-736B8C7F1FF2@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 

0
dc2983 (3206)
10/29/2008 5:33:46 AM
Yes, that makes more sense.  Thanks.

Tom

"David Ching" <dc@remove-this.dcsoft.com> wrote in message 
news:56704633-DFB2-4391-BDCF-EA51625498C6@microsoft.com...
> "Tom Serface" <tom.nospam@camaswood.com> wrote in message 
> news:99D109FC-4782-460F-88AF-736B8C7F1FF2@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 

0
tom.nospam (3240)
10/29/2008 6:20:56 PM
Reply:

Similar Artilces:

Can I control linked cell property value in a copied ActiveX contr
I need to copy an ActiveX control approximately 200 times in 1 worksheet (not form). The LinkedCell property value does not change when I copy and paste - so I end up with 200 controls pointing to the same cell. This is a pain to edit. The control is invoked with the following syntax =EMBED("Forms.ScrollBar.1",""). It "smells like I should be able to expose that cell address so a copy might work but I can't find any reference to the EMBED on line or in 6 books. Any help or redirection would be much appreciated. ...

problem with resizing
Hi! I'm writing a MDI application. Child window is splitted in three panes. In the one pane I've got a FormView with some buttons. How to do, that this FormView was in the center of a pane (even during resizing )? And the second problem, how to do, that during resizing, splitters dividing window were always in the same places? Please, help me. I would be appreciate. bart ...

Controlling display names
I'll try asking this again a different way: Is there a way to have a display name for Exchange 2003 in the global address list appear differently than the display name when sent outside my organization via email? Example: in the GAL, I want to have John Smith, but for email sent outside the organization, we just want email to come from John in the email header: From: "John" <johnsemailaddress@mycompany.com> This problem is all about the display name, nothing to do with the actual e-mail address. ? In news:Xns9751A534BB07vo243hotmailcom@207.46.248.16, Vo <vo24...

ActiveX Controls
Hy, I use MS Excel 2003, and recently, I cannot insert ActiveX controls, such as button, combobox, aso... on an Excel sheet. As soon as I selection tools from the toolbox and click on the sheet, Excel hangs. Would somebody have a solution or knows the reason of this phenomenon? Thank you for your assistance Charly A complete guess... Close excel and clean up your windows Temp folder. Windows start button|Run type: %temp% and hit enter Delete as much as you can and then back to excel to test it. Charly wrote: > > Hy, > > I use MS Excel 2003, and recently, I cannot insert...

resizing problems
I am using OpenGL in my MFC app. The problem is when I resize the window from the left or top border the whole scene of my OpenGL moves even before my OnPaint event handler is called and when my OnPaint is called after this it repaints the scene so this produces a flicker. If, however I resize the window from the right or bottom border this problem doen't occur. Can anybody please tell me what is happening? Thank you ...

a control that does console i/o
Hi, does anybody know any windows control that can programmatically prompt and take input from user? What I need is something close enough so I can customize with minimal effort. Thanks, Vincent A control? Every process can have only one Console window. So, you'd almost never find a control having its own Console window. However if your Application does an "AllocConsole" you can get your own Console window and any Control that you write can do IO through this console window; but be aware that mixing UI with console is considered ugly. -vJ "Vincent Yu" <anon...

Controling dot-matrix printer
Hi all, I want to use dot-matrix printer to print data one line each times. Does anyone know any reference about it? Any comment is welcome. Thanks in advanced. Best regards, Justin In the general case, you can simply print to the Windows device context for any printer supported by Windows and it should work. Did you try this? What is wrong with it? If you need to programmatically control a specific printer--I can't image why you'd need to do this--you need to get a reference for *that* printer so you know which codes have what affect. -- Jonathan Wood SoftCircuits ...

Bitmap resize on same DC
I am a little be confused! I have a custom control with a bitmap inside I create the bitmap with this code ************************************************* CClientDC dc(this) ; if (m_dcGrid.GetSafeHdc() == NULL) { m_dcGrid.CreateCompatibleDC(&dc) ; m_bitmapGrid.CreateCompatibleBitmap(&dc, m_nClientWidth,m_nClientHeight) ; m_pbitmapOldGrid = m_dcGrid.SelectObject(&m_bitmapGrid) ; } ************************************************ and in OnPaint i have: ************************************************ CPaintDC dc(this) ; // device context for painting CDC memDC ; CBit...

Control the Quantity being Received
Customer suggested that there should be an option in Purchase Order Processing to stop receiving a quantity greater than the P.O. order quantity. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/e...

CStatic derived dialog and auto-resize
Hi, I would like to add auto-resizing feature to my Cstatic derived control. I mean when I load a bitmap I would like to adjust size dynamically. I tried to SendMessage WM_SIZE but it doesn't work. >I would like to add auto-resizing feature to my Cstatic derived control. I >mean when I load a bitmap I would like to adjust size >dynamically. >I tried to SendMessage WM_SIZE but it doesn't work. You can resize a window by using the SetWindowPos or MoveWindow APIs. Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq ...

Dialog Box: Which control gains the focus?
Hello everybody! Sample: extern CMyDialog* pDial; (initialisation) .... (entering datas) pDial->ShowWindow(SW_HIDE); (other processing) pDial-ShowWindow(SW_SHOW); pDial->SetFocus(); Which control has the focus? In a project developped with Visual Cpp version 5 & 6, it's the last control having the focus when dialog was visible. An other project developped with Visual Studio .Net, it's always the first control (first in tabulation order) which has the focus. With or without MFC, the behaviour is the same. Who knows the reason why? What is exactly behind pDial->S...

Need the check state of list control item as user checks/unchecks it
I have CListCtrl object. As soon as the check box is selected i need to display some message box. If NM_CLICK message is handled and GetCheck() is used it is too early and will not get the proper state of the item selected . Please let me if anybody knows. Hook LVN_ITEMCHANGED a sample code may look like this void CCustomListCtrlDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; BOOL bTest = m_Ctrl.GetCheck(pNMListView->iItem); *pResult = 0; } Regards, -Boben. "Rajani" <anonymous@discussions.microsoft.com>...

auto resize text without resizing cell in excel
format|cells|alignment tab|check "shrink to fit" Ferd wrote: -- Dave Peterson ...

Controlling Cell/Cursor Placement
Greetings all: I am wondering if there is a way to controll the way excel moves from one cell to another cell after you hit the "enter" or "tab" keys? I created a spreadsheet for my employees, they will start off in one specific cell, then they must go in a sequence of other cells on the sheet entering in various information. I would like the spreadsheet to automatically move to the next cell where they need to go. Is this possilbe? Thanks for your help! One way is to use a "named range". Check out this old post: http://tinyurl.com/39vzv -- HTH, R...

Drop Down box resizing on open
I'm using Excel 2000 and have created a workbook with lots of drop down boxes which keep resizing when I open up the sheet. I have the drop downs in column B, with linked cells in column A with IF's in column D based on column's A values. I have macro's running in the background autofitting column D (the IF variables can give results which range from 1-10 lines taken from another sheet). The drop down boxes have been positioned in the lower half of the cells so the cell contents can be read. I have made sure that each drop down box has 'move but dont size with cells&...

How to resize a CTreeCtl when the dialog window is resized
Hello, Is there any documentation on how to do this? Or does anyone have any suggestions? Thanks, Linda >-----Original Message----- >Hello, > >Is there any documentation on how to do this? Or does anyone have any >suggestions? > >Thanks, >Linda > >. You can handle the message WM_SIZE of dialog to change the size of CTreeCtrl. Use message mapping. Then call the MoveWindow function to change the size: CTreeCtrl::MoveWindow(x, y, width, height) >-----Original Message----- >Hello, > >Is there any documentation on how to do this? Or does anyo...

Resizing trendline title in legend
G'day, Im having trouble resizing the legend from 3 lines to 1. I have used a scatter chart and then Add Trendline>Moving average. The legend that is auto-generated is "10 per. Mov. Avg. (PROJECTED INITIAL YELD" The title is broken up into 3 lines as above, and no matter how much I resize or how much big I make the legend area or how small the font, it INSISTS on using 3 lines. Because the title is auto-generated (10 per. Mov. Avg.....) there is nowhere where I can actually edit the title eg make it shorter, or remove the alt-enter line breaks (if thats what it is). The ...

Controls on other form
I am trying to code on when a button is being click from other form, a combo box text from other form will check to "Close" where the job= 11111 is this the right way to code? Dim str1 As String Dim str2 As String str1 = Forms![WIPRaw]!txtJob.Text str2 = Me.txtJobOld If str2 = str1 Then Forms![WIPRaw]!combo1.Text = "Close" End If Simply can't get it works... -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200706/1 Remove the .Text at the end. The control must have focus in order to refer to the Text p...

how to control size of a bound object
Please help me...... I need to generate a report with various figures that are contained in a bound table field. When the report is generated, I cannot get the shrink, grow command to work for a bound object, only for a text box. Does anyone know how to get around this, via macros or code? I would appreciate your help so very much. auntboo, I'm confoosed... is the field value a numeric or text? I assume by "various figures" that you mean numeric... You wrote... >I cannot get the shrink, grow command to work for a bound object, >only for a text box. If t...

InsertItem fails on ActiveX control subclassing listview
I have successfully created an ActiveX control (using MFC COleControl) that is based on (subclasses) the list-view control (SysListView32). The control appears, and in report mode, it successfully displays the columns I have added to it -- InsertColumn (LVM_INSERTCOLUMN) succeeds. A call to DeleteAllItems (LVM_DELETEALLITEMS message) succeeds (but there are no items yet). However, when I call InsertItem (LVM_INSERTITEM) with a valid LVITEM structure being passed, it returns -1! Also, the portion of the control where items would appear is not colored white, as I would expect. I have...

Resizable CPropertySheet In Resizable CFormView
I'm trying to build an MFC-based SDI app that has a look somewhat like that shown by Joseph M. Newcomer at http://www.flounder.com/proppage.gif in his page "The Graphical Developer Interface" ( http://www.flounder.com/gdi.htm ). The property sheet and the pages in it should be resizable, and it's the resizing that I'm having problems with. I selected a CFormView-based application and put a CPropertySheet in it, with appropriate pages. (I selected a CFormView over a dialog-based app because I wanted the framework's support for all the things you don't get with a...

resize
trying to resize a template from 1 to 1 to 1 to 10. it has a frame around the page and every time i resize, it resizes the frame to make it really small in the corner. is there a way this can be locked? thanku sounds like the frame may be associated with a background page, that often happens with some materials that I put together. Al "Harry Archer" <ha092003@removehotmail.com> wrote in message news:eDkN9%23pqDHA.392@TK2MSFTNGP11.phx.gbl... > trying to resize a template from 1 to 1 to 1 to 10. it has a frame around > the page and every time i resize, it resizes the f...

Can I automatically resize all controls in a Dialog without adding user codes
Dear All, Can I design a Dialog that automatically resizes all controls when the Dialog is being resized? Many thanks, Yes. You can resize or move them as you wish by handling OnSize of the dialog. SetWindowPos can be used to change the size and/or position. Here is a helpful link: http://www.codeproject.com/dialog/resizabledialog.asp --- Ajay No. You must explicitly take action on the OnSize handler to resize them. Sometimes, there are packages called "geometry managers" that make this fairly straightforward (check www.codeproject.com and www.codeguru.com for examples)...

Creating Run Time Controls
I am creating a checkbox at run time, as shown below. Spy tells me that the checkbox is receiving messages, but it doen't respond to snaps by checking and un-checking, nor does it receive BM_SETCHEck messages like the check boxes I create from a Dialog resource. How can I get these run time check boxes to respond? CButton *m_mycheckbox; // Member of CMyDialog BOOL CMyDialog::OnInitDialog() { *m_mycheckbox; = new CButton; *m_mycheckbox; ->Create( _T("My Checkbox Name"), WS_CHILD|WS_VISIBLE|SS_LEFT|BS_CHECKBOX|BS_LEFTTEXT...

Access 2007: Resizing one textbox resizes all
Created a new form, all textboxes were auto-created from the Data Source table. Now, I want to resize some of the textboxes to smaller and larger. When I give focus to one textbox and drag to resize, all textboxes automatically get focus and resize as well. Or, when I change the textbox width in the Properties for one text box, all of them change. Never saw this behavior in Access 2003. A2007 has a new feature for linking all the controls. Sometimes a very handy feature, sometimes not so handy. To remove the linking, select one of the linked controls, go to the arrange m...