Sign in to follow this  
Followers 0
kingjacob90

_GUICtrlListView_AddItem wont fit!

1 post in this topic

#1 ·  Posted (edited)

Hi I am using _GUICtrlListView_AddItem and the Item will not fit under the Column. How do I make it so the item will go onto the next line?

Here is the program I am creating pleas comment. If you like I can give you the full working version contact me on my Autoit MSG-er  :D .

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
$version="1.1"
If FileExists(@ScriptDir&"\version.txt") Then
    FileDelete(@ScriptDir&"\version.txt")
EndIf
FileWrite(@ScriptDir&"\version.txt",$version)

TCPStartup() ; Start the TCP service.

; Register OnAutoItExit to be called when the script is closed.
OnAutoItExitRegister("OnAutoItExit")

; Assign Local variables the loopback IP Address and the Port.
$what_ip=InputBox("pick IP","Pick your IP (using 1,2,3 or 4)"&@CRLF&@CRLF&"1 = "&@IPAddress1&@CRLF&@CRLF&"2 = "& _
@IPAddress2&@CRLF&@CRLF&"3 = "&@IPAddress3&@CRLF&@CRLF&"4 = "&@IPAddress4& _
@CRLF&@CRLF&"test = 127.0.0.1","","",250,300)
If @error Then Exit
If $what_ip="1" Then
    Global $sIPAddress = @IPAddress1 ; This IP Address only works for testing on your own computer.
ElseIf $what_ip="2" Then
    Global $sIPAddress = @IPAddress2 ; This IP Address only works for testing on your own computer.
ElseIf $what_ip="3" Then
    Global $sIPAddress = @IPAddress3 ; This IP Address only works for testing on your own computer.
ElseIf $what_ip="4" Then
    Global $sIPAddress = @IPAddress4 ; This IP Address only works for testing on your own computer.
ElseIf $what_ip="test" Then
    Global $sIPAddress="127.0.0.1"
Else
    MsgBox(16,"","Input error")
EndIf
If $sIPAddress="0.0.0.0" Then
    MsgBox(16,"","IP not good, will now exit program!")
    Exit
EndIf

;---not yet used---
If FileExists(@ScriptDir&"\my_ip.txt") Then
    FileDelete(@ScriptDir&"\my_ip.txt")
EndIf
FileWrite(@ScriptDir&"\my_ip.txt",$sIPAddress)
;---not yet used--- END


Global $iPort = 65432 ; Port used for the connection.
server_gui()

Func server_gui()
    Global $server_gui=GUICreate("Server info (Your IP = "&$sIPAddress&")",400,610)
    GUISetBkColor(0x000000)

    Global $gui_send=GUICtrlCreateButton("Send MSG",5,580,390,25,0x0001)
        GUICtrlSetFont(-1,12)

    Global $gui_help=GUICtrlCreateButton("Help",5,3,190,25)
    Global $gui_about=GUICtrlCreateButton("About",205,3,190,25)
    Global $idListview = GUICtrlCreateListView("", 5, 30, 390, 370)
    GUICtrlCreateLabel("Type in the Server IP you wont to talk to:",5,405,390,15)
        GUICtrlSetColor(-1,0xffffff)
    Global $gui_input_ip=GUICtrlCreateInput("192.168.1.68",5,425,390,25,0x0001)
        GUICtrlSetFont(-1,12)
    GUICtrlCreateLabel("Type in the MSG you wont to send:",5,455,390,15)
        GUICtrlSetColor(-1,0xffffff)
    Global $gui_input_msg=GUICtrlCreateInput("",5,475,390,100,0x0004)

    GUISetState()

    _GUICtrlListView_InsertColumn($idListview, 0, "InBox", 350)
    Sleep(500)
    _GUICtrlListView_AddItem($idListview,">>>server online",0)
    Sleep(500)
    $world_ip="Not Known"
    _GUICtrlListView_AddItem($idListview,">>>Your LAN ip > "&$sIPAddress,0)
    Sleep(500)
    _GUICtrlListView_AddItem($idListview,">>>Your World ip > "&$world_ip,0)
    MyTCP_Server($sIPAddress, $iPort)
EndFunc

Func MyTCP_Server($sIPAddress, $iPort)

    ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions.
    Local $iListenSocket = TCPListen($sIPAddress, $iPort)
    Local $iError = 0

    If @error Then
        ; Someone is probably already listening on this IP Address and Port (script already running?).
        $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError)
        Return False
    EndIf

    ; Assign a Local variable to be used by the Client socket.
    Local $iSocket = 0

    Do ; Wait for someone to connect (Unlimited).
        ; Accept incomming connexions if present (Socket to close when finished; one socket per client).
        $iSocket = TCPAccept($iListenSocket)

        ;---<<|>>|GUI|<<|>>---;
        $gui_msg=GUIGetMsg()
        If $gui_msg=$gui_send Then
            $gui_input_ip_read=GUICtrlRead($gui_input_ip)
            $gui_input_msg_read=GUICtrlRead($gui_input_msg)
            FileWrite(@ScriptDir&"\ip.txt",$gui_input_ip_read)
            FileWrite(@ScriptDir&"\msg.txt",$gui_input_msg_read)
            ShellExecute(@ScriptDir&"\cliant.exe")
            _GUICtrlListView_AddItem($idListview,">>>Sending Msg to"&$gui_input_ip_read)
            GUICtrlSetData($gui_input_msg,"")
            Sleep(700)
        EndIf
        If $gui_msg=$gui_help Then
            ShellExecute(@ScriptDir&"\help.exe")
        EndIf
        If $gui_msg=$gui_about Then
            ShellExecute(@ScriptDir&"\about.exe")
        EndIf
        If $gui_msg=-3 Then Exit


        ; If an error occurred display the error code and return False.
        If @error Then
            $iError = @error
            MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not accept the incoming connection, Error code: " & $iError)
            Return False
        EndIf

        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Return False
    Until $iSocket <> -1 ;if different from -1 a client is connected.

    ; Close the Listening socket to allow afterward binds.
    TCPCloseSocket($iListenSocket)
    If @error Then
        MsgBox(16,"","Error = close socket"&@CRLF&"Error code = "&@error)
        Exit
    EndIf

    ; Assign a Local variable the data received.
    Local $sReceived = TCPRecv($iSocket,1000000) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): was 4 bytes length.
    If @error Then
        If @error<>-1 Then
            MsgBox(16,"","Error = Recv"&@CRLF&"Error code = "&@error)
            Exit
        EndIf
    EndIf

    ; Notes: If you don't know how much length will be the data,
    ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error.

    ; Display the string received.
    _GUICtrlListView_AddItem($idListview,$sReceived,0)
    _GUICtrlListView_Scroll($idListview,0,500)

    ; Close the socket.
    TCPCloseSocket($iSocket)
    MyTCP_Server($sIPAddress, $iPort)
EndFunc   ;==>MyTCP_Server

Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit
Edited by kingjacob90

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0