Sign in to follow this  
Followers 0
Donald8282

Useful things to practice

4 posts in this topic

Hello, I was just wondering what are some useful things to practice for AutoIt. I'm not really working on a project right now but what are some useful things to learn for the future? =D thanks in adv. -Donald8282

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I would suggest GUI and For statements.

Have you messed with GUI's a lot or no?

I wrote some detailed GUI tutorials, if you want to have a look. Here is a link to the folder I have uploaded, you can check and see if you want to try any.

Gui Tutorial Folder

Here's a script from it, for Context Menu's.

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

#CS
In this script we will learn how to create, add to and create sub menu context menus.
#CE

Global $HelpItem, $SubMenuItem

_CreateGui() ; Tell the script to run the function: _CreateGui()

Func _CreateGui() ; Begin the function _CreateGui()
    GuiCreate("GUI Tutorial: Context Menu",300,200) ; Create the Gui
    $ContextMenu = GuiCtrlCreateContextMenu() ; Create a context menu and assign it to var ContextMenu. To create the context menu control do not enclose anything in the ()
    $HelpItem = GuiCtrlCreateMenuItem("Help", $ContextMenu) ; Create a menu item in the context menu labeled "Help" with the var HelpItem
    $SubMenu = GuiCtrlCreateMenu("SubMenu", $ContextMenu) ; Create a second menu inside the context menu.
    $SubMenuItem = GuiCtrlCreateMenuItem("SubMenu Help", $SubMenu) ; Create a second help item inside the sub menu of the context menu.
    GuiSetState() ; Display the GUI
EndFunc ; End the function _CreateGui

While 1 ; Start a while statement to capture the commands from the GUI
    $GuiMsg = GuiGetMsg() ; Set the var GuiMsg to the commands from the GUI
    Select ; Begin a select statement
    Case $GuiMsg = $HelpItem ; An "If" statement to tell the script what to do if the HelpItem var is called.
        MsgBox(0, "GUI Tutorial: Context Menu", "You pressed the 'Help' item in the main context menu") ; A MsgBox displaying that the HelpItem var was selected
    Case $GuiMsg = $SubMenuItem ; An "If" statement to tell the script what to do if the SubMenuItem var is called instead.
        MsgBox(0, "GUI Tutorial: Context Menu", "You pressed the 'Help' item in the sub context menu")  ; A MsgBox displaying that the SubMenuItem var was selected
    Case $GuiMsg = $Gui_Event_Close ; A "If" statement for the command from the GUI, in this case the close button on the GUI
        Exit ; Tell the program to exit if the command from the GUI is infact the close button
    EndSelect ; End the select statement
WEnd ; End the while statement

They are all pretty small, but should suffice in learning what you need to know.

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Yeah, I've messed with GUI. This is my latest thing I've been making with GUI...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         Donald Whitten

#ce ----------------------------------------------------------------------------

;============make delete menu for fav. ex. Google >

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <IE.au3>
#Include <WinAPI.au3>
#Include <GuiListView.au3>
#Include <String.au3>
#Include <Date.au3>


$cURL2 = ""
$TitleGet1 = ""
$Settings = @ScriptDir & "\myBrowserSettings.ini"
$len = ""

If FileExists($Settings) Then
Else
    IniWrite($Settings, "Home", "Website", "http://www.google.com/")
    IniWrite($Settings, "BGPic", "Location", "")
EndIf

_IEErrorHandlerRegister()

$E_Browser = _IECreateEmbedded()
$Home = IniRead($Settings, "Home", "Website", "")
$Main = IniRead($Settings, "BGPic", "Location", "")

$Hour = @HOUR
$Minute = @MIN

$AM_PM = ""

If @HOUR >= 12 Then
    $AM_PM = "PM"
ElseIf @HOUR < 12 Then
    $AM_PM = "AM"
EndIf

If @HOUR > 12 Then
    $Hour -= 12
ElseIf @HOUR = 00 Then
    $Hour = 12
EndIf


$Mon = _DateToMonth(@MON, 1)

Dim $myFavsMenu[1] ;Array to hold favorite controls
$myFavsMenu[0] = 0 ;This will hold a count

$Window = GUICreate("", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $GUI_SS_DEFAULT_GUI + $WS_MAXIMIZEBOX + $WS_SIZEBOX)
GUISetBkColor(0x00FF00)
GUISetState()
GUISetState(@SW_MAXIMIZE)

$Height_Width = WinGetPos($Window)
$Background = GUICtrlCreatePic($main, 0, 0, $Height_Width[2], $Height_Width[3], 0, $GUI_WS_EX_PARENTDRAG)

