Option Explicit
Private Declare Function NetMessageBufferSend Lib "netapi32.dll" ( _
lpServerName As Any, _
lpMsgName As Byte, _
lpFromName As Any, _
lpBuf As Byte, _
ByVal lnBufLen As Long _
) As Long
Private Const NERR_Success As Long = 0&
Private Sub Command1_Click()
On Error GoTo Fehler
Dim Result As Boolean
If Text1 = "" Then MsgBox "Bitte Computername angeben.", vbInformation: Text1.SetFocus: Exit Sub
If Text2 = "" Then MsgBox "Bitte Absender angeben.", vbInformation: Text2.SetFocus: Exit Sub
If Text3 = "" Then MsgBox "Sie müssen auch eine Nachricht eingeben.", vbInformation: Text1.SetFocus: Exit Sub
Dialog.Show 0, Me
DoEvents
Result = SendMsg(Text1, Text2, Text3)
If Result Then
Unload Dialog
' MsgBox "Die Nachricht wurde verschickt."
Else
Unload Dialog
MsgBox "Die Nachricht konnte nicht verschickt werden."
End If
Text1.SetFocus
Exit Sub
Fehler:
MsgBox Err.Description
Unload Dialog
Exit Sub
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text2.SetFocus: KeyAscii = 0
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text3.SetFocus: KeyAscii = 0
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command1.SetFocus: KeyAscii = 0
End Sub
Private Function SendMsg(SendTo As String, SendFrom As String, Message As String) As Long
Dim WrittenTo() As Byte ' enthält den Empfänger der Nachricht
Dim WrittenBy() As Byte ' enthält den Absender der Nachricht
Dim MSGBuffer() As Byte ' enthält die zu sendende Nachricht
WrittenTo = SendTo & vbNullChar
WrittenBy = SendFrom & vbNullChar
MSGBuffer = Message & vbNullChar
SendMsg = (NetMessageBufferSend(ByVal 0&, WrittenTo(0), _
WrittenBy(0), MSGBuffer(0), UBound(MSGBuffer)) = NERR_Success)
End Function