Sign in to follow this  
Followers 0

Buttons, Labels and Clicks, OH MY

5 posts in this topic

Posted · Report post

I have an application that works fine, except for one tiny issue. I've had to expand the number of tasks to the point that I've had to shrink the buttons down a bit. Each button has a label describing what it does. The issue is that you cannot click where the label or text is.. only on the outskirts of the button to have it perform its task. Is there something I can do to make the label clickable, or make it so that it doesn't mask the button below it? Here is a snippet with the label and button creation:


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")

Share this post


Link to post
Share on other sites



Posted (edited) · Report post

Actually, the issue seems to start at the HPV-20 button. The buttons above it, and the exit button at the bottom seem to have no issue. I'm sure at this point it's something screwey I've missed.


; 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
Added tags

Share this post


Link to post
Share on other sites

Posted · Report post

Please add code blocks to that script, or use [autoit ] [/autoit ] tags. It's very hard to follow that.Remove the spaces from the tags before using them.

Share this post


Link to post
Share on other sites

Posted · Report post

smedley89,

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

Share this post


Link to post
Share on other sites

Posted · Report post

Thank you very much! I figured it had to be something simple I was overlooking!

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

  • Recently Browsing   0 members

    No registered users viewing this page.