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:

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:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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!
    <DllImport("user32.dll", SetLastError:=True)>
    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


    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    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

    ''' <summary>
    ''' Set window position to bottom right of SAP GUI screen
    ''' </summary>
    ''' <param name="hWnd">The window handle</param>
    ''' <returns>Errortext, if any </returns>
    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

    ''' <summary>
    ''' Set window size, and position relative to sap gui window
    ''' </summary>
    ''' <param name="hWnd">The window handle</param>
    ''' <param name="w">Width</param>
    ''' <param name="h">Height </param>
    ''' <returns>Errortext, if any </returns>
    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

    ''' <summary>
    ''' Set window size, and position relative to sap gui window
    ''' </summary>
    ''' <param name="hWnd">The window handle</param>
    ''' <param name="w">Width</param>
    ''' <param name="h">Height </param>
    ''' <returns>Errortext, if any </returns>
    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

Download

You can download the needed files here: guixt_dockwindow.zip

The .zip files contains:

- the VB.NET project (needs to be compiled so it can be called via callVB)
- a .dll file that you can use without compiling (guixt_dockwindow.dll)

(Hint: Please "unblock" the downloaded .zip file in the file-properties, otherwise windows can not execute the .dll file due to security reasons)

Components
Controls