Mit GuiXT
Controls können Sie beliebige ActiveX Controls in das SAP GUI Fenster
einblenden und über VB.NET automatisieren. Dabei stehen Ihnen die in
Windows enthaltenen Controls (z.B. HTML-Control, Common Controls wie
List Viewer, Tree), weitere von Microsoft kostenlos zur Verfügung
gestellte Controls (z.B. RTF-Control) und eine Vielzahl zusätzlich
erhältlicher Komponenten zur Verfügung, z.B. PDF-Anzeige,
Tabellenkalkulation, Grafikprogramme, CAD, Telefonanbindung.
Die Controls
können Sie im GuiXT Script über VB.NET Aufrufe steuern; es ist auch
möglich, aus einem Control unmittelbar Methoden anderer Controls
aufzurufen.
Wir zeigen das
in diesem Tutorial am Beispiel zweier gleichzeitig eingeblendeter
Controls:
-
RTF-Control
Damit zeigen wir ein Dokument mit SAP-Daten an, das der Benutzer
ändern und dann sichern kann
-
HTML-Control Das HTML-Control nutzen wir zum Einblenden einer
Tool-Leiste zum Formatieren des Dokuments

Dokument und Toolbox in
Transaktion VA23
Das Dokument
generieren wir aus einem RTF-Template und zeigen es im RTF-Control an.
Die Toolbox rechts über dem Dokument ist in HTML implementiert:

Der Benutzer
kann im Dokument einen Textabschnitt mit der Maus selektieren und dann
in der Toolbox eine Farbe, ein Textformat (fett, unterstrichen, kursiv)
oder Aufzählungszeichen wählen:

Selektion des
Textes im RTF-Control oben
Durch Klick in
der Toolbox ist die Firmenadresse rechts oben auf "fett" und "hellblau"
gesetzt
Der Benutzer
kann den Text nach Belieben anpassen und anschließend sichern:

Der Text kann
dann als E-Mail verschickt, im SAP zu dem Kunden abgespeichert
(Objektdienste) oder lokal weiter verarbeitet werden:

Wir stellen
zunächst kurz die wesentlichen Teile der Implementierung vor:
Einblenden der beiden Controls (GuiXT Script)
Control
(2,0)
(20,72)
name="rtf"
progID="RICHTEXT.RichtextCtrl"
initFlag="initcontrol"
properties="ScrollBars:3"
Control
(0.8,49)
(1.9,72)
name="colorpicker"
progID="file://colorpicker.html"
Aufruf einer VB.NET-Routine zum Initialisieren der Controls
(GuiXT Script)
// initialize
control in VB
CallVB
"utilities.customer.rtf_init"
"&V[rtf]" "&V[colorpicker]"
"rtfcontent"
RTF-Dokument aus GuiXT Text laden (VB.NET, Initialisierung)
Public
Sub
rtf_init(rtf As
RichTextLib.RichTextBox,
html As
SHDocVw.WebBrowser,
textname As
String)
' load content
from GuiXT long text
Dim
guixt As
New
guinet.guixt
rtf.TextRTF =
guixt.GetText(textname)
Abfangen des Click-Elements der Toolbox (VB.NET, Initialisierung)
' set handler
for HTML click
Dim
doc As
mshtml.HTMLDocumentClass
= html.Document
AddHandler
CType(doc,
mshtml.HTMLDocumentEvents2_Event).onclick,
AddressOf
WebBrowserClick
Abfrage, wo geklickt wurde (VB.NET, WebBrowserClick)
Private
Function
WebBrowserClick(pEvtObj
As
mshtml.IHTMLEventObj)
As
Boolean
' where did
the user click?
Dim
clickedElement
As mshtml.IHTMLElement
= pEvtObj.srcElement
While
clickedElement
IsNot
Nothing
AndAlso
clickedElement.tagName.ToUpper <>
"TD"
clickedElement = clickedElement.parentElement
End
While
Select
Case
clickedElement.id
Case
"bold"
...
Case
"underline"
...
Formatänderung im RTF-Dokument (VB.NET, WebBrowserClick)
Case
"bold"
' set/delete "bold"
If
IsDBNull(RTFBox.SelBold)
OrElse
RTFBox.SelBold =
False
Then
RTFBox.SelBold
= True
Else
RTFBox.SelBold
= False
End
If
...
Farbänderung im RTF-Dokument (VB.NET, WebBrowserClick)
Dim
selectedColorRGB
As
String
= pEvtObj.srcElement.style.backgroundColor
' convert RGB color
into integer
Dim
selectedColorInt
As
Integer
= RGBStringToInt(selectedColorRGB)
' set/delete color
If
IsDBNull(RTFBox.SelColor)
OrElse
RTFBox.SelColor <> selectedColorInt
Then
RTFBox.SelColor =
selectedColorInt
Else
RTFBox.SelColor = RGB(0, 0, 0)
End
If
Lesen des Dokuments aus dem
RTF-Control nach GuiXT Langtext (VB.NET)
Public
Sub
rtf_get_content(rtf As
RichTextLib.RichTextBox,
textname As
String)
' read content into GuiXT long text
Dim
guixt As
New guinet.guixt
guixt.SetText(textname, rtf.TextRTF)
End Sub
Sichern des RTF-Dokuments (GuiXT InputScript)
CallVB
"utilities.customer.rtf_get_content"
"&V[rtf]"
"rtfcontent"
CopyText
fromText="rtfcontent"
toFile="&V[outputfile]"
if
Q[ok]
Message
"S: Text gesichert"
-statusline
else
Message
"E: Text konnte nicht gesichert
werden"
-statusline
endif
Return
VB.NET Coding
insgesamt
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 | Imports guinet
Imports SAPFEWSELib
Imports RichTextLib
Imports SHDocVw
Public Class customer
Private RTFBox As RichTextLib.RichTextBox
Public Sub rtf_init(rtf As RichTextLib.RichTextBox, _
html As SHDocVw.WebBrowser, textname As String)
' Appearence
rtf.BorderStyle = BorderStyleConstants.rtfNoBorder
rtf.BackColor = RGB(255, 255, 255)
' load content from GuiXT long text
Dim guixt As New guinet.guixt
rtf.TextRTF = guixt.GetText(textname)
' set handler for HTML click
Dim doc As mshtml.HTMLDocumentClass = html.Document
AddHandler CType(doc, mshtml.HTMLDocumentEvents2_Event).onclick, _
AddressOf WebBrowserClick
' Save RTF object in order to find it later on in click handler
RTFBox = rtf
End Sub
Public Sub rtf_get_content(rtf As RichTextLib.RichTextBox, _
textname As String)
' read content into GuiXT long text
Dim guixt As New guinet.guixt
guixt.SetText(textname, rtf.TextRTF)
End Sub
Private Function WebBrowserClick(pEvtObj As mshtml.IHTMLEventObj) As Boolean
' where did the user click?
Dim clickedElement As mshtml.IHTMLElement = pEvtObj.srcElement
' search table cell in DOM hierarchy
While clickedElement IsNot Nothing _
AndAlso clickedElement.tagName.ToUpper <> "TD"
clickedElement = clickedElement.parentElement
End While
' table cell found? else return
If clickedElement Is Nothing Then
Return False
End If
Dim doc As mshtml.HTMLDocumentClass = clickedElement.document
' Find current RTF box
Dim RTFBox As RichTextLib.RichTextBox
RTFBox = RTFBoxes.Item(doc.parentWindow)
Select Case clickedElement.id
Case "bold"
' set/delete "bold"
If IsDBNull(RTFBox.SelBold) OrElse RTFBox.SelBold = False Then
RTFBox.SelBold = True
Else
RTFBox.SelBold = False
End If
Case "underline"
' set/delete "underline"
If IsDBNull(RTFBox.SelUnderline) _
OrElse RTFBox.SelUnderline = False Then
RTFBox.SelUnderline = True
Else
RTFBox.SelUnderline = False
End If
Case "italic"
' set/delete "italic"
If IsDBNull(RTFBox.SelItalic) OrElse RTFBox.SelItalic = False Then
RTFBox.SelItalic = True
Else
RTFBox.SelItalic = False
End If
Case "bullet"
' set/delete "bullet"
If IsDBNull(RTFBox.SelBullet) OrElse RTFBox.SelBullet = False Then
RTFBox.SelBullet = True
Else
RTFBox.SelBullet = False
End If
Case Else
Dim selectedColorRGB As String = _
pEvtObj.srcElement.style.backgroundColor
If Not selectedColorRGB.StartsWith("rgb(") Then
Return False
End If
' convert RGB color into integer
Dim selectedColorInt As Integer = RGBStringToInt(selectedColorRGB)
' set/delete color
If IsDBNull(RTFBox.SelColor) _
OrElse RTFBox.SelColor <> selectedColorInt Then
RTFBox.SelColor = selectedColorInt
Else
RTFBox.SelColor = RGB(0, 0, 0)
End If
End Select
Return True
End Function
Function RGBStringToInt(rgbstring As String) As Integer
' color string format is e.g. rgb(128,16,255)
' remove "rgb(" And ")"
rgbstring = rgbstring.Substring(4).Trim(")")
Dim rgbcomponents() As String = rgbstring.Split(","c)
Dim R As Integer = CInt(rgbcomponents(0))
Dim G As Integer = CInt(rgbcomponents(1))
Dim B As Integer = CInt(rgbcomponents(2))
' convert RGB color into integer
Return ColorTranslator.ToWin32(Color.FromArgb(R, G, B))
End Function
End Class
|
Alle Dateien können Sie als
zip-Datei herunterladen:
Alle Dateien als zip
Datei
Einige Bemerkungen zur
Implementierung:
Dokumentation der
ActiveX-Schnittstelle für VB.NET
Für die Microsoft-Controls findet sich die Dokumentation im Internet,
meist in MSDN (Microsoft Developer Network). In unserem Fall z.B. in dem
Artikel
Visual Basic: RichTextBox Control. Die Methoden sind dort für VB6
beschrieben und können identisch in VB.NET verwendet werden.
Anzeige der Scrollbalken im RTF-Control
Generell setzt man die Anzeigeattribute eines Controls am besten in
der VB.NET-Routine, die zur Initialisierung aufgerufen wird, in unserem
Fall also in der Methode rtf_init. Das funktioniert bei dem RTF-Control
allerdings nicht für die Eigenschaft ScrollBars, da diese zur
Laufzeit readonly ist. Ausschnitt
Dokumentation:
ScrollBars Property (RichTextBox
Control)Returns
or sets a value indicating whether a RichTextBox control
has horizontal or vertical scroll bars. Read-only at
run time.
Syntax
object.ScrollBars
The object placeholder represents
an object expression that
evaluates to a RichTextBox control.
Settings
The ScrollBars property settings
are:
Constant |
Value |
Description |
rtfNone |
0 |
(Default) No scroll bars
shown. |
rtfHorizontal |
1 |
Horizontal scroll bar
only. |
rtfVertical |
2 |
Vertical scroll bar only. |
rtfBoth |
3 |
Both horizontal and
vertical scroll bars shown. |
Daher ist es nicht möglich,
den Defaultwert 0 (keine Scrollbalken) in der VB.NET-Routine zu
ändern. Wir können stattdessen aber im GuiXT Script bei Anlegen
des Controls bereits Eigenschaften mitgeben, die auch in diesem
Fall wirksam werden:
Control
(2,0)
(20,72)
name="rtf"
...
properties="ScrollBars:3"
Hierbei auf Gross/Kleinschreibung
des property-Namens achten.
Planen, wie die ActiveX-Komponente später auf den Benutzer-PCs
installiert wird
Bei Standard-Windowskomponenten ist das
automatisch der Fall. Zusätzlich gekaufte Komponenten werden meist über
ein eigenes Setup installiert.
In unserem Fall (RTF-Control) ist das
Control von Microsoft für alle Windows-Versionen bis Windows 8, auch
64-Bit, unterstützt; es ist aber nicht automatisch mit Windows
installiert (siehe
Microsoft Support Statement for Visual Basic 6.0 on Windows Vista,
Windows Server 2008, Windows 7, and Windows 8).
Folgende Aktionen sind deshalb auf jedem
PC noch nötig (manuell oder durch passende Tools z.B. Windows Logon Exit):
-
Die Datei "richtx32.ocx" nach
C:\Windows\SysWoW64 kopieren
-
Ein MS DOS Window (Command prompt)
mit "Run as Administrator" starten
-
Den Befehl
C:\Windows\SysWoW64\regsvr32.exe richtx32.ocx
ausführen
|