FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Size matching
Posts: 1396
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: 44229
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: 1396
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: 44229
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: 1396
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: 44229
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
Posts: 8559
Joined: Tue Dec 20, 2005 07:36 PM

Re: Size matching

Posted: Tue May 12, 2026 03:40 PM

Maestro Antônio, en el ejemplo que publicó, ¿cómo desactivo el DIÁLOGO usando el botón?

// C:\FWH2603\SAMPLES\ SIZEMATH.PRG

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL oDlg, oWeb, oBar, oFont, oBtn
   LOCAL cVer := "Exit"

   DEFINE FONT  oFont  NAME "MS SANS SERIF"  SIZE 0,-12

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

   // No funciona?
   // oDlg:lHelpIcon := .T.

   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 ), ) }

   // DEFINE BUTTONBAR oBar OF oDlg _3D BOTTOM // 2007

   // No funciona
   // DEFINE BUTTON OF oBar FILE "..\bitmaps\16x16\exit.bmp" ;
   //   ACTION( oWeb:End(), oDlg:End())

   // No funciona
   @ 605, 250 BTNBMP oBtn OF oDlg SIZE 50 , 30 PROMPT cVer FONT oFont CENTER ;
      PIXEL ACTION( oWeb:End(), oDlg:End(), __Quit() )  //???

   // centered no funciona?
   ACTIVATE DIALOG oDlg CENTERED // VALID ( oWeb:End(), .T. ) // Para??

RETURN NIL

// FIN / END

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 44229
Joined: Thu Oct 06, 2005 05:47 PM

Re: Size matching

Posted: Tue May 12, 2026 03:55 PM

Dear Joao,

#Include "FiveWin.ch"  
  

FUNCTION Main()  
  

   LOCAL oDlg, oWeb, oFont, oBtn  

   LOCAL cVer := "Exit"  
  

   DEFINE FONT  oFont  NAME "MS SANS SERIF"  SIZE 0,-12  
  

   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 ), ) }  
  

   // CORRECCIÓN: Posición del botón dentro del área visible (550 en lugar de 605)  

   @ 550, 250 BTNBMP oBtn OF oDlg SIZE 50, 30 PROMPT cVer FONT oFont CENTER ;  

      PIXEL ACTION oDlg:End()  
  

   ACTIVATE DIALOG oDlg CENTERED  
  

RETURN NIL
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8559
Joined: Tue Dec 20, 2005 07:36 PM

Re: Size matching

Posted: Tue May 12, 2026 04:39 PM

No funciona, Maestro. No hay ninguna acción en el botón.

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 44229
Joined: Thu Oct 06, 2005 05:47 PM

Re: Size matching

Posted: Tue May 12, 2026 04:54 PM

Usa TWebView2 en vez de TWebView

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 9028
Joined: Thu Oct 06, 2005 08:17 PM

Re: Size matching

Posted: Tue May 12, 2026 04:56 PM

Remove

oWeb:SetParent( oDlg )
Posts: 8559
Joined: Tue Dec 20, 2005 07:36 PM

Re: Size matching

Posted: Tue May 12, 2026 05:12 PM
Enrico Maria Giordano wrote:

Remove

oWeb:SetParent( oDlg )

Enrico, if I remove the command: oWeb:SetParent( oDlg ), the Exit button disappears.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8559
Joined: Tue Dec 20, 2005 07:36 PM

Re: Size matching

Posted: Tue May 12, 2026 05:15 PM
Antonio Linares wrote:

Usa TWebView2 en vez de TWebView

Maestro, con TWebView2, la página de Fivetech no aparece y el botón tampoco funciona. Misterio. Jajajaja.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9028
Joined: Thu Oct 06, 2005 08:17 PM

Re: Size matching

Posted: Tue May 12, 2026 05:18 PM

What is the "power button"?

Posts: 8559
Joined: Tue Dec 20, 2005 07:36 PM

Re: Size matching

Posted: Tue May 12, 2026 05:23 PM
Enrico Maria Giordano wrote:

What is the "power button"?

Sorry, EXIT Button.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341