Jump to content

can't understand this (GUI) i need help pls


Recommended Posts

hello guys

when i want the button to do a task lets say run notepad for example, we will write this

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 305, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 88, 64, 417, 153)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   Run("Notepad")
EndSwitch
WEnd

ok now i want my script to run this code when i press on the button ( i took this code from this forum )

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icon.ico
#AutoIt3Wrapper_Res_Comment=DynDns (TM) Updater
#AutoIt3Wrapper_Res_Description=Updates your Dynamic IP on the DYNDNS(R) server automatically. Warning, this software is not an official product of DYNDNS(R).
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Dragonlair 2011 - 2012
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <inet.au3>
#Include <string.au3>
#include <Constants.au3>
If WinExists("Dyndns Auto-Updater") Then
    Exit
EndIf
Global  $User, $Pass, $Domain, $TimeInput, $EditTime
$DefaultTimer = 300
Opt("GUIEventOptions",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Opt("GUIOnEventMode", 1)
TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
$Form1 = GUICreate("Dyndns Auto-Updater", 276, 182, 0, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize")
GUICtrlCreateLabel("UserName", 8, 5, 54, 17)
$Input1 = GUICtrlCreateInput("", 8, 20, 257, 21)
GUICtrlCreateLabel("Password", 8, 48, 50, 17)
$Input2 = GUICtrlCreateInput("", 8, 65, 257, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
GUICtrlCreateLabel("DomainName", 8, 96, 68, 17)
$Input3 = GUICtrlCreateInput("", 8, 114, 257, 21)
GUICtrlCreateLabel("Time to update", 8, 144, 75, 17)
$Label5 = GUICtrlCreateLabel("", 88, 144, 31, 17)
GUICtrlSetTip($Label5, "Number in seconds to check for an IP change, click me to change my value")
GUICtrlSetOnEvent($Label5, "EditTime")
GUICtrlCreateLabel("Seconds.", 120, 144, 49, 17)
$Button1 = GUICtrlCreateButton("Update Now", 184, 136, 75, 25)
GUICtrlSetOnEvent($Button1, "DNSUpdate")
GUICtrlCreateLabel("Status;", 8, 160, 37, 17)
$Label8 = GUICtrlCreateLabel("Undefined", 56, 160, 190, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Run on startup", 176, 0, 97, 17)
GUICtrlSetOnEvent($Checkbox1, "StartupCheckBox")
GUISetState(@SW_SHOW)
If RegRead("HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun","DynDnsUpdater") Then GUICtrlSetState($Checkbox1, $GUI_CHECKED)
If RegRead("HKLMSOFTWAREDynDnsUpdater", "TimerSet") Then $DefaultTimer = RegRead("HKLMSOFTWAREDynDnsUpdater", "TimerSet")

If $CmdLine[0] Then
    If $CmdLine[1] = "-HIDE" Then Minimize()
EndIf
If RegRead("HKLMSOFTWAREDynDnsUpdater", "UserName") Then
    $User = RegRead("HKLMSOFTWAREDynDnsUpdater", "UserName")
    $Pass = _StringEncrypt(0,RegRead("HKLMSOFTWAREDynDnsUpdater", "Pass"),"7EF12",1)
    $Domain = RegRead("HKLMSOFTWAREDynDnsUpdater", "Domain")
    GUICtrlSetData($Input1,$User)
    GUICtrlSetData($Input2,$Pass)
    GUICtrlSetData($Input3,$Domain)
    Call ("DNSUpdate")
EndIf
$i = $DefaultTimer
AdlibRegister("Timer",1000)
While 1
    Sleep(100)
WEnd
Func EditTime()
$EditTime = GUICreate("Input time value", 220, 95, 30, 30)
GUICtrlCreateLabel("Please Input the time in seconds to check for an IP change", 8, 8, 204, 25)
$TimeInput = GUICtrlCreateInput("12345", 91, 39, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$OK = GUICtrlCreateButton("OK", 72, 64, 75, 25)
GUICtrlSetOnEvent($OK, "EditOK")
GUISetState(@SW_SHOW)
GUICtrlSetData($TimeInput,$DefaultTimer)
EndFunc
Func EditOK()
    $DefaultTimer = GUICtrlRead($TimeInput)
    If $DefaultTimer < 60 then
        MsgBox(64,"Error","Incorrect number" & @LF & "wrote a number preferably 60 - 3600")
    Else
    $i = $DefaultTimer
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "TimerSet", "REG_SZ", $DefaultTimer)
    GUIDelete($EditTime)
    EndIf
EndFunc
Func StartupCheckBox()
    If GUICtrlRead($Checkbox1) = 1 Then
    RegWrite("HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun", "DynDnsUpdater", "REG_SZ", @ScriptDir & "DynDnsUpdater.exe -HIDE")
    Else
    RegDelete("HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun","DynDnsUpdater")
    EndIf
EndFunc
Func Close()
    Exit
EndFunc
Func DNSUpdate()
    GUICtrlSetState($Button1, $GUI_DISABLE)
    If $User <> GUICtrlRead($Input1) Or $Pass <> GUICtrlRead($Input2) Or $Domain <> GUICtrlRead($Input3) Then
    $User = GUICtrlRead($Input1)
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "UserName", "REG_SZ", $User)
    $Pass = GUICtrlRead($Input2)
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "Pass", "REG_SZ", _StringEncrypt(1,$Pass,"7EF12",1))
    $Domain = GUICtrlRead($Input3)
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "Domain", "REG_SZ", $Domain)
    DYNDNSUpdate()
    Else
    CheckIP()
    EndIf
    GUICtrlSetState($Button1, $GUI_ENABLE)
EndFunc
Func CheckIP()
    GUICtrlSetData($Label8,"Checking IP")
    GUICtrlSetColor($Label8, 0x0000FF)
    Sleep(3000)
    If RegRead("HKLMSOFTWAREDynDnsUpdater", "LastIP") <> _GetIP() Then
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "LastIP", "REG_SZ", _GetIP())
    DYNDNSUpdate()
    Else
    GUICtrlSetData($Label8,"Same IP, no need to update the DNS")
    GUICtrlSetColor($Label8, 0x008000)
    $i = $DefaultTimer
EndIf
EndFunc
Func DYNDNSUpdate()
    GUICtrlSetData($Label8,"Requesting Update :" & _GetIP())
    GUICtrlSetColor($Label8, 0x0000FF)
    $DnsStatement = _InetGetSource("http://" & $User & ":" & $Pass & "@members.dyndns.org/nic/update?hostname=" & $Domain & "&myip=" & _GetIP() & "&wildcard=NOCHG&backmx=NOCHG&mx=NOCHG&system=dyndns")
    If $DnsStatement = "nochg " & _GetIP() Then
    GUICtrlSetData($Label8,"DNS update requested successful")
    GUICtrlSetColor($Label8, 0x008000)
    EndIf
    If $DnsStatement = "good " & _GetIP() Then
    GUICtrlSetData($Label8,"DNS update requested successful")
    GUICtrlSetColor($Label8, 0x008000)
    EndIf
    If $DnsStatement = "nohost" Then
    GUICtrlSetData($Label8,"Specified hostname does not exist")
    GUICtrlSetColor($Label8, 0xFF0000)
    EndIf
    If $DnsStatement = "badauth" Then
    GUICtrlSetData($Label8,"Invalid user/password")
    GUICtrlSetColor($Label8, 0xFF0000)
    EndIf
    If $DnsStatement = "abuse" Then
    GUICtrlSetData($Label8,"Please wait 5 min to next update")
    GUICtrlSetColor($Label8, 0xFF0000)
    EndIf
    If $DnsStatement = "" Then
    GUICtrlSetData($Label8,"Fill the fields of domain and user password")
    GUICtrlSetColor($Label8, 0xFF0000)
    EndIf
    $i = $DefaultTimer
    RegWrite("HKLMSOFTWAREDynDnsUpdater", "LastIP", "REG_SZ", _GetIP())
EndFunc
Func Timer()
    $i = $i -1
    GUICtrlSetData($Label5,$i)
    If $i = 0 Then
    Call ("DNSUpdate")
    $i = $DefaultTimer
    EndIf
EndFunc
Func Minimize()
    GuiSetState(@SW_MINIMIZE)
    GuiSetState(@SW_HIDE)
    TraySetState(1)
    TraySetToolTip ("DynDns Updater - Click here to restore window")
    Traytip ("DynDns Updater", "Click here to restore window", 5)
EndFunc
Func SpecialEvent()
    GuiSetState(@SW_RESTORE)
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc

and how to set a command for main menu and how to run the above code on it ?

i hope any one help me :D

Edited by TarwadaC4
Link to comment
Share on other sites

Where did you 'take' the code from? Please post the link.

About your question you firstly can't use Run how you're trying to do it, Run is used for running an external program not code.You firstly need to learn the basics of AutoIt before you should continue. I would suggest learning about Functions in the Help file & reading these tutorials >> http://www.autoitscript.com/wiki/Tutorials

OR

Compile that code and then rename it as 'DNSSomething.exe' and then use Run.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Please see my second suggestion with compiling the code as an EXE.

Edit: Typo.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

OK, as I've mentioned before you need to really explain your intentions instead of us giving you a bunch of ideas for you to turn around and say "I know this & that!"

What about having that code in a file called Something.au3 and then using the commandline parameter /AutoIt3ExecuteScript? You can see how to achieve this here >>

OR

Failing that you're going to have to understand the functions of that code and work out how the application updates DynDNS. It will be good exercise and to get you started I'll give you a hint >> _InetGetSource("http://.....

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Pretty much what guinness has already suggested.

You first just need to decide on whether you want it to launch a compiled or non-compiled - "DynDns ™ Updater".

Then, in the first script you posted (for launching notepad), you will simply put in the information to run "DynDns ™ Updater".

If you try to fail and succeed which have you done?AutoIt Forum Search

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...