Purpose
You want to position a Webview control at a specific location in the SAP GUI window, for example, at the
bottom right edge.
Example: Embed a chatbot-webapplication into an SAP Screen
Solution
When using a WebView control, GuiXT always also provides the name of the window (Windows handle)
in a variable.
This can be passed to a function in order to subsequently change the window properties (size,
position).
In addition, GuiXT also provides access to the window properties of the SAP GUI window,
so that a separate window or the WebView control can be positioned relative to it. In our
example, this would be the lower right corner.
We also change to window to
0.75% of the height and 0.25% of the width of the SAP GUI
window in this example.
We show here the implementation of this positioning as an example. You can use the compiled DLL
file, or download the VB.NET project and extend it yourself.
GuiXT Script:
GuiXT
WebView (0,0.9) (15.4,33.8) _
"http://www.synactives10.com/chatbot" _
name="mywebview.41" -floating
// Set according to sap gui dimensions
// -> 25% width and 75% height
set V[w] "&V[_windowsize_x]" / 4 decimals=0
set V[h] "&V[_windowsize_y]" / 4 decimals=0
set V[h] "&V[h]" * 3
callvb guixt_dockwindow.utilities.set_window_size _
hwnd:="&V[mywebview2.hwnd]" w:="&V[w]" h:="&V[h]"
callvbasync guixt_dockwindow.utilities.dock_bottom_right _
hwnd:="&V[mywebview2.hwnd]"
VB.NET Coding:
VB.NET
Imports guinet
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class utilities
' interface to GuiXT
Private myguixt As New guixt
Private mysapwindow As NativeWindow
Private Structure RECT
Public Left As Int32
Public Top As Int32
Public Right As Int32
Public Bottom As Int32
End Structure
Public Const SWP_NOMOVE As Short = &H2
Public Const SWP_NOSIZE As Short = 1
Public Const SWP_NOZORDER As Short = &H4
Public Const SWP_SHOWWINDOW As Short = &H40
Enum ShowWindowCommands As Integer
Hide = 0
Normal = 1
ShowMinimized = 2
Maximize = 3
ShowMaximized = 3
ShowNoActivate = 4
Show = 5
Minimize = 6
ShowMinNoActive = 7
ShowNA = 8
Restore = 9
ShowDefault = 10
ForceMinimize = 11
End Enum
'MoveWindow changes window's top, left, width and height...
'...even if it do not want to change their dimensions and haves fixed edges!
Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer,
nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
End Function
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As ShowWindowCommands) As Boolean
End Function
Private Declare Function GetWindowRect Lib "user32.dll" (
ByVal hwnd As IntPtr,
ByRef lpRect As RECT) As Int32
'''
''' Set window position to bottom right of SAP GUI screen
'''
''' The window handle
''' Errortext, if any
Public Function dock_bottom_right(ByVal hWnd As Long) As String
Dim ret As String = ""
Try
If mysapwindow Is Nothing Then
mysapwindow = myguixt.GuiWindow()
End If
' Get the screen dimensions of sap gui window
Dim r As New RECT
GetWindowRect(mysapwindow.Handle, r)
' Get the screen dimensions of the given window
' (e.g. webview control)
Dim r2 As New RECT
GetWindowRect(hWnd, r2)
' Set the window to the bottom right of the sap gui window
MoveWindow(hWnd, r.Right - (r2.Right - r2.Left), r.Bottom - (r2.Bottom - r2.Top),
r2.Right - r2.Left, r2.Bottom - r2.Top, True)
Catch ex As Exception
ret = ex.Message
End Try
Return ret
End Function
'''
''' Set window size, and position relative to sap gui window
'''
''' The window handle
''' Width
''' Height
''' Errortext, if any
Public Function set_window_dimensions(ByVal hWnd As Long, x As Integer, y As Integer, w As Integer, h As Integer) As String
Dim ret As String = ""
Try
If Not myguixt.GuiWindow Is Nothing Then
If mysapwindow Is Nothing Then
mysapwindow = myguixt.GuiWindow()
End If
' Get the screen dimensions of sap gui window
Dim r As New RECT
GetWindowRect(mysapwindow.Handle, r)
' Get the screen dimensions of the given window
' (e.g. webview control)
Dim r2 As New RECT
GetWindowRect(hWnd, r2)
MoveWindow(hWnd, r.Left + x, r.Top + y, w, h, True)
'Window may be minimized by user -> restore
ShowWindow(hWnd, ShowWindowCommands.Normal)
End If
Catch ex As Exception
ret = ex.Message
End Try
Return ret
End Function
'''
''' Set window size, and position relative to sap gui window
'''
''' The window handle
''' Width
''' Height
''' Errortext, if any
Public Function set_window_size(ByVal hWnd As Long, w As Integer, h As Integer) As String
Dim ret As String = ""
Try
' Get the screen dimensions of the given window
' (e.g. webview control)
Dim r2 As New RECT
GetWindowRect(hWnd, r2)
MoveWindow(hWnd, r2.Left, r2.Top, w, h, True)
'Window may be minimized by user -> restore
ShowWindow(hWnd, ShowWindowCommands.Normal)
Catch ex As Exception
ret = ex.Message
End Try
Return ret
End Function
End Class