dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Positioning a WebBrowser control

  1. #1
    Join Date
    Jul 2008
    Posts
    15

    Positioning a WebBrowser control

    Hello all:

    I need to include a WebBrowser control in a window -most exactly in a dialog box-. I'm using Visual C++ and the Windows API "bareback", I mean without MFC or ATL.

    I managed to include it in a way that addresses the entire client area of the dialog box, but the problem is that I need that the Web control address only certain position, because the rest of the client area is occupied by the usual buttons, texts and other controls that are usually included in the dialog boxes.

    I tried two ways of solution:

    1 .- The control stems directly from the dialog box (say dialogHwnd) and use the methods

    put_Left()
    put_Top()
    put_Width()
    put_Height()

    of the IWebBrowser2 interface to position de control, but without result, since the control does not change position (continues to occupy the entire space of the container).

    2 .- I tried to derive the control of an child window defined within the dialog box (say of childWindowHwnd). The problem is that the control -the Web page you should see- does not appear inside of the window (or elsewhere).

    Of course, any light or guidance on how to do it, or on what I'm wrong, will be largely rewarded :-)

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Re: Positioning a WebBrowser control

    Once your control lies in a dialog (which I presume is based on a dialog template resource) the most handy method is to set it's position/size from scratch in the resource editor.

    However, if you realy need to move/resize it at run-time, then you can use MoveWindow or SetWindowPos. For that, you have to do the following steps:
    1. Using control's window handle get it's rectangle by a call of GetWindowRect; aso may be possible to need the window rectangle of other controls to further calculate your control's new position/size.
    2. Using parent window (dialog) handle call ScreenToClient to transform control's screen coordinates in coordinates relative to parent client area.
    3. Calculate new control's coordinates (or rectangle) as you need.
    4. Using the control's window handle call MoveWindow or SetWindowPos
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Jul 2008
    Posts
    15

    Re: Positioning a WebBrowser control

    ovidiucucu: thanks for your reply

    My problem is not how to position or resize a child window in a dialog box. I believe is my lack of a good understand of the interaction between the WebBrowser control itself and its window container. At this moment I'm trying to understand just an example of this site: the Mausau's Web Custom Control ( http://www.codeguru.com/cpp/controls...cle.php/c5201/ )

    Unfortunately it uses a rather advanced OOP technique and the logic is a hard to understand.

  4. #4
    Join Date
    Jan 2008
    Posts
    178

    Re: Positioning a WebBrowser control

    Just use the native OCX hosting control and position this one.

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Re: Positioning a WebBrowser control

    Quote Originally Posted by fred100 View Post
    Just use the native OCX hosting control and position this one.
    Native of who?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)