Jump to content

Form freezes while trying to resolve IP


Recommended Posts

Hi,

I have a form which calls this function:

Func HostToIP($Host, $Label)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Host)
    If @error Then
        GUICtrlSetData ($Label, "Error code: " & @error)
    Else
        GUICtrlSetData ($Label, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

But if it cannot resolve the host to an IP, the whole form freezes for a few seconds until the TCPNameToIP times out, how can I stop the form from freezing whilst it waits for the host to ip times out?

TCPNameToIP is part of #include <_sql.au3>

Link to comment
Share on other sites

Couldn't ack.  Tested with:

$tdStart=TimerInit()
            TCPStartup()
            $sIPAddress = TCPNameToIP("www.autoitscript2.com")
            If @error Then
                GUICtrlSetData($Label, "Error code: " & @error)
            Else
                GUICtrlSetData($Label, $sIPAddress)
            EndIf
            TCPShutdown()
            ConsoleWrite('Time for resolve: '&TimerDiff($tdStart)&@CRLF)

consoleoutput:

Quote

Time for resolve: 25.8624331039144

TCPNameToIP is a native AutoIt func.

 

Post a full runable reproducer script showing your issue.

Link to comment
Share on other sites

23 minutes ago, AutoBert said:

Post a full runable reproducer script showing your issue.

Heres a full working script where it freezes:

#NoTrayIcon
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Sound.au3>
#include <MetroGUI-UDF\MetroGUI_UDF.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <_sql.au3>

#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe
#AutoIt3Wrapper_Res_HiDpi=y

_SetTheme("DarkBlueV2")

_Metro_EnableHighDPIScaling()

Local $ServerAddress = "SomeServer"

$GLOBAL_MAIN_GUI = _Metro_CreateGUI("Settings", 347, 532, 950, -1, True)

GUISetFont ( 9 , 0 , 0 , "Segoe UI" , $GLOBAL_MAIN_GUI , 5 )
GUICtrlSetDefColor ( $COLOR_WHITE , $GLOBAL_MAIN_GUI )

GUICtrlCreateGroup("", 8, 35, 330, 142)
GUICtrlCreateLabel("IP", 24, 80)

$IP = GUICtrlCreateLabel("", 130, 80, 193, 21, $SS_RIGHT)

$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True)

$GUI_CLOSE_BUTTON = $Control_Buttons[0]
GUICtrlSetTip($GUI_CLOSE_BUTTON, "Close")
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]

Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

GUISetState(@SW_SHOW)

HostToIP($ServerAddress, $IP)

While 1
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            Exit
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0)
            Switch $MenuSelect
                Case "0"
                    MsgBox (4096,"1","2")
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($GLOBAL_MAIN_GUI)
                    Exit
            EndSwitch
    EndSwitch
WEnd

