FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Size matching
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Size matching
Posted: Wed Apr 15, 2026 12:38 PM

Hi,

The WebView is located on the dialog. When you change the size of the dialog with the mouse, the size of the WebView should change accordingly. However, the oDlg:bResized code block is not working correctly. What am I wrong about?

DEFINE DIALOG oDlg FROM 0,0 TO 600,600 TITLE "My dialog" PIXEL TRUEPIXEL RESIZABLE ;
STYLE nOR(WS_THICKFRAME, WS_CAPTION)

ACTIVATE DIALOG oDlg NOWAIT

oDlg:bResized:={||SetWindowPos(oWeb:GetWindow(), 0, 0, 0, oDlg:nWidth, ;
oDlg:nHeight-GetSysMetrics(SM_CYCAPTION)-GetSysMetrics(SM_CYBORDER)*2)}

oWeb:=TWebView():New(0, oDlg:hWnd)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size matching
Posted: Wed Apr 15, 2026 03:50 PM

Please try it this way:

  #include "FiveWin.ch"

  function Main()

 local oDlg, oWeb

 DEFINE DIALOG oDlg FROM 0, 0 TO 600, 600 TITLE "My dialog" ;
    PIXEL TRUEPIXEL RESIZABLE

 oDlg:bStart := {|| oWeb := TWebView():New( 0, oDlg:hWnd ), ;
                    oWeb:SetParent( oDlg ), ;
                    oWeb:Navigate( "https://www.fivetechsoft.com" ) }

 oDlg:bResized := {|| If( oWeb != nil, ;
    oWeb:SetSize( oDlg:nClientWidth, oDlg:nClientHeight ), ) }

 ACTIVATE DIALOG oDlg ;
    VALID ( oWeb:End(), .T. )

  return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Size matching
Posted: Thu Apr 16, 2026 09:44 AM

Thank you. The method :setSize has a third parameter - nHint. What is it?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size matching
Posted: Thu Apr 16, 2026 09:58 AM

Dear Yuri,

The third parameter nHints in TWebView:SetSize() is a window size hint that controls how the specified width and height are interpreted. It is defined at line 56 of the class:

Code (prg): Select all Collapse
METHOD SetSize( nWidth, nHeight, nHints ) INLINE WebView_SetSize( ::hWebView, nWidth, nHeight, nHints )
``` 

The possible values are defined as constants at the top of the same file:

| Constant | Value | Meaning |
|---|---|---|
| `WEBVIEW_HINT_NONE` | 0 | Width and height are the **default size** |
| `WEBVIEW_HINT_MIN` | 1 | Width and height are **minimum bounds** |
| `WEBVIEW_HINT_MAX` | 2 | Width and height are **maximum bounds** |
| `WEBVIEW_HINT_FIXED` | 3 | Window size **cannot be changed** by the user | [0-cite-1](#0-cite-1) 

These constants come from the underlying webview library API (`webview_set_size` in `webview.h`): [0-cite-2](#0-cite-2) 

On the Win32 backend, the implementation uses these hints to set window styles and geometry constraints โ€” for example, `WEBVIEW_HINT_MIN` sets the minimum window size, `WEBVIEW_HINT_MAX` sets the maximum, and `WEBVIEW_HINT_FIXED` removes the `WS_THICKFRAME` style to prevent resizing: 

**Important note:** This third parameter only applies to `TWebView`, not `TWebView2`. The `TWebView2:SetSize()` method only accepts two parameters (`nWidth, nHeight`) and directly calls `pController->put_Bounds()` without any hint logic. 

In your code, since you're using `TWebView` and embedding it as a child of a dialog, you're calling `oWeb:SetSize( oDlg:nClientWidth, oDlg:nClientHeight )` without the third parameter, which defaults to `WEBVIEW_HINT_NONE` (0) โ€” meaning the values are treated as the default/current size. That's the correct usage for a resize handler.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Size matching
Posted: Thu Apr 16, 2026 11:01 AM

It didn't work out. The oWeb:setSize() method, for some reason, changes the size of the owner's window, bat not the WebView. :cry:

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Size matching
Posted: Thu Apr 16, 2026 11:47 AM

The problem is that TWebView:SetSize() is designed for standalone webview windows, not for embedded child windows. Looking at the C++ implementation in webview.h, set_size() calls SetWindowPos on m_window (the webview's own window) and uses AdjustWindowRect with WS_OVERLAPPEDWINDOW โ€” which adds frame/border adjustments inappropriate for a child window. It also modifies the window style via SetWindowLong, which interferes with the WS_CHILD style you set via SetParent(). 1-cite-0

The existing samples that use TWebView with SetParent() do not use SetSize() for resizing. Instead, they call SetWindowPos directly on the webview's window handle: 1-cite-1 1-cite-2

Solution โ€” use SetWindowPos directly:

Code (prg): Select all Collapse
oDlg:bResized := {|| If( oWeb != nil, ;
   SetWindowPos( oWeb:GetWindow(), 0, 0, 0, oDlg:nClientWidth, oDlg:nClientHeight, 4 ), ) }

The 4 is SWP_NOZORDER. This resizes the webview's window directly without the AdjustWindowRect overhead that SetSize() applies.

Alternative โ€” switch to TWebView2:

TWebView2:SetSize() does not have this problem because it calls pController->put_Bounds(rect) which correctly resizes the browser control within the host window: 1-cite-3

The TWebView2 samples use SetSize() for resize handling without issues: 1-cite-4

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion