CWebView::SetBounds Method  
 
BOOL SetBounds(
  LPRECT lpRect  
);
BOOL SetBounds(
  INT xPos,  
  INT yPos,  
  INT nWidth,  
  INT nHeight  
);

The SetBounds method sets the position and size of the browser child window.

Parameters

lpRect
A pointer to a RECT structure which specifies the position and dimensions of the browser window. If this version of the method is called, this parameter cannot be NULL.
xPos
The x-position of the child window. This is a client area coordinate of the host window, not a screen position.
yPos
The y-position of the child window. This is a client area coordinate of the host window, not a screen position.
nWidth
The width of the child window. This is expressed in device units for the host window's client area.
nHeight
The height of the child window. This is expressed in device units for the host window's client area.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The SetBounds method updates the position and size of the embedded browser window relative to the client area of the host window. It calls the put_Bounds method on the underlying WebView2 controller to resize the child window that renders the web content. The specified coordinates and dimensions must fall within the client area of the host window associated with the browser instance. Attempting to specify bounds outside of the host window will result in clipping or the control being partially hidden.

The nWidth and nHeight parameters are device units, the same pixel units that the Win32 API uses with functions like MoveWindow and SetWindowPos. If the host window was created as a per-monitor DPI-aware window, the values your application gets with a WM_SIZE message are already scaled for the current DPI and you should just pass those values directly to this method. If your application is not DPI-aware, Windows will attempt to scale the values for you through DPI virtualization. It is important to note that these values are not logical units like Twips and they are not independent of DPI scaling.

Typically this method is called from within a WM_SIZE or WM_MOVE message handler so that the browser control resizes and repositions itself along with the parent window. You can also call this function directly to dock the browser into a specific portion of the host window's client area, such as aligning it within a child frame or panel.

In most applications it is sufficient to call this method in response to a WM_SIZE message so the browser control resizes along with the client area of the host window. However, in a per-monitor DPI-aware application it may also be useful to call this method when handling WM_MOVE. This is because moving a top-level window between monitors can trigger a DPI change even if the window size itself does not change. Reapplying the bounds in response to WM_MOVE ensures the control is correctly adjusted to the new scaling factor. For applications that are not DPI-aware, handling WM_MOVE is generally unnecessary since the client area origin remains at (0,0) and Windows applies DPI virtualization automatically.

Calling SetBounds does not affect the visibility of the browser window. To hide or show the control, use the Hide or Show methods, and to query its visibility, use IsVisible.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also