$M_File = GUICtrlCreateMenu("File")
$F_SavePage = GUICtrlCreateMenuItem("Save Page", $M_FILE)
GUICtrlCreateMenuItem("", $M_File)
$F_Exit = GUICtrlCreateMenuItem("Exit", $M_FILE)

$M_Tools = GUICtrlCreateMenu("Tools")
$T_Pass = GUICtrlCreateMenuItem("Password Creator", $M_Tools)
$T_His = GUICtrlCreateMenuItem("Clear History", $M_Tools)

$M_Fav = GUICtrlCreateMenu("Favorites")
$var = IniReadSection($Settings, "favorites")
If @error Then
Else
    For $c = 1 To $var[0][0]
        $thisFav = GUICtrlCreateMenuItem($var[$c][0], $M_Fav)
        _ArrayAdd($myFavsMenu, $thisFav)
        $myFavsMenu[0] += 1
    Next
EndIf

$M_Help = GUICtrlCreateMenu("Help")
$H_CMD = GUICtrlCreateMenuItem("Commands", $M_Help)
$H_Info = GUICtrlCreateMenuItem("Info", $M_Help)

$B_Home = GUICtrlCreateButton ("Home", 10, 10, 70, 20)
$B_Back = GUICtrlCreateButton ("Back", 90, 10, 70, 20)
$B_Forward = GUICtrlCreateButton("Forward", 170, 10, 70, 20)
$I_URL = GUICtrlCreateInput("", 250, 10, 600, 20)
$B_Go = GUICtrlCreateButton("&Go", 860, 10, 70, 20, $BS_DEFPUSHBUTTON)
$B_Refresh = GUICtrlCreateButton("Refresh", 940, 10, 70, 20)
$I_Time = GUICtrlCreateInput($Hour & ":" & $Minute & " " & $AM_PM & " / " & $Mon & " " & @MDAY & ", " & @YEAR, 1040, 10, 130, 20, $ES_READONLY)
$B_Background = GUICtrlCreateButton ("Background", 1198, 10, 70, 20)
$Browser = GUICtrlCreateObj($E_Browser, 10, 40, $Height_Width[2] - 40, $Height_Width[3] - 120)
Global $P_Progress = GUICtrlCreateProgress(10, 710, 1245, 20)

For $b = $B_Home To $P_Progress
    GUICtrlSetResizing($b, 1)
    GUICtrlSetBkColor($b, 0x000000)
    GUICtrlSetColor($b, 0x00FF00)
Next




$SinkObject = ObjEvent($E_Browser, "IEEvent_")

_IENavigate($E_Browser, $Home)

If $Main = "" Then
    TrayTip("Background", 'Click "Background" to change the background', 1)
Else
EndIf

While 1
    Sleep(10)
    
    ;/////////////////////Title Set////////////////////////
    $TitleGet = _IEPropertyGet($E_Browser, "Title")
    $Title = WinGetTitle($Window)
    
    If $TitleGet1 <> $TitleGet Then
        _WinAPI_SetWindowText($Window, $TitleGet & " - Rocket Browser v1.0 by Donald Whitten.")
        $TitleGet1 = $TitleGet
    EndIf
    
    ;////////////////////Title Set End////////////////////
    
    ;////////////////////URL Set//////////////////////
    
    $cURL = _IEPropertyGet($E_Browser, "locationurl")
    $cURL1 = GUICtrlRead($I_URL)
    
    If $cURL2 <> $cURL Then
        GUICtrlSetData($I_URL, $cURL)
        $cURL2 = $cURL
    EndIf
    
    ;////////////////////URL Set End//////////////////////
    
    ;//////////////////Time / Date///////////////////////////
    
    $Mon = _DateToMonth(@MON, 1)
    
    If @HOUR >= 12 Then
        $AM_PM = "PM"
    ElseIf @HOUR < 12 Then
        $AM_PM = "AM"
    EndIf
    
    If @HOUR = 00 Then
        $Hour = 12
    EndIf
    
    If $Minute <> @MIN Then
        $Minute = @MIN
    If @HOUR > 12 Then
        GUICtrlSetData($I_Time, @HOUR - 12 & ":" & @MIN & " " & $AM_PM & " / " & $Mon & " " & @MDAY & ", " & @YEAR)
    Else
        GUICtrlSetData($I_Time, @HOUR & ":" & @MIN & " " & $AM_PM & " / " & $Mon & " " & @MDAY & ", " & @YEAR)
    EndIf
