Page 1 of 2
Size matching
Posted: Wed Apr 15, 2026 12:38 pm
by Natter
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)
Re: Size matching
Posted: Wed Apr 15, 2026 3:50 pm
by Antonio Linares
Please try it this way:
Code: Select all | Expand
#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
Re: Size matching
Posted: Thu Apr 16, 2026 9:44 am
by Natter
Thank you. The method :setSize has a third parameter - nHint. What is it?
Re: Size matching
Posted: Thu Apr 16, 2026 9:58 am
by Antonio Linares
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: Select all | Expand
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.
Re: Size matching
Posted: Thu Apr 16, 2026 11:01 am
by Natter
It didn't work out. The oWeb:setSize() method, for some reason, changes the size of the owner's window, bat not the WebView. 
Re: Size matching
Posted: Thu Apr 16, 2026 11:47 am
by Antonio Linares
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: Select all | Expand
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
Re: Size matching
Posted: Tue May 12, 2026 3:40 pm
by karinha
Maestro Antônio, en el ejemplo que publicó, ¿cómo desactivo el DIÁLOGO usando el botón?
Code: Select all | Expand
// 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.
Re: Size matching
Posted: Tue May 12, 2026 3:55 pm
by Antonio Linares
Dear Joao,
Code: Select all | Expand
#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
Re: Size matching
Posted: Tue May 12, 2026 4:39 pm
by karinha
No funciona, Maestro. No hay ninguna acción en el botón.
Gracias, tks.
Regards, saludos.
Re: Size matching
Posted: Tue May 12, 2026 4:54 pm
by Antonio Linares
Usa TWebView2 en vez de TWebView
Re: Size matching
Posted: Tue May 12, 2026 4:56 pm
by Enrico Maria Giordano
Re: Size matching
Posted: Tue May 12, 2026 5:12 pm
by karinha
Enrico, if I remove the command: oWeb:SetParent( oDlg ), the Exit button disappears.
Regards, saludos.
Re: Size matching
Posted: Tue May 12, 2026 5:15 pm
by karinha
Antonio Linares wrote: Tue May 12, 2026 4:54 pm
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.
Re: Size matching
Posted: Tue May 12, 2026 5:18 pm
by Enrico Maria Giordano
What is the "power button"?
Re: Size matching
Posted: Tue May 12, 2026 5:23 pm
by karinha