Sign in to follow this  
Followers 0
shay

Need help to add GUI+Refresh button

4 posts in this topic

i use this small script to see my IP etc...

i want to move this code to GUI and so i can do "refresh" to the IP etc...

i need Exit and refresh button.

#include <INet.au3>

$Public = _GetIP()
if $Public = 0 Then
    $Public     = "Error local IP"
EndIf

$lan1 = @IPAddress1
$lan2 = @IPAddress2
$name = @ComputerName

MsgBox(0, "IpConfig", "Public IP: " &$Public & @CRLF & @CRLF & "Local IP: " & $lan1 & @CRLF & @CRLF & "Local LAN 2: " & $lan2 & @CRLF & @CRLF & "PC Name: " & $name )

thanks


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites



shay,

i want to move this code to GUI and so i can do "refresh" to the IP etc...

i need Exit and refresh button.

If you can write the code you posted, you should be able to figure out how to write a GUI and 2 buttons. Look in the Help file under GUICtrlCreateButton and there is a nice example of how to do it.

Give it go yourself and come back if you run into difficulties. :(

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

The GUI was no problem

but i don't have any idea how to execute the "Refresh"

so the IP will refresh.

#include <INet.au3>
GuiCreate("IP",230,200,209,29)
$Public = _GetIP()
if $Public = 0 Then
    $Public     = "Error local IP"
EndIf

$lan1 = @IPAddress1
$lan2 = @IPAddress2
$name = @ComputerName

$button1=GuiCtrlCreateButton("Exit",24,160,87,34)
$button2=GuiCtrlCreateButton("Refresh",121,160,87,34)
$label1=GuiCtrlCreateLabel("Public IP: " &$Public,50,40,136,15)
$label2=GuiCtrlCreateLabel("Local IP: " & $lan1,50,60,136,15)
$label3=GuiCtrlCreateLabel("Local LAN 2: " & $lan2,50,80,136,15)
$label4=GuiCtrlCreateLabel("PC Name: " & $name,50,110,136,15)
GuiSetState()

While 1
$msg=GuiGetMsg()
If $msg=-3 Then Exit
If $msg=$button1 Then button1()
If $msg=$button2 Then button2()
Wend

Func button1()
    Exit
EndFunc

Func button2()
    ;need to refresh the labels
EndFunc

"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

shay,

but i don't have any idea how to execute the "Refresh"

What did you do to get the values in the first place?

If you were to put that code into a function, you could call it both initially and when the "Refresh" button is pressed. You can use GUICtrlSetData to change the content of the labels after the "Refresh". Like this:

#include <GUIConstantsEx.au3>
#include <INet.au3>

$Public = Get_IP()
$lan1 = @IPAddress1
$lan2 = @IPAddress2
$name = @ComputerName

GUICreate("IP", 230, 200, 209, 29)
$button1 = GUICtrlCreateButton("Exit", 24, 160, 87, 34)
$button2 = GUICtrlCreateButton("Refresh", 121, 160, 87, 34)
$label1 = GUICtrlCreateLabel("Public IP: " & $Public, 50, 40, 136, 15)
$label2 = GUICtrlCreateLabel("Local IP: " & $lan1, 50, 60, 136, 15)
$label3 = GUICtrlCreateLabel("Local LAN 2: " & $lan2, 50, 80, 136, 15)
$label4 = GUICtrlCreateLabel("PC Name: " & $name, 50, 110, 136, 15)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button1
            button1()
        Case $button2
            button2()
    EndSwitch
WEnd

Func button1()
    Exit
EndFunc   ;==>button1

Func button2()
    GUICtrlSetData($label1, "Public IP: " & Get_IP())
    GUICtrlSetData($label2, "Local IP: " & @IPAddress1)
    GUICtrlSetData($label3, "Local LAN 2: " & @IPAddress2)
    GUICtrlSetData($label4, "PC Name: " & @ComputerName)
EndFunc   ;==>button2

Func Get_IP()
    Local $Public = _GetIP()
    If $Public = 0 Then
        $Public = "Error local IP"
    EndIf
    Return $Public
EndFunc   ;==>Get_IP

You will see I have changed your list of If statements for a Switch structure - this makes the code clearer (in the opinion of most) and actually faster!

M23


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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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