Hallo,
Ich baue gerade ein TV Steuerung wo ich zumindest den Grundstein haben, wie ich es benötige.
Ich suche noch ein paar tipps dies einfacher zu gestalten da ich noch etwas ratlos bin wie es besser schreiben kann.
Ich habe in mein Script zb. 3 Tv mit einer aufklappfunktion, wo bestimmte Befehle hinterlegt werden können.
Nur wie mach ich das wenn ich zb. 10 Tv´s brauche, da wird die Liste ja endlos lang
Ich werden bei allen TV die gleiche Liste angezeigt das kann man sicher auch einfacher durchführen das ich nur mehr die Position des TV angeben muss.
Könnte mir jemand helfen ?
C
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#Region all client IP´s
Global $telnet_port = "8080" ;Port
Global $TV1_ip = "192.168.0.10"
Global $TV2_ip = "192.168.0.11"
Global $TV3_ip = "192.168.0.12"
#EndRegion
$hGUI = GUICreate("Test", 1000, 750, 0, 0)
#Region TV1 Button
$TV1fb = GUICtrlCreateButton("TV 1", 100, 100, 60, 20)
$TV1ch = GUICtrlCreateButton("", 100, 118, 60, 20)
$TV1chContext = GUICtrlCreateContextMenu($TV1ch)
$TV1MenuItem1 = GUICtrlCreateMenuItem("Test 1", $TV1chContext)
$TV1MenuItem2 = GUICtrlCreateMenuItem("Test 2", $TV1chContext)
$TV1MenuItem3 = GUICtrlCreateMenuItem("Test 3", $TV1chContext)
$TV1MenuItem4 = GUICtrlCreateMenuItem("Test 4", $TV1chContext)
$TV1MenuItem5 = GUICtrlCreateMenuItem("Test 5", $TV1chContext)
$TV1MenuItem6 = GUICtrlCreateMenuItem("", $TV1chContext)
$TV1MenuRestart = GUICtrlCreateMenuItem("Restart", $TV1chContext)
GUICtrlSetFont($TV1fb, 8.5, 700, 0, "")
GUICtrlSetFont($TV1ch, 8.5, 500, 0, "")
#EndRegion TV1 Button
#Region TV2 Button
$TV2fb = GUICtrlCreateButton("TV2", 200, 100, 60, 20)
$TV2ch = GUICtrlCreateButton("", 200, 118, 60, 20)
$TV2chContext = GUICtrlCreateContextMenu($TV2ch)
$TV2MenuItem1 = GUICtrlCreateMenuItem("Test 1", $TV2chContext)
$TV2MenuItem2 = GUICtrlCreateMenuItem("Test 2", $TV2chContext)
$TV2MenuItem3 = GUICtrlCreateMenuItem("Test 3", $TV2chContext)
$TV2MenuItem4 = GUICtrlCreateMenuItem("Test 4", $TV2chContext)
$TV2MenuItem5 = GUICtrlCreateMenuItem("Test 5", $TV2chContext)
$TV2MenuItem6 = GUICtrlCreateMenuItem("", $TV2chContext)
$TV2MenuRestart = GUICtrlCreateMenuItem("Restart", $TV2chContext)
GUICtrlSetFont($TV2fb, 8.5, 700, 0, "")
GUICtrlSetFont($TV2ch, 8.5, 500, 0, "")
#EndRegion TV2 Button
#Region TV3 Button
$TV3fb = GUICtrlCreateButton("TV3", 300, 100, 60, 20)
$TV3ch = GUICtrlCreateButton("", 300, 118, 60, 20)
$TV3chContext = GUICtrlCreateContextMenu($TV3ch)
$TV3MenuItem1 = GUICtrlCreateMenuItem("Test 1", $TV3chContext)
$TV3MenuItem2 = GUICtrlCreateMenuItem("Test 2", $TV3chContext)
$TV3MenuItem3 = GUICtrlCreateMenuItem("Test 3", $TV3chContext)
$TV3MenuItem4 = GUICtrlCreateMenuItem("Test 4", $TV3chContext)
$TV3MenuItem5 = GUICtrlCreateMenuItem("Test 5", $TV3chContext)
$TV3MenuItem6 = GUICtrlCreateMenuItem("", $TV3chContext)
$TV3MenuRestart = GUICtrlCreateMenuItem("Restart", $TV3chContext)
GUICtrlSetFont($TV3fb, 8.5, 700, 0, "")
GUICtrlSetFont($TV3ch, 8.5, 500, 0, "")
#EndRegion TV3 Button
GUISetState(@SW_SHOW)
While 1
Sleep(10)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;TV1
Case $TV1fb
Case $TV1ch
ShowMenu($hGUI, $nMsg, $TV1chContext)
Case $TV1MenuItem1
Test1()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "Test 1")
Case $TV1MenuItem2
Test2()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "Test 2")
Case $TV1MenuItem3
Test3()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "Test 3")
Case $TV1MenuItem4
Test4()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "Test 4")
Case $TV1MenuItem5
Test5()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "Test 5")
Case $TV1MenuRestart
restart()
$telnet_host = $TV1_ip
telnet_send ()
GUICtrlSetData($TV1ch, "")
Sleep (5000)
telnet_send ()
;TV2
Case $TV2fb
Case $TV2ch
ShowMenu($hGUI, $nMsg, $TV2chContext)
Case $TV2MenuItem1
Test1()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "Test 1")
Case $TV2MenuItem2
Test2()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "Test 2")
Case $TV2MenuItem3
Test3()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "Test 3")
Case $TV2MenuItem4
Test4()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "Test 4")
Case $TV2MenuItem5
Test5()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "Test 5")
Case $TV2MenuRestart
restart()
$telnet_host = $TV2_ip
telnet_send ()
GUICtrlSetData($TV2ch, "")
Sleep (5000)
telnet_send ()
;TV3
Case $TV3fb
Case $TV3ch
ShowMenu($hGUI, $nMsg, $TV3chContext)
Case $TV3MenuItem1
Test1()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "Test 1")
Case $TV3MenuItem2
Test2()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "Test 2")
Case $TV3MenuItem3
Test3()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "Test 3")
Case $TV3MenuItem4
Test4()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "Test 4")
Case $TV3MenuItem5
Test5()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "Test 5")
Case $TV3MenuRestart
restart()
$telnet_host = $TV3_ip
telnet_send ()
GUICtrlSetData($TV3ch, "")
Sleep (5000)
telnet_send ()
EndSwitch
WEnd
#Region Func
Func ShowMenu($hWnd, $CtrlID, $nContextID)
Local $arPos, $x, $y
Local $hMenu = GUICtrlGetHandle($nContextID)
$arPos = ControlGetPos($hWnd, "", $CtrlID)
$x = $arPos[0]
$y = $arPos[1] + $arPos[3]
ClientToScreen($hWnd, $x, $y)
TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc ;ShowMenu
; Convert the client GUI coordinates to screen desktop coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
Local $stPoint = DllStructCreate("int;int")
DllStructSetData($stPoint, 1, $x)
DllStructSetData($stPoint, 2, $y)
DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
$x = DllStructGetData($stPoint, 1)
$y = DllStructGetData($stPoint, 2)
; release Struct not really needed as it is a local
$stPoint = 0
EndFunc ;==>ClientToScreen
; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc ;==>TrackPopupMenu
;Channels Func
Func Test1()
Global $telnet_command = "Telnet command 1"
EndFunc
Func Test2()
Global $telnet_command = "Telnet command 2"
EndFunc
Func Test3()
Global $telnet_command = "Telnet command 3"
EndFunc
Func Test4()
Global $telnet_command = "Telnet command 4"
EndFunc
Func Test5()
Global $telnet_command = "Telnet command 5"
EndFunc
Func restart()
Global $telnet_command = "Telnet restart"
EndFunc
;Telnet_send
Func telnet_send ()
TCPStartup ()
$Conection = TCPConnect ( $telnet_host, $telnet_port )
If @error Then MsgBox (0,"Error","connection not ok")
TCPSend ( $Conection, $telnet_command & Chr ( 10 ) )
If @error Then
MsgBox (0,"Error","not possible")
EndIf
EndFunc
; End Telnet_send
#EndRegion Func
Alles anzeigen