Jump to content

First Prog Ever !


Recommended Posts

This is my first Program ever with autoit BE NICE!!

I know its ver basic but its mine lol !

I want my main gui to only have tray icon not show in the task bar if you can help let me know

Have attached the files cos you will need the ini's

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.4.9
    Author: figgler
    
    Script Function:
    Basic Program Launcher .
    
    I want the main gui to only have system tray icon not show on the task bar
    if you can tell me how pm me figgler on the forums
#ce ----------------------------------------------------------------------------
#include <GUIConstants.au3>
#include <GuiList.au3>
#include <misc.au3>
_Singleton("BPL")

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
Opt("TrayMenuMode",1) 

Global $bMinToTray
; Add GUI Globals
Global $AddPath, $AddTitle, $AddParams, $filepath
; Rem GUI Globals
Global $RemList1

; List ini file
$T_ini = @ScriptDir & "\List.ini"
; Settings file
$SettingsFile = @TempDir & "\BPL_Settings.ini"
;Version no.
$Version = "1.0"
; Help file
$HelpFile = "Help.txt"
; Main GUI Title
$MainGUI_Title = "BPL v" & $Version
; Check drive type
$Drive = DriveGetType ( @ScriptDir )

;Get settings if the file exists
If FileExists($SettingsFile) Then
    
    $WinTop = IniRead($SettingsFile, "GUI Position", "Y_Coord", 1) ; Y coord
    $WinLeft = IniRead($SettingsFile, "GUI Position", "X_Coord", 1) ; X coord
Else
    IniWrite($SettingsFile, "General", "F_Run", "0")
    IniWrite($SettingsFile, "General", "Version", $Version)
    $WinTop = @DesktopHeight / 4 ; Y coord
    $WinLeft = @DesktopWidth / 4 ; X coord
EndIf

; Tray menu
$TrayOpen = TrayCreateItem("Open")
TrayCreateItem("")
$TrayExit = TrayCreateItem("Exit")
TraySetState()

; Main GUI
$MainGUI = GUICreate($MainGUI_Title, 200, 420, $WinLeft, $WinTop)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "ToTray")
; Menu
$MenuFile = GUICtrlCreateMenu("&File")
$MenuAddtoList = GUICtrlCreateMenuItem("Add Item", $MenuFile)
GUICtrlSetOnEvent($MenuAddtoList, "AddGUI")
$MenuRemove = GUICtrlCreateMenuItem("Remove Item", $MenuFile)
GUICtrlSetOnEvent($MenuRemove, "RemGUI")
$MenuExit = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUICtrlSetOnEvent($MenuExit, "CLOSE")
$MenuExtras = GUICtrlCreateMenu("Startup")
$MenuAddStart = GUICtrlCreateMenuItem("Add Startup", $MenuExtras)
GUICtrlSetOnEvent($MenuAddStart, "Add_Startup")
$MenuDelStart = GUICtrlCreateMenuItem("Del Startup", $MenuExtras)
GUICtrlSetOnEvent($MenuDelStart, "Del_Startup")
$MenuWin = GUICtrlCreateMenu("Computer")
$WinReboot = GUICtrlCreateMenuItem("Reboot", $MenuWin)
GUICtrlSetOnEvent($WinReboot, "Reboot_pc")
$WinShutdown = GUICtrlCreateMenuItem("Shutdown", $MenuWin)
GUICtrlSetOnEvent($WinShutdown, "Shutdown_Pc")
$MenuHelp = GUICtrlCreateMenu("Help")
$MenuHelpFile = GUICtrlCreateMenuItem("Help", $MenuHelp)
GUICtrlSetOnEvent($MenuHelpFile, "Open_Help")
$MenuAbout = GUICtrlCreateMenuItem("About", $MenuHelp)
GUICtrlSetOnEvent($MenuAbout, "AboutGUI")
; First list
$List1 = GUICtrlCreateList("", 5, 5, 190, 365)
GUICtrlSetOnEvent($List1, "List1_Click")
GUICtrlSetTip($List1, "Click the name of the program to launch")
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetCursor($List1, 0)
$Exit = GUICtrlCreateButton("Exit", 77, 370, 46, 25, 0)
GUICtrlSetOnEvent($Exit, "CLOSE")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetCursor($Exit, 0)
GUISetState(@SW_SHOW)
; call list1
List1()


While 1
    
$TrayMsg = TrayGetMsg()
Switch $TrayMsg
    Case $TrayOpen
        Open()
    Case $TrayExit
        Exit
EndSwitch

WEnd

; Add Item GUI
Func AddGUI()
    $AddGUI = GUICreate("Add Item", 225, 195, $WinLeft - 25, $WinTop, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), -1, $MainGUI)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
    $AddTitle = GUICtrlCreateInput("", 8, 24, 121, 21)
    $AddPath = GUICtrlCreateInput("", 8, 72, 121, 21)
    $AddSearch = GUICtrlCreateButton("Search", 136, 72, 75, 25, 0)
    GUICtrlSetOnEvent($AddSearch, "SearchBTN")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AddLabel3 = GUICtrlCreateLabel("Parameters", 8, 100, 63, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AddParams = GUICtrlCreateInput("", 8, 119, 121, 21)
    $AddBTN = GUICtrlCreateButton("Add", 28, 154, 75, 25, 0)
    GUICtrlSetOnEvent($AddBTN, "AddBTN")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AddCancel = GUICtrlCreateButton("Cancel", 108, 154, 75, 25, 0)
    GUICtrlSetOnEvent($AddCancel, "CLOSE")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AddLabel1 = GUICtrlCreateLabel("Menu Title", 8, 8, 63, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AddLabel2 = GUICtrlCreateLabel("Select Executable", 8, 55, 107, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    Disable()
EndFunc ;==>AddGUI

Func SearchBTN()
    $filepath = FileOpenDialog("Select the Executable", "C:\", "Executables (*.exe)")
    GUICtrlSetData($AddPath, $filepath)
EndFunc ;==>SearchBTN

; AddBTN
Func AddBTN()
    If GUICtrlRead($AddTitle) = "" Then
        MsgBox(48, "Title", "Title Box Is Empty !")
    ElseIf GUICtrlRead($AddPath) = "" Then
        MsgBox(48, "EXE Path", "No EXE path Set !")
    Else
        $KVData = "Path=" & GUICtrlRead($AddPath) & @LF & "Params=" & GUICtrlRead($AddParams) & @LF
        IniWriteSection($T_ini, GUICtrlRead($AddTitle), $KVData )
        ;Reload the list
        _GUICtrlListClear($List1)
        List1() 
        Close()
    EndIf
EndFunc ;==>AddBTN  

; Remove Item GUI
Func RemGUI()
    $RemGUI = GUICreate("Remove Item", 216, 229, $WinLeft - 16, $WinTop, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), -1, $MainGUI)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
    $RemList1 = GUICtrlCreateList("", 8, 32, 193, 110)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $RemCancel = GUICtrlCreateButton("Cancel", 112, 184, 75, 25, 0)
    GUICtrlSetOnEvent($RemCancel, "CLOSE")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $RemBTN = GUICtrlCreateButton("Remove", 16, 184, 75, 25, 0)
    GUICtrlSetOnEvent($RemBTN, "RemBTN")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $RemCheck = GUICtrlCreateCheckbox("Remove Files and Folders ?", 16, 152, 177, 17)
    GUICtrlSetOnEvent($RemCheck, "NotImp")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $RemLabel1 = GUICtrlCreateLabel("Select Item To Remove", 8, 8, 137, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    List2()
    Disable()
EndFunc ;==>RemGUI

; Remove Button
Func RemBTN()
        $RemSelected = GUICtrlRead($RemList1)
        $RemFiles = IniRead($T_ini, $RemSelected, "Path", 1)
        ;Del ini section
        IniDelete($T_ini, $RemSelected)
        ;MsgBox(48, "Item Removed", $RemSelected & " Removed!")
        ;Reload the lists
        _GUICtrlListClear($List1)
        List1()
        _GUICtrlListClear($RemList1)
        List2()
        Close()
EndFunc ;==>RemBTN

; Remove list
Func List2()
    $RemSections = IniReadSectionNames($T_ini)
    If @error Then
        MsgBox(48, "Error", "Error occurred, cant find the " & $T_ini & " file.")
    Else
        For $i = 1 To $RemSections[0]
            GUICtrlSetData($RemList1, $RemSections[$i], Default)
        Next
    EndIf
EndFunc   ;==>List2

; About GUI
Func AboutGUI()
    $AboutGUI = GUICreate("About BPL", 186, 169, $WinLeft, $WinTop, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS), -1, $MainGUI)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
    $AboutEdit = GUICtrlCreateEdit("", 9, 8, 167, 119, $ES_READONLY)
    GUICtrlSetData(-1, StringFormat("Basic Program Launcher is what it says you can add programs to the list for 1 click launch.\r\nYou can add BLP to startup if it is on a fixed Drive only! \r\nFree to Use/Modify and Redistribute."))
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $AboutOK = GUICtrlCreateButton("OK", 48, 134, 75, 25, 0)
    GUICtrlSetOnEvent($AboutOK, "CLOSE")
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    Disable()
EndFunc

; Loops the ini file to add to list
Func List1()
    $Sections = IniReadSectionNames($T_ini)
    If @error Then
        MsgBox(48, "Error", "The " & $T_ini & " file is either missing or has no entries !")
    Else
        For $i = 1 To $Sections[0]
            GUICtrlSetData($List1, $Sections[$i], Default)
        Next
    EndIf
EndFunc   ;==>List1

; List1 Click event
Func List1_Click()

            $Selected = GUICtrlRead($List1)
            $ExePath = IniRead($T_ini, $Selected, "Path", "No EXE Path")
            $ExeParams = IniRead($T_ini, $Selected, "Params", "No Params")
        If $ExePath = "No EXE Path" Then
                ;do nothing could not get A Not to work!
        Else
                If $ExeParams = "No Params" Then
                    $ExeParams = ""
                EndIf
            Run($ExePath & " " & $ExeParams)
        EndIf

EndFunc ;==>List1_Click

; min to tray and hide
Func ToTray()
            $bMinToTray = 1
            WinSetState($MainGUI, '', @SW_HIDE)
            Opt('TrayIconHide', 0)
            TraySetState(4)
EndFunc ;==>ToTray
    
; open main gui
Func Open()
            Opt('TrayIconHide', 0)
            WinSetState($MainGUI, '', @SW_RESTORE)
            WinSetState($MainGUI, '', @SW_SHOW)
            $bMinToTray = 0
            TraySetState(8)
EndFunc ;==>Open

;Enable main GUI
Func Enable()
        If $bMinToTray = 0 Then
        GUISetState(@SW_ENABLE, $MainGUI)
        EndIf
EndFunc ;==>Enable
    
;Disable Main Gui
Func Disable()
        If $bMinToTray = 0 Then
        GUISetState(@SW_DISABLE, $MainGUI)
        EndIf
EndFunc ;==>Disable
    
; Add to system startup
Func Add_Startup()
    If IsAdmin() = 0 Then
     MsgBox(48, "Admin Rights", "You Do Not Have Admin Rights")
Else
    
    If $Drive = "Fixed" Then
        RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "BPL", "REG_SZ", @ScriptFullPath)
        MsgBox(48, "Starup", "Added BPL to " & @UserName & "'s Startup")
    Else
        MsgBox(48, "Starup", "Can't Add to startup as BPL is running on a "& $Drive & " Drive !")
    EndIf
EndIf
EndFunc ;==>Add_Startup 

; Remove from system startup
Func Del_Startup()
        If IsAdmin() = 0 Then
     MsgBox(48, "Admin Rights", "You Do Not Have Admin Rights")
Else
    If $Drive = "Fixed" Then
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "BPL")
            MsgBox(48, "Starup", "Removed BPL From " & @UserName & "'s Startup")
    Else
        MsgBox(48, "Starup", "Should not have BPL on Startup as it is running on a "& $Drive & " Drive !")
    EndIf
EndIf   
EndFunc ;==>Del_Startup

; Open Help file
Func Open_Help()
            If FileExists($HelpFile) Then
                Run("notepad.exe " & $HelpFile)
            Else
                MsgBox(48, "Help", "The " & $HelpFile & " Is Missing !")
            EndIf
EndFunc ;==>Open_Help   

; Reboot pc
Func Reboot_Pc()
        Shutdown(6)
EndFunc ;==>Reboot

; Shutdown pc
Func Shutdown_Pc()
        Shutdown(9)
EndFunc ;==>Shutdown pc

; Not implimented yet function
Func NotImp()
    MsgBox(48, "Function", "Not implimented yet Sorry!")
EndFunc ;==>NotImp

; Close and Exit Function
Func CLOSE()
    
  If @GUI_WinHandle = $MainGUI Then ; We can exit if called from the main gui
        $pos = WinGetPos($MainGUI_Title)
        ; Update the ini with last position of the main gui
        IniWrite($SettingsFile, "GUI Position", "X_Coord", $pos[0])
        IniWrite($SettingsFile, "GUI Position", "Y_Coord", $pos[1])
      Exit
  Else
    Enable()
    GUIDelete(@GUI_WINHANDLE) ; Only close the child gui if Close is called outside main gui
  EndIf
  
EndFunc ;==>CLOSE

BPL_Source_Files.rar

Link to comment
Share on other sites

Extended style: $WS_EX_TOOLWINDOW

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

No, he doesn't mean that sandman.

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Those two are correct, congratulations with your first script!

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

Thanks guys

I Tried that

$MainGUI = GUICreate($MainGUI_Title, 200, 420, $WinLeft, $WinTop, $WS_EX_TOOLWINDOW )oÝ÷ Ù8ZµÈh¦Æâ¶Ê~Ø^èÖ®¶­sbb33c´ÖäuTÒuT7&VFRb33c´ÖäuTõFFÆRÂ#ÂC#Âb33cµväÆVgBÂb33cµvåF÷ÂÓÂb33cµu5ôUõDôôÅtäDõr

That works but makes the main frame of the gui funny small and square ?

Sorry for being thick lol !!

Link to comment
Share on other sites

The second attempt is the correct way to do it. I'm not sure about the side effects. Screenshot, maybe?

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

That works but makes the main frame of the gui funny small and square ?

Sorry for being thick lol !!

its because its a toolwindow

$MainGUI = GUICreate($MainGUI_Title, 200, 420, $WinLeft, $WinTop, $WS_EX_TOOLWINDOW )

its an extended style so this is not correct,

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...