Func HostToIP($Host, $Label)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Host)
    If @error Then
        GUICtrlSetData ($Label, "Error code: " & @error)
    Else
        GUICtrlSetData ($Label, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

 

Link to comment
Share on other sites

this script isn't working:

+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
! Invalid AutoIt3Wrapper directive Keyword:#AutoIt3Wrapper_Res_HiDpi with value:y
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(50,44) : error: _Metro_HoverCheck_Loop() called with wrong number of args.
    _Metro_HoverCheck_Loop($GLOBAL_MAIN_GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF.au3"(558,80) : REF: definition of _Metro_HoverCheck_Loop().
Func _Metro_HoverCheck_Loop(ByRef $GUI_HOVER_REG, $Metro_GUI, $Metro_GUI_2 = 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(68,54) : error: _Metro_GUIDelete() called with wrong number of args.
                    _Metro_GUIDelete($GLOBAL_MAIN_GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF.au3"(317,44) : REF: definition of _Metro_GUIDelete().
Func _Metro_GUIDelete($GUI_HOVER_REG, $GUI)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(18,29) : error: _Metro_EnableHighDPIScaling(): undefined function.
_Metro_EnableHighDPIScaling()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(32,75) : error: _Metro_AddControlButtons(): undefined function.
$Control_Buttons = _Metro_AddControlButtons(True, False, True, False, True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3"(58,126) : error: _Metro_MenuStart(): undefined function.
            Local $MenuSelect = _Metro_MenuStart($GLOBAL_MAIN_GUI, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\test.au3 - 5 error(s), 0 warning(s)
!>12:56:52 AU3Check ended. Press F4 to jump to next error.rc:2
+>12:56:52 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.253

attach your (modified?) version of MetroGUI_UDF.au3 and if any func of _sql.au3 this also.

Link to comment
Share on other sites

Now this errors:

+>13:17:44 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(141,43) : warning: $GLOBAL_GUI_LIST: possibly used before declaration.
    For $iGUIs = 0 To UBound($GLOBAL_GUI_LIST)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(315,56) : error: _GetDesktopWorkArea() called with wrong number of args.
    Local $FullScreenPOS = _GetDesktopWorkArea($mGUI, True)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroUDF-Required\BorderlessWinUDF.au3"(188,32) : REF: definition of _GetDesktopWorkArea().
Func _GetDesktopWorkArea($hWnd)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3"(185,55) : error: INTERNAL_INTERCEPT_FRAMEDRAW(): undefined function.
    GUIRegisterMsg(0x0083, "INTERNAL_INTERCEPT_FRAMEDRAW")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Downloads\MetroGUI_UDF_v3\MetroGUI UDF v3\MetroGUI_UDF_fromCM.au3 - 2 error(s), 1 warning(s)
!>13:17:46 AU3Check ended. Press F4 to jump to next error.rc:2
+>13:17:46 AutoIt3Wrapper Finished.

So last try: post link to used version of the MetroGuiUDF

Edit: i know GUI's created with native AutoIt won't freeze, maybe the author of the UDF has some bugs.

 

 

Edited by AutoBert
Link to comment
Share on other sites

22 minutes ago, AutoBert said:

Ok, yet i can ack, needed time with this UDF  2318 ms this is ~ 100* as in a normal GUI. But if you call before GuiSetState the user didn't notice it. 

User needs to be able to see the window from the very start, it will later have a refresh button which will call the same function again, and I wouldnt want it freezing when doing the function again after pressing refresh button

47 minutes ago, AutoBert said:

Edit: i know GUI's created with native AutoIt won't freeze, maybe the author of the UDF has some bugs.
 

I have stripped it down to basics, its now using native autoit, but still freezes:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>

Local $SERVERADDRESS = "SomeServer"

GUICreate("", 395, 532, 598, 0)

GUICtrlCreateLabel("IP: ", 24, 56, 20, 17)

$JEFF_IP = GUICtrlCreateLabel("", 120, 56, 249, 21)

GUISetState(@SW_SHOW)

HostToIP($ServerAddress)

Func HostToIP($Server)
TCPStartup()
    Local $sIPAddress = TCPNameToIP($Server)
    If @error Then
        GUICtrlSetData ($JEFF_IP, "Error code: " & @error)
    Else
        GUICtrlSetData ($JEFF_IP, $sIPAddress)
    EndIf
TCPShutdown()
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Tested with:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>


TCPStartup()
Local $SERVERADDRESS = "www.autoitscript2.com"

GUICreate("", 395, 532, 598, 0)
$idResolve=GUICtrlCreateButton('&IP',5,5,100,21)
GUICtrlCreateLabel("IP: ", 24, 56, 20, 17)

$JEFF_IP = GUICtrlCreateLabel("", 120, 56, 249, 21)

GUISetState(@SW_SHOW)

;HostToIP($SERVERADDRESS)

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($JEFF_IP, "Error code: " & @error)
    Else
        GUICtrlSetData($JEFF_IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TCPShutdown()
            Exit
        Case $idResolve
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd

console output:

Time for resolve: 27.7536355246535
Time for resolve: 2.48640318259607
Time for resolve: 2.83392362742224
Time for resolve: 2.59456332104105

 

Edited by AutoBert
Link to comment
Share on other sites

Meanwhile tested with:

==============================================================================================
; Name ..........: MetroGUI UDF Example
; Version .......: v4.3
; Author ........: BB_19
; ===============================================================================================================================

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

#NoTrayIcon
#include "MetroGUI-UDF\MetroGUI_UDF.au3"

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

            TCPStartup()
;Create resizable Metro GUI
$Form1 = _Metro_CreateGUI("Example", 500, 300, -1, -1, True)

;Add/create control buttons to the GUI
$Control_Buttons = _Metro_AddControlButtons(True, True, True, True, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("Button Style 1", 105, 245, 130, 40)
$Button2 = _Metro_CreateButtonEx("Button Style 2", 255, 245, 130, 40)


;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Set resizing options for the controls so they don't change in size or position. This can be customized to match your gui perfectly for resizing. See AutoIt Help file.
GUICtrlSetResizing($Button1, 768 + 8)
GUICtrlSetResizing($Button2, 768 + 8)
$IP = GUICtrlCreateLabel("", 130, 55, 193, 21)
GUICtrlSetColor(-1,0xffffff)
GUISetState(@SW_SHOW)

Local $SERVERADDRESS = "www.autoitscript2.com"

While 1
    _Metro_HoverCheck_Loop($Form1) ;This hover check has to be added to the main While loop, otherwise the hover effects won't work.
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;=========================================Control-Buttons===========================================
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            _Metro_GUIDelete($Form1) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
            TCPShutdown()
            Exit
        Case $GUI_MAXIMIZE_BUTTON
            GUISetState(@SW_MAXIMIZE)
        Case $GUI_RESTORE_BUTTON
            GUISetState(@SW_RESTORE)
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
            _Metro_FullscreenToggle($Form1, $Control_Buttons)
            ;===================================================================================================
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($Form1, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($Form1)
                    Exit
            EndSwitch
        Case $Button2
            _GUIDisable($Form1, 0, 30) ;For better visibility of the MsgBox on top of the first GUI.
            _Metro_MsgBox(0, "Metro MsgBox Example", "Button 2 clicked. (Button with 3 secs timeout)", 400, 11, $Form1, 3) ; with 3 secs timeout
            _GUIDisable($Form1)
        Case $Button1
            #cs
            _GUIDisable($Form1, 0, 30)
            _Metro_MsgBox(0, "Metro MsgBox Example", "Press ok to set progressbar.", 350, 11, $Form1)
            _GUIDisable($Form1)
            For $i = 0 To 85 Step +2
                Sleep(1)
                _Metro_SetProgress($Progress1, $i)
            Next
            _GUIDisable($Form1, 0, 30)
            Local $Select_YesNo = _Metro_MsgBox(4, "Metro MsgBox Example", "Select yes to create a second GUI.", 350, 11, $Form1)
            If $Select_YesNo = "Yes" Then _SecondGUI()
            _GUIDisable($Form1)
            #ce
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd


Func _SecondGUI()
    Local $Form2 = _Metro_CreateGUI("Example2", 600, 400, -1, -1, True)

    ;Add control buttons
    Local $Control_Buttons_2 = _Metro_AddControlButtons(True, True, True, True)

    ;Set variables for control buttons
    Local $GUI_CLOSE_BUTTON = $Control_Buttons_2[0]
    Local $GUI_MAXIMIZE_BUTTON = $Control_Buttons_2[1]
    Local $GUI_RESTORE_BUTTON = $Control_Buttons_2[2]
    Local $GUI_MINIMIZE_BUTTON = $Control_Buttons_2[3]
    Local $GUI_FULLSCREEN_BUTTON = $Control_Buttons_2[4]
    Local $GUI_FSRestore_BUTTON = $Control_Buttons_2[5]
    Local $Button1 = _Metro_CreateButton("Close", 250, 340, 100, 40)
    GUICtrlSetResizing($Button1, 768 + 8)
    GUISetState(@SW_SHOW)

    While 1
        _Metro_HoverCheck_Loop($Form2) ;Add hover check in loop
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $Button1
                _Metro_GUIDelete($Form2) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
                Return 0
            Case $GUI_MAXIMIZE_BUTTON
                GUISetState(@SW_MAXIMIZE)
            Case $GUI_RESTORE_BUTTON
                GUISetState(@SW_RESTORE)
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
                _Metro_FullscreenToggle($Form2, $Control_Buttons_2)
        EndSwitch
    WEnd
EndFunc   ;==>_SecondGUI

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($IP, "Error code: " & @error)
    Else
        GUICtrlSetData($IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

 

also no problems:

Time for resolve: 37.4138078896741
Time for resolve: 4.10688525681313
Time for resolve: 3.32032425001504

the problem is TCPNameToIP, if used with a string that isn't a URL  than it's frozen using a non existing  URL it resolve fast.   So @BB_19 did good job.

Edited by AutoBert
Link to comment
Share on other sites

On 30/07/2016 at 2:21 PM, AutoBert said:

Meanwhile tested with:

==============================================================================================
; Name ..........: MetroGUI UDF Example
; Version .......: v4.3
; Author ........: BB_19
; ===============================================================================================================================

;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling):
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so /rm /pe

;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling())
#AutoIt3Wrapper_Res_HiDpi=y

#NoTrayIcon
#include "MetroGUI-UDF\MetroGUI_UDF.au3"

;=======================================================================Creating the GUI===============================================================================
;Set Theme
_SetTheme("DarkBlue") ;See MetroThemes.au3 for selectable themes or to add more

;Enable high DPI support: Detects the users DPI settings and resizes GUI and all controls to look perfectly sharp.
_Metro_EnableHighDPIScaling() ; Note: Requries "#AutoIt3Wrapper_Res_HiDpi=y" for compiling. To see visible changes without compiling, you have to disable dpi scaling in compatibility settings of Autoit3.exe

            TCPStartup()
;Create resizable Metro GUI
$Form1 = _Metro_CreateGUI("Example", 500, 300, -1, -1, True)

;Add/create control buttons to the GUI
$Control_Buttons = _Metro_AddControlButtons(True, True, True, True, True) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True

;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected.
$GUI_CLOSE_BUTTON = $Control_Buttons[0]
$GUI_MAXIMIZE_BUTTON = $Control_Buttons[1]
$GUI_RESTORE_BUTTON = $Control_Buttons[2]
$GUI_MINIMIZE_BUTTON = $Control_Buttons[3]
$GUI_FULLSCREEN_BUTTON = $Control_Buttons[4]
$GUI_FSRestore_BUTTON = $Control_Buttons[5]
$GUI_MENU_BUTTON = $Control_Buttons[6]
;======================================================================================================================================================================

;Create  Buttons
$Button1 = _Metro_CreateButton("Button Style 1", 105, 245, 130, 40)
$Button2 = _Metro_CreateButtonEx("Button Style 2", 255, 245, 130, 40)


;Create an Array containing menu button names
Dim $MenuButtonsArray[4] = ["Settings", "About", "Contact", "Exit"]

;Set resizing options for the controls so they don't change in size or position. This can be customized to match your gui perfectly for resizing. See AutoIt Help file.
GUICtrlSetResizing($Button1, 768 + 8)
GUICtrlSetResizing($Button2, 768 + 8)
$IP = GUICtrlCreateLabel("", 130, 55, 193, 21)
GUICtrlSetColor(-1,0xffffff)
GUISetState(@SW_SHOW)

Local $SERVERADDRESS = "www.autoitscript2.com"

While 1
    _Metro_HoverCheck_Loop($Form1) ;This hover check has to be added to the main While loop, otherwise the hover effects won't work.
    $nMsg = GUIGetMsg()
    Switch $nMsg
        ;=========================================Control-Buttons===========================================
        Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON
            _Metro_GUIDelete($Form1) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
            TCPShutdown()
            Exit
        Case $GUI_MAXIMIZE_BUTTON
            GUISetState(@SW_MAXIMIZE)
        Case $GUI_RESTORE_BUTTON
            GUISetState(@SW_RESTORE)
        Case $GUI_MINIMIZE_BUTTON
            GUISetState(@SW_MINIMIZE)
        Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
            _Metro_FullscreenToggle($Form1, $Control_Buttons)
            ;===================================================================================================
        Case $GUI_MENU_BUTTON
            Local $MenuSelect = _Metro_MenuStart($Form1, $GUI_MENU_BUTTON, 150, $MenuButtonsArray, "Segoe UI", 9, 0) ; Opens the metro Menu. See decleration of $MenuButtonsArray above.
            Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
                Case "0"
                    ConsoleWrite("Returned 0 = Settings button clicked." & @CRLF)
                Case "1"
                    ConsoleWrite("Returned 1 = About button clicked." & @CRLF)
                Case "2"
                    ConsoleWrite("Returned 2 = Contact button clicked." & @CRLF)
                Case "3"
                    ConsoleWrite("Returned 3 = Exit button clicked." & @CRLF)
                    _Metro_GUIDelete($Form1)
                    Exit
            EndSwitch
        Case $Button2
            _GUIDisable($Form1, 0, 30) ;For better visibility of the MsgBox on top of the first GUI.
            _Metro_MsgBox(0, "Metro MsgBox Example", "Button 2 clicked. (Button with 3 secs timeout)", 400, 11, $Form1, 3) ; with 3 secs timeout
            _GUIDisable($Form1)
        Case $Button1
            #cs
            _GUIDisable($Form1, 0, 30)
            _Metro_MsgBox(0, "Metro MsgBox Example", "Press ok to set progressbar.", 350, 11, $Form1)
            _GUIDisable($Form1)
            For $i = 0 To 85 Step +2
                Sleep(1)
                _Metro_SetProgress($Progress1, $i)
            Next
            _GUIDisable($Form1, 0, 30)
            Local $Select_YesNo = _Metro_MsgBox(4, "Metro MsgBox Example", "Select yes to create a second GUI.", 350, 11, $Form1)
            If $Select_YesNo = "Yes" Then _SecondGUI()
            _GUIDisable($Form1)
            #ce
            HostToIP($SERVERADDRESS)
    EndSwitch
WEnd


Func _SecondGUI()
    Local $Form2 = _Metro_CreateGUI("Example2", 600, 400, -1, -1, True)

    ;Add control buttons
    Local $Control_Buttons_2 = _Metro_AddControlButtons(True, True, True, True)

    ;Set variables for control buttons
    Local $GUI_CLOSE_BUTTON = $Control_Buttons_2[0]
    Local $GUI_MAXIMIZE_BUTTON = $Control_Buttons_2[1]
    Local $GUI_RESTORE_BUTTON = $Control_Buttons_2[2]
    Local $GUI_MINIMIZE_BUTTON = $Control_Buttons_2[3]
    Local $GUI_FULLSCREEN_BUTTON = $Control_Buttons_2[4]
    Local $GUI_FSRestore_BUTTON = $Control_Buttons_2[5]
    Local $Button1 = _Metro_CreateButton("Close", 250, 340, 100, 40)
    GUICtrlSetResizing($Button1, 768 + 8)
    GUISetState(@SW_SHOW)

    While 1
        _Metro_HoverCheck_Loop($Form2) ;Add hover check in loop
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON, $Button1
                _Metro_GUIDelete($Form2) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs!
                Return 0
            Case $GUI_MAXIMIZE_BUTTON
                GUISetState(@SW_MAXIMIZE)
            Case $GUI_RESTORE_BUTTON
                GUISetState(@SW_RESTORE)
            Case $GUI_MINIMIZE_BUTTON
                GUISetState(@SW_MINIMIZE)
            Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON
                _Metro_FullscreenToggle($Form2, $Control_Buttons_2)
        EndSwitch
    WEnd
EndFunc   ;==>_SecondGUI

Func HostToIP($Server)
    $tdStart = TimerInit()
    $sIPAddress = TCPNameToIP($SERVER)
    If @error Then
        GUICtrlSetData($IP, "Error code: " & @error)
    Else
        GUICtrlSetData($IP, $sIPAddress)
    EndIf
    ConsoleWrite('Time for resolve: ' & TimerDiff($tdStart) & @CRLF)
EndFunc   ;==>HostToIP

 

also no problems:

Time for resolve: 37.4138078896741
Time for resolve: 4.10688525681313
Time for resolve: 3.32032425001504

the problem is TCPNameToIP, if used with a string that isn't a URL  than it's frozen using a non existing  URL it resolve fast.   So @BB_19 did good job.

Appolgise for the delay on my response. I am using it with a name rather than URL, so is there no way of getting rid of the freeze when using it with a name rather than a url?

Link to comment
Share on other sites

A URL is a name. And you misread his entire point. If you send the function a URL that isn't valid, then it's going to freeze until it times out.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

1 hour ago, BrewManNH said:

A URL is a name. And you misread his entire point. If you send the function a URL that isn't valid, then it's going to freeze until it times out.

Thank you for clarifying, is there anyway i can test that its valid first without having the window freeze?

If there is a function available for this whats the info page url for it for me to read up on?

Link to comment
Share on other sites

On 30.07.2016 at 11:29 AM, cookiemonster said:

TCPNameToIP is part of #include <_sql.au3>

Try to use ADO.au3 :

https://www.autoitscript.com/forum/files/file/389-adoau3-udf/

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
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
 Share

×
×
  • Create New...