Jump to content

Need help with CD Tray App


imani
 Share

Recommended Posts

The following is the code of my app. But the problem is that I do not want to show the app when minimized and also the Tray Menu has problems. The trayitem should be unchecked when you click it if it is already checked and should be working for all my drives

#include <GuiConstants.au3>
#include <Constants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1); no default menu (Paused/Exit)
Global $cdd,$i,$j=0,$d[10]


$tray = GuiCreate("CDTray Eject OR Close", 240, 100,-1, -1 )
GUIsetIcon(@SystemDir & "\shell32.dll", 12)
TraySetIcon(@SystemDir & "\shell32.dll",12)

$eject = GuiCtrlCreateButton("Eject", 10, 20, 70, 20)
GUICtrlSetOnEvent($eject, "eject")
$close = GuiCtrlCreateButton("Close", 100, 20, 70, 20)
GUICtrlSetState($close,$GUI_FOCUS)
GUICtrlSetOnEvent($close, "close")
GUICtrlCreateGroup("",15,50,200,40)
GUICtrlCreateLabel("Select Defualt Drive",20,64,-1,-1)
$default = GUICtrlCreateCombo("", 120, 60, 45, 20,$CBS_DROPDOWNLIST)
$tc= TrayCreateItem("Close")
TrayCreateItem("")
$te = TrayCreateItem("Eject")
TrayCreateItem("")
$ddrive = TrayCreateMenu("Selected Drive")
TrayCreateItem("")
$show = TrayCreateItem("Show the Interface")
GUICtrlSetOnEvent($show, "show")
TrayCreateItem("")
$quit = TrayCreateItem("Quit")

$cdd = DriveGetDrive("CDROM")
For $i=1 to $cdd[0]
GUICtrlSetData($default,$cdd[$i],$cdd[1]) 
$d[$j] = TrayCreateItem($cdd[$i],$ddrive)
$j+=1
Next
TrayItemSetState($d[0],$Tray_checked)

;68 unchecked
;65 checked
GuiSetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
TraySetState()
While 1
    $read = GUICtrlRead($default)
    $msg = TrayGetMsg()
    For $i=0 to $cdd[0]
    If $msg = $d[$i] Then
        If TrayItemGetState($d[$i]) =  68 Then          
            TrayItemSetState($d[$i],$Tray_checked)
        Else
        TrayItemSetState($d[$i],$Tray_unchecked)
        EndIf
    EndIf
    Next
    Select
        Case $msg = $quit
            Exit
        Case $msg = $tc
        Case $msg = $te
            
    EndSelect
WEnd

func eject()
    CDTray($read,"open")
EndFunc
Func close()
    CDTray($read,"close")
EndFunc
Func defualt()
        EndFunc
Func SpecialEvents()  
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE   
            GUISetState($tray,@SW_HIDE)
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE           
    EndSelect   
EndFunc
Func show()
    GUISetState($tray,@SW_SHOW)
    EndFunc
Edited by imani
Link to comment
Share on other sites

You have a confused mix of Event/Msg modes.

First, the GUI and the Tray have separate modes. If you want the whole thing in Event mode then you have to to Opt("TrayOnEventMode", 1) in addition to Opt("GuiOnEventMode", 1).

Second, you have to set the event functions separately, with GuiSetOnEvent() for the GUI, GuiCtrlSetOnEvent() for the GUI controls, and TraySetOnEvent() for the tray items.

Third, there should be no GuiGetMsg() or TrayGetMsg() at all if you are running in Event mode. Generally just an idle loop like this:

While 1
      Sleep(20) ; Wait for events
WEnd

The event functions will take care of everything else.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...