Buttons, Labels and Clicks, OH MY
#1
Posted 06 July 2012 - 09:48 PM
GuiCtrlCreateLabel(" (Click to set for SFC)", 5, 50, 135, 30)
$SFCButton = GUICtrlCreateButton("SFC", 130,40, 120, 30)
;the following line creates a tooltip
GuiCtrlSetTip(-1, "Sets IP to" & @cr & "169.254.196.200"& @cr &"255.255.255.0")
#2
Posted 06 July 2012 - 09:56 PM
; OS: XP, Windows 7 ; Author: Ken Stillings ; #include <GUIConstants.au3> ;declaring the variables needed for user input Global $IP = "" Global $SN = "" Global $GW = "" Global $Error = "" ;creating the GUI and related buttons GUICreate("CBE IP Change", 255, 390) GuiCtrlCreateLabel(" (Click to set for ASA)", 5, 15, 140, 30) $ASAButton = GUICtrlCreateButton("ASA", 130, 5, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Sets IP to" & @cr &"192.168.31.200"& @cr &"255.255.255.0"& @cr &"192.168.31.31") GuiCtrlCreateLabel(" (Click to set for SFC)", 5, 50, 135, 30) $SFCButton = GUICtrlCreateButton("SFC", 130,40, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Sets IP to" & @cr & "169.254.196.200"& @cr &"255.255.255.0") GuiCtrlCreateLabel(" (Click to set Custom IP)", 5, 85, 180, 30) $CUSTButton = GUICtrlCreateButton("Custom", 130,75, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "This button allows you to enter"& @cr & "your own IP information") GuiCtrlCreateLabel("(Click to set for Standard)", 5, 120, 135, 30) $STDButton = GUICtrlCreateButton("Standard", 130,110, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Restores your IP to DHCP which"& @cr &"pulls the IP from the router") GuiCtrlCreateLabel(" (Click to ping Sapphire)", 5, 155, 155, 30) $PNGSapphire = GUICtrlCreateButton("Sapphire", 130,145, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Pings the Sapphire"& @cr &"IP 192.168.31.11") GuiCtrlCreateLabel(" (Click to ping HPV-20)", 5, 190, 190, 30) $PNGhpv = GUICtrlCreateButton("HPV-20", 130,180, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Pings the HPV-20"& @cr &"IP 192.168.31.1") GuiCtrlCreateLabel(" (Click to ping Router)", 5, 225, 225, 30) $PNGrouter = GUICtrlCreateButton("ROUTER", 130,215, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Pings the router at "& @cr &"IP 192.168.31.31") GuiCtrlCreateLabel("(Run IPCONFIG /Release)", 5, 260, 225, 30) $IPrelease = GUICtrlCreateButton("/RELEASE", 130,250, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Runs the"& @cr &"IPCONFIG /release command") GuiCtrlCreateLabel(" (Run IPCONFIG /Renew)", 5, 295, 225, 30) $IPrenew = GUICtrlCreateButton("/RENEW", 130,285, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Runs the"& @cr &"IPCONFIG /renew command") GuiCtrlCreateLabel(" (Run IPCONFIG /All)", 5, 330, 225, 30) $IPall = GUICtrlCreateButton("/ALL", 130,320, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "Runs the IPCONFIG /ALL"& @cr &"command, showing current"& @cr &"IP configuration") $EXITButton = GUICtrlCreateButton("Exit", 130,355, 120, 30) ;the following line creates a tooltip GuiCtrlSetTip(-1, "This button exits the program") ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $ASAButton Run ('c:windowssystem32netsh.exe') sleep (1000) send ('interface IP set address name="Local Area Connection" source=static 192.168.31.200 255.255.255.0 192.168.31.31 1+{enter}') sleep (1000) send ('exit+{enter}') sleep (1000) $answer = MsgBox(0, "IP Address", "Your IP address is set.") Case $msg = $SFCButton Run ('c:windowssystem32netsh.exe') sleep (1000) send ('interface ip set address name="Local Area Connection" source=static 169.254.196.200 255.255.255.0+{enter}') sleep (1000) send ('exit+{enter}') sleep (1000) $answer = MsgBox(0, "IP Address", "Your IP address is set.") Case $msg = $STDButton Run ('c:windowssystem32netsh.exe') sleep (1000) send ('interface ip set dns name="Local Area Connection" source=DHCP+{enter}') sleep (1000) send ('interface ip set wins name="Local Area Connection" source=DHCP+{enter}') sleep (1000) send ('interface ip set address name="Local Area Connection" source=DHCP+{enter}') sleep (1000) send ('exit+{enter}') sleep (500) $answer = MsgBox(0, "IP Address", "Your IP address is set.") Case $msg = $CUSTButton GetIP() GetSN() GetGW() Run ('c:windowssystem32netsh.exe') sleep (1000) if $GW <>"" then send ('interface ip set address "Local Area Connection" static ' & $IP & ' ' & $SN &' ' & $GW & ' 1+{enter}') else send ('interface ip set address "Local Area Connection" static ' & $IP &' ' & $SN &'+{enter}') endif sleep (1000) send ('exit+{enter}') sleep (500) $answer = MsgBox(0, "IP Address", "Your IP address is set.") Case $msg = $PNGSapphire Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ping 192.168.31.11+{enter}') Case $msg = $PNGhpv Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ping 192.168.31.1+{enter}') Case $msg = $PNGrouter Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ping 192.168.31.31+{enter}') Case $msg = $IPrelease Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ipconfig /release+{enter}') Case $msg = $IPrenew Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ipconfig /renew+{enter}') Case $msg = $IPall Run ('c:windowssystem32cmd.exe') sleep (1000) send ('ipconfig /all+{enter}') Case $msg = $EXITButton exit EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop ;ends the application if the red X is clicked on the gui Wend ;~~~~~~~~~~~~~~~~~~~ func GetIP() ;remove any information in the variables $IP = "" ;accepts user input $IP = InputBox("Enter IP Address", "Please enter the IP address in this format: xxx.xxx.xxx.xxx", "", "", 0,0) If @Error = 1 then Exit endIf ValidIP($IP) EndFunc ;~~~~~~~~~~~~~~~~~~~~~ func GetSN() $SN = "" ;clearing any previous data $SN = InputBox("Enter Subnet", "Please enter the subnet mask in this format: xxx.xxx.xxx.xxx", "", "", 0,0) If @Error = 1 then Exit EndIf ValidSN($SN) EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~ func GetGW() $GW = "" ;clearing any previous data $GW = InputBox("Enter Gateway", "Please enter the gateway in this format: xxx.xxx.xxx.xxx - or leave blank", "", "", 0,0) If $GW <> "" then ValidGW($GW) ; only needs to check for validity if field is not left blank. EndIf endfunc ;~~~~~~~~~~~~~~~~~~~~~~ func ValidIP($IPcheck) $arrayIP = StringSplit($IPcheck, ".") if $arrayIP[0] <> 4 then msgbox(16, "Error", "Invalid IP range.") GetIP() elseif $arrayIP[1] < 1 OR $arrayIP[1] > 255 then msgbox(16, "Error", "Invalid IP range.") GetIP() elseif $arrayIP[2] > 255 then msgbox(16, "Error", "Invalid IP range.") GetIP() elseif $arrayIP[3] > 255 then msgbox(16, "Error", "Invalid IP range.") GetIP() elseif $arrayIP [4]> 255 then msgbox(16, "Error", "Invalid IP range.") GetIP() EndIf $count = 1 while $count < 5 if (StringIsDigit($arrayIP[$count]) ==0) then msgbox(16, "Error", "No letters or special characters allowed.") GetIP() EndIf $count = $count +1 wend endFunc ;~~~~~~~~~~~~~~~~~~~~~~~~ func ValidSN($SNCheck) $arraySN = StringSplit($SNcheck, ".") if $arraySN[0] <> 4 then ;the first element in the split array gives the number of elements. If there's more or less than 4 elements (192.168.1, or 192.124.23.1.2) then there is an error. msgbox(16, "Error", "Invalid Subnet range.") GetSN() elseif $arraySN[1] < 1 OR $arraySN[1] > 255 then msgbox(16, "Error", "Invalid Subnet range.") GetSN() elseif $arraySN[2] > 255 then msgbox(16, "Error", "Invalid Subnet range.") GetSN() elseif $arraySN[3] > 255 then msgbox(16, "Error", "Invalid Subnet range.") GetSN() elseif $arraySN[4]> 255 then msgbox(16, "Error", "Invalid Subnet range.") GetIP() EndIf ;the array containing the information from the entry starts at element 1, not 0. Here, we run through a loop looking for non numeric entries. $count = 1 while $count < 5 if (StringIsDigit($arraySN[$count]) ==0) then msgbox(16, "Error", "No letters or special characters allowed.") GetIP() EndIf $count = $count +1 wend endFunc ;~~~~~~~~~~~~~~~~~~~~~~~~ func ValidGW($GWCheck) $arrayGW = StringSplit($GWcheck, ".") if $arrayGW[0] <> 4 then msgbox(16, "Error", "Invalid IP range.") GetGW() elseif $arrayGW[1] < 1 OR $arrayGW[1] > 255 then msgbox(16, "Error", "Invalid IP range.") GetGW() elseif $arrayGW[2] > 255 then msgbox(16, "Error", "Invalid IP range.") GetGW() elseif $arrayGW[3] > 255 then msgbox(16, "Error", "Invalid IP range.") GetGW() elseif $arrayGW[4]> 255 then msgbox(16, "Error", "Invalid IP range.") GetGW() EndIf ;the array containing the information from the entry starts at element 1, not 0. Here, we run through a loop looking for non numeric entries. $count = 1 while $count < 5 if (StringIsDigit($arrayGW[$count]) ==0) then msgbox(16, "Error", "No letters or special characters allowed.") GetGW() EndIf $count = $count +1 wend endFunc
Edited by Melba23, 07 July 2012 - 08:40 AM.
Added tags
#3
Posted 06 July 2012 - 10:22 PM
How to ask questions the smart way!
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 editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#4
Posted 07 July 2012 - 08:54 AM
You have a slight overlap between the labels and the buttons - AutoIt then does not know which control you are trying to click as so actions neither. I have added colour to the labels to show you.
The solution is to reduce the size of the label - as I have shown with the "ASA" button. Then there is no overlap and the button works across its width.
; OS: XP, Windows 7 ; Author: Ken Stillings ; #include <GUIConstants.au3> ;declaring the variables needed for user input Global $IP = "" Global $SN = "" Global $GW = "" Global $Error = "" ;creating the GUI and related buttons GUICreate("CBE IP Change", 255, 390) GUICtrlCreateLabel(" (Click to set for ASA)", 5, 15, 125, 30) GUICtrlSetBkColor(-1, 0x00FF00) $ASAButton = GUICtrlCreateButton("ASA", 130, 5, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Sets IP to" & @CR & "192.168.31.200" & @CR & "255.255.255.0" & @CR & "192.168.31.31") GUICtrlCreateLabel(" (Click to set for SFC)", 5, 50, 135, 30) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetBkColor(-1, 0xFF0000) $SFCButton = GUICtrlCreateButton("SFC", 130, 40, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Sets IP to" & @CR & "169.254.196.200" & @CR & "255.255.255.0") GUICtrlCreateLabel(" (Click to set Custom IP)", 5, 85, 180, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $CUSTButton = GUICtrlCreateButton("Custom", 130, 75, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "This button allows you to enter" & @CR & "your own IP information") GUICtrlCreateLabel("(Click to set for Standard)", 5, 120, 135, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $STDButton = GUICtrlCreateButton("Standard", 130, 110, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Restores your IP to DHCP which" & @CR & "pulls the IP from the router") GUICtrlCreateLabel(" (Click to ping Sapphire)", 5, 155, 155, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $PNGSapphire = GUICtrlCreateButton("Sapphire", 130, 145, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Pings the Sapphire" & @CR & "IP 192.168.31.11") GUICtrlCreateLabel(" (Click to ping HPV-20)", 5, 190, 190, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $PNGhpv = GUICtrlCreateButton("HPV-20", 130, 180, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Pings the HPV-20" & @CR & "IP 192.168.31.1") GUICtrlCreateLabel(" (Click to ping Router)", 5, 225, 225, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $PNGrouter = GUICtrlCreateButton("ROUTER", 130, 215, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Pings the router at " & @CR & "IP 192.168.31.31") GUICtrlCreateLabel("(Run IPCONFIG /Release)", 5, 260, 225, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $IPrelease = GUICtrlCreateButton("/RELEASE", 130, 250, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Runs the" & @CR & "IPCONFIG /release command") GUICtrlCreateLabel(" (Run IPCONFIG /Renew)", 5, 295, 225, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $IPrenew = GUICtrlCreateButton("/RENEW", 130, 285, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Runs the" & @CR & "IPCONFIG /renew command") GUICtrlCreateLabel(" (Run IPCONFIG /All)", 5, 330, 225, 30) GUICtrlSetBkColor(-1, 0xFF0000) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $IPall = GUICtrlCreateButton("/ALL", 130, 320, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "Runs the IPCONFIG /ALL" & @CR & "command, showing current" & @CR & "IP configuration") $EXITButton = GUICtrlCreateButton("Exit", 130, 355, 120, 30) ;the following line creates a tooltip GUICtrlSetTip(-1, "This button exits the program") ; GUI MESSAGE LOOP GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $ASAButton ;Run('c:windowssystem32netsh.exe') ;Sleep(1000) ;Send('interface IP set address name="Local Area Connection" source=static 192.168.31.200 255.255.255.0 192.168.31.31 1+{enter}') ;Sleep(1000) ;Send('exit+{enter}') ;Sleep(1000) $answer = MsgBox(0, "ASA", "Your IP address is set.") Case $msg = $SFCButton ;Run('c:windowssystem32netsh.exe') ;Sleep(1000) ;Send('interface ip set address name="Local Area Connection" source=static 169.254.196.200 255.255.255.0+{enter}') ;Sleep(1000) ;Send('exit+{enter}') ;Sleep(1000) $answer = MsgBox(0, "SFC", "Your IP address is set.") Case $msg = $STDButton ;Run('c:windowssystem32netsh.exe') ;Sleep(1000) ;Send('interface ip set dns name="Local Area Connection" source=DHCP+{enter}') ;Sleep(1000) ;Send('interface ip set wins name="Local Area Connection" source=DHCP+{enter}') ;Sleep(1000) ;Send('interface ip set address name="Local Area Connection" source=DHCP+{enter}') ;Sleep(1000) ;Send('exit+{enter}') ;Sleep(500) $answer = MsgBox(0, "STD", "Your IP address is set.") Case $msg = $CUSTButton ;GetIP() ;GetSN() ;GetGW() ;Run('c:windowssystem32netsh.exe') ;Sleep(1000) ;If $GW <> "" Then ; Send('interface ip set address "Local Area Connection" static ' & $IP & ' ' & $SN & ' ' & $GW & ' 1+{enter}') ;Else ; Send('interface ip set address "Local Area Connection" static ' & $IP & ' ' & $SN & '+{enter}') ;EndIf ;Sleep(1000) ;Send('exit+{enter}') ;Sleep(500) $answer = MsgBox(0, "Cust", "Your IP address is set.") Case $msg = $PNGSapphire Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ping 192.168.31.11+{enter}') Case $msg = $PNGhpv Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ping 192.168.31.1+{enter}') Case $msg = $PNGrouter Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ping 192.168.31.31+{enter}') Case $msg = $IPrelease Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ipconfig /release+{enter}') Case $msg = $IPrenew Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ipconfig /renew+{enter}') Case $msg = $IPall Run('c:windowssystem32cmd.exe') Sleep(1000) Send('ipconfig /all+{enter}') Case $msg = $EXITButton Exit Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd
All clear?
M23
Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display
RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options
GUIListViewEx - Insert, delete, move, drag and sort ListView items
#5
Posted 09 July 2012 - 01:04 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users





