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
|