EndIf
    
    ;///////////////////////Time / Date End/////////////////////

    ;/////////////////////Favorite/////////////////////////////
    HotKeySet("^f", "_Favorite")
    ;/////////////////////Favorite End/////////////////////////
    
    ;/////////////////////Home Set/////////////////////////////
    HotKeySet("^h", "_Home")
    ;/////////////////////Home Set End/////////////////////////

    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
        
    ;//////////////////////////Menu options////////////////////////
    
    Case $msg = $F_Exit
        Exit
        
    Case $msg = $F_SavePage
        _IEAction($E_Browser, "SaveAs")
        
    Case $msg = $T_His
        RunWait ( 'RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2', @ScriptDir, @SW_HIDE )
        RunWait ( 'RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1', @ScriptDir, @SW_HIDE )
        
    Case $msg = $T_Pass
        $PassLen = InputBox("Random Password", "Password length 8 - 12", "8")
        If @error Then
        else
            
        
        If $PassLen > 12 Then
            $PassLen = 12
        ElseIf $PassLen < 8 Then
            $PassLen = 8
        EndIf
        
        $RandPass = _randStr($PassLen)
        MsgBox(64, "Random Password", "Copied to clipboard: " & $RandPass)
        ClipPut($RandPass)
        
        EndIf
        
    Case $msg = $H_Info
        MsgBox(64, "Information", "Creator: Donald Whitten (Donald8274 and Donald8282)." & @CRLF & "This is a freeware product licensed to: " & @UserName & "." & @CRLF & "This product is not intended to be sold.")
        
    Case $msg = $H_CMD
        MsgBox(64, "Commands", "F5: Refresh Page." & @CRLF & "CTRL + F: Favorite the page." & @CRLF & "CTRL + H: Set as home page.")
    
    ;////////////////////////Menu Options End////////////////////////
    
    Case $msg = $GUI_EVENT_MAXIMIZE
        GUICtrlSetResizing($Browser, 1)
        GUICtrlSetResizing($Background, 1)
        
    ;///////////////////////Button Actions//////////////////////////
    
    Case $msg = $B_Go
        $URL = GUICtrlRead($I_URL)
        _IENavigate($E_Browser, $URL)
        
    Case $msg = $B_Home
        _IENavigate($E_Browser, $Home)
        GUICtrlSetState($B_Go, $GUI_FOCUS)
        
    Case $msg = $B_Refresh
        _IEAction($E_Browser, "Refresh")
        GUICtrlSetState($B_Go, $GUI_FOCUS)
        
    Case $msg = $B_Back
        _IEAction($E_Browser, "Back")
        GUICtrlSetState($B_Go, $GUI_FOCUS)
        
    Case $msg = $B_Forward
        _IEAction($E_Browser, "Forward")
        GUICtrlSetState($B_Go, $GUI_FOCUS)
        
    Case $msg = $B_Background
        $Picture = FileOpenDialog("Select a picture...", "C:\Users\Owner\Pictures\Logitech Webcam", "Images (*.jpg;*.bmp)", 1)
        If $Picture <> "" Then
            GUICtrlSetImage($Background, $picture)
            GUICtrlSetState($Browser, $GUI_HIDE)
            GUICtrlSetState($Browser, $GUI_SHOW)
            IniWrite($Settings, "BGPic", "Location", $Picture)
        Else
        EndIf
    ;///////////////////////////Button Actions End/////////////////////////
    EndSelect
    
    For $i = 1 To $myFavsMenu[0]
        If $Msg = $myFavsMenu[$i] Then
            _IENavigate($E_Browser, $var[$i][1])
        EndIf
    Next
    
WEnd

Func IEEvent_ProgressChange($Progress, $ProgressMax)
    $percent = Int(($Progress * 100) / $ProgressMax)
    If $percent >= 0 And $percent <= 100 Then GUICtrlSetData($P_Progress, $percent)
    EndFunc   ;==>IEEvent_ProgressChange
    
Func _Favorite()
    $FavName = InputBox("Favorite", "Create Favorite Name", _IEPropertyGet($E_Browser, "Title"))
    If @error = 1 Then
    Else
    IniWrite($Settings, "Favorites", $FavName, $cURL)
    
    $var = IniReadSection($Settings, "favorites")
    If @error Then
    Else
            $thisFav = GUICtrlCreateMenuItem($FavName, $M_Fav)
            _ArrayAdd($myFavsMenu, $thisFav)
            $myFavsMenu[0] += 1
    EndIf
EndIf
EndFunc

Func _Home()
    IniWrite($Settings, "Home", "Website", _IEPropertyGet($E_Browser, "LocationURL"))
    MsgBox(64, "Home", "Home website set to: " & _IEPropertyGet($E_Browser, "LocationURL"))
    $Home = IniRead($Settings, "Home", "Website", "")
EndFunc

Func _randStr($len)
    $mypasschars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
    $charArr = StringSplit($mypasschars, "")
    Local $str = ""
    For $a = 1 To $len
        $str &= $charArr[(Random(1, $charArr[0], 1))]
    Next
    Return $str
EndFunc   ;==>_randStr

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