Jump to content

Im stumped


rawrr
 Share

Recommended Posts

Well, I want this to when typed create a trayitem with the name typed in (Check...)

Then I want it to save it.. So every time the person loads it will have the same settings.. (Not working...)

Then I want it to when the created tray item is clicked to bring up another input box and type 2 other things and then save those to the tray item so when clicked it will write something in a file..(Got the write in file part but not the other..)

Please help..

Heres my script..

#include <GUIConstants.au3>
Opt("TrayMenuMode",1)

$GUI = Guicreate("", 100 , 100, 200, 200)
$label = Guictrlcreatelabel("Name:", 15, 8, 70, 20)
$input = GUICtrlCreateInput("", 15, 25, 70, 20)
$button = GUICtrlCreateButton("Ok", 15, 75, 70, 20)
GUISetState()

While 1
    Switch GuiGetMsg()
        Case $btn
            traycreateitem (GuiCtrlRead($file))
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by rawrr
Link to comment
Share on other sites

I got it to work! Hey, I fixed it :) Here ya go.

Although its kinda funny, that your Variables dont even match...I fixed it...

#include <GUIConstants.au3>
#include <File.au3>
Opt("TrayMenuMode",1)

$GUI = Guicreate("", 100 , 100, 200, 200)
$label = Guictrlcreatelabel("Name:", 15, 8, 70, 20)
$input = GUICtrlCreateInput("", 15, 25, 70, 20)
$button = GUICtrlCreateButton("Ok", 15, 75, 70, 20)
GUISetState()
If FileExists("File.txt") Then
Dim $Array
_FileReadToArray("File.txt", $Array)
For $x = 1 to $Array[0]
    TrayCreateItem($Array[$x])
Next
EndIf
While 1
    Switch GuiGetMsg()
        Case $button
            traycreateitem (GuiCtrlRead($input))
            $f = FileOpen("File.txt", 1)
            FileWriteLine($f, GUICtrlRead($input))
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Just run the script, make a few tray items, and then rerun it, and it sets them automatically :) enjoy!

Edited by Swift
Link to comment
Share on other sites

Ty, I changed my variables at the last minute but forgot to change all of em..

EDIT : When I click the tray item it doesn't bring up another GUI where theres 2 input boxes.

Edited by rawrr
Link to comment
Share on other sites

Hi,

I'm not sure what your trying to exactly do, but I gather each new tray menu item will be running a program or something?

Try this crude throw together script if you like.. Just drop your file or directory into either input fields, it'll use the file/folder as the tray item name and use the drop path as the program to run when you click the tray item.

#include <GUIConstants.au3>
#Include <Constants.au3>

Opt("TrayMenuMode",1)
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)

Global $Ini = @ScriptDir & "\settings.ini"

$Gui = Guicreate("Drag & Drop File", 200 , 150, -1, -1, -1, BitOr($WS_EX_TOPMOST,$WS_EX_ACCEPTFILES))
GUISetOnEvent($GUI_EVENT_DROPPED, "GuiEvent", $Gui)
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiEvent", $Gui)


GUICtrlCreateGroup("Tray Item Name:", 5, 5, 190, 50)
$ItemName = GUICtrlCreateInput("", 15, 25, 170, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

GUICtrlCreateGroup("What To Run:", 5, 60, 190, 50)
$WhatToRun = GUICtrlCreateInput("", 15, 80, 170, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

$AddItem = GUICtrlCreateButton("Add Item To Tray", 30, 120, 140, 20)
GUICtrlSetOnEvent(-1, "GuiEvent") 

GUISetState(@SW_HIDE, $Gui)

TrayCreateItem("Add Item",-1, 49)
TrayItemSetOnEvent(-1, "TrayEvent")
TrayCreateItem("Exit",-1, 50)
TrayItemSetOnEvent(-1, "TrayEvent")
TraySetState()

LoadTray()

While 1
   Sleep(100)
WEnd

Func GuiEvent()
    Switch @GUI_CtrlId
        Case $AddItem
            If GuiCtrlRead($ItemName) <> "" And FileExists(GuiCtrlRead($WhatToRun)) Then
                TrayCreateItem("", -1, 0)
                TrayCreateItem(GuiCtrlRead($ItemName), -1, 0)
                TrayItemSetOnEvent(-1, "TrayEvent")
                IniWrite($Ini, "TrayItems", GuiCtrlRead($ItemName), GuiCtrlRead($WhatToRun))
                GUICtrlSetData($ItemName, "")
                GUICtrlSetData($WhatToRun, "")
                GUISetState(@SW_HIDE, $Gui)
            EndIf   
        Case $GUI_EVENT_DROPPED
            Local $FileName = StringTrimLeft(@GUI_DragFile, StringInStr(@GUI_DragFile, "\", 0, -1))
            If @GUI_DropId = $ItemName Then
                GUICtrlSetData($ItemName, $FileName)
                GUICtrlSetData($WhatToRun, @GUI_DragFile)
            ElseIf @GUI_DropId = $WhatToRun Then
                GUICtrlSetData($ItemName, $FileName)
            EndIf   
        Case $GUI_EVENT_CLOSE
            GUICtrlSetData($ItemName, "")
            GUICtrlSetData($WhatToRun, "")
            GUISetState(@SW_HIDE, $Gui)
    EndSwitch
EndFunc

Func TrayEvent()
    Switch TrayItemGetText(@TRAY_ID)
        Case "Add Item"
            GUISetState(@SW_SHOW, $Gui)
        Case "Exit"
            Exit
        Case Else
            Local $IR = IniRead($Ini, "TrayItems", TrayItemGetText(@TRAY_ID), "") 
            If FileExists($IR) Then ShellExecute($IR)
    EndSwitch
EndFunc

Func LoadTray()
    $IRS = IniReadSection($Ini, "TrayItems")
    If Not @error Then
        For $i = 1 To $IRS[0][0]
            TrayCreateItem("", -1, 0)
            TrayCreateItem($IRS[$i][0], -1, 0)
            TrayItemSetOnEvent(-1, "TrayEvent") 
        Next
    EndIf
    If Not FileExists($Ini) Then GUISetState(@SW_SHOW, $Gui)
EndFunc
Hope it gives you some idea of what your trying to do.

Cheers

Edited by smashly
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...