There is an example code in AutoIT on CD tray controller.
After runnig this script, you will see a small bar on the Right corner of the screen. Move the moue point on to it. then you will see the window for controlling.
Code: Select all
#include-once
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <Timers.au3>
#include <StaticConstants.au3>
Opt('MustDeclareVars', 1)
Local $Button1, $Button2, $Button3, $Button4, $Button5, $btn1, $btn2, $btn3, $btn4, $btn5, $nMsg, $1, $2, $3, $4, $hi, $Form1, $romz, $1 = False, $2 = False, $3 = False, $4 = False, $5 = False
Local $Label1, $Label2, $Label3, $Label4, $Label5, $W, $Form,$Label, $a_mpos
$romz = DriveGetDrive("CDROM")
For $x = 1 To $romz[0]
CDTray($romz[$x], "close")
Next
$W = @DesktopWidth - 200
up()
Func up()
$Form = GUICreate("Hidden", 116, 10, $W, 0, BitOR($WS_POPUP, $WS_BORDER, $DS_MODALFRAME), $WS_EX_TOPMOST)
$Label = GUICtrlCreateLabel("........", 2, 2,50, 10)
GUISetState(@SW_SHOW,$Form)
EndFunc
While 1
$a_mpos = GUIGetCursorInfo($Form1)
If $a_mpos[4] = $Label Then
GUISetState(@SW_HIDE,$Form)
ExitLoop
EndIf
WEnd
Switch $romz[0]
Case "0"
MsgBox(0, "Error", "No CD Drives Found")
Exit
Case "1"
$1 = True
$hi = 50
Case "2"
$2 = True
$hi = 90
Case "3"
$3 = True
$hi = 130
Case "4"
$4 = True
$hi = 170
Case "5"
$5 = True
$hi = 210
EndSwitch
_lb()
Func _lb()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 116, $hi, $W, 0, BitOR($WS_POPUP, $WS_BORDER, $DS_MODALFRAME), $WS_EX_TOPMOST)
Switch $romz[0]
Case "0"
MsgBox(0, "Error", "No CD Drives Found")
Exit
Case "1"
$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
Case "2"
$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
Case "3"
$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
Case "4"
$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
$Button4 = GUICtrlCreateButton("Open (" & StringUpper($romz[4]) & ") ", 8, 136, 97, 25, 0)
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
Case "5"
$Button1 = GUICtrlCreateButton("Open (" & StringUpper($romz[1]) & ") ", 8, 16, 97, 25, 0)
$Button2 = GUICtrlCreateButton("Open (" & StringUpper($romz[2]) & ") ", 8, 56, 97, 25, 0)
$Button3 = GUICtrlCreateButton("Open (" & StringUpper($romz[3]) & ") ", 8, 96, 97, 25, 0)
$Button4 = GUICtrlCreateButton("Open (" & StringUpper($romz[4]) & ") ", 8, 136, 97, 25, 0)
$Button5 = GUICtrlCreateButton("Open (" & StringUpper($romz[5]) & ") ", 8, 176, 97, 25, 0)
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)
EndSwitch
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Form1, "int", 1000, "long", 0x00040004);slide in from left
GUISetState(@SW_SHOW, $Form1)
#EndRegion ### END Koda GUI section ###
;~ _Timer_SetTimer($Form1, 1000, "_update()")
EndFunc ;==>_lb
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If $1 = True Or $2 = True Or $3 = True Or $4 = True Or $5 = True Then
$btn1 = _GUICtrlButton_GetText($Button1)
If $btn1 = "Close (" & $romz[1] & ") " Then
CDTray($romz[1], "close")
_GUICtrlButton_SetText($Button1, "Open (" & StringUpper($romz[1]) & ") ")
$Label1 = GUICtrlCreateLabel("", 8, 0, 100, 17, $SS_CENTER)
Else
CDTray($romz[1], "open")
_GUICtrlButton_SetText($Button1, "Close (" & StringUpper($romz[1]) & ") ")
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
EndIf
EndIf
Case $Button2
If $2 = True Or $3 = True Or $4 = True Or $5 = True Then
$btn2 = _GUICtrlButton_GetText($Button2)
If $btn2 = "Close (" & $romz[2] & ") " Then
CDTray($romz[2], "close")
_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[2]) & ") ")
$Label2 = GUICtrlCreateLabel("", 8, 40, 100, 17, $SS_CENTER)
Else
CDTray($romz[2], "open")
_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[2]) & ") ")
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
EndIf
EndIf
Case $Button3
If $3 = True Or $4 = True Or $5 = True Then
$btn3 = _GUICtrlButton_GetText($Button3)
If $btn3 = "Close (" & $romz[3] & ") " Then
CDTray($romz[3], "close")
_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[3]) & ") ")
$Label3 = GUICtrlCreateLabel(""), 8, 80, 100, 17, $SS_CENTER)
Else
CDTray($romz[3], "open")
_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[3]) & ") ")
$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
EndIf
EndIf
Case $Button4
If $4 = True Or $5 = True Then
$btn4 = _GUICtrlButton_GetText($Button4)
If $btn4 = "Close (" & $romz[4] & ") " Then
CDTray($romz[4], "close")
_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[4]) & ") ")
$Label4 = GUICtrlCreateLabel("", 8, 120, 100, 17, $SS_CENTER)
Else
CDTray($romz[4], "open")
_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[4]) & ") ")
$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
EndIf
EndIf
Case $Button5
If $5 = True Then
$btn5 = _GUICtrlButton_GetText($Button5)
If $btn5 = "Close (" & $romz[5] & ") " Then
CDTray($romz[5], "close")
_GUICtrlButton_SetText($Button2, "Open (" & StringUpper($romz[5]) & ") ")
$Label5 = GUICtrlCreateLabel("", 8, 160, 100, 17, $SS_CENTER)
Else
CDTray($romz[5], "open")
_GUICtrlButton_SetText($Button2, "Close (" & StringUpper($romz[5]) & ") ")
$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)
EndIf
EndIf
EndSwitch
WEnd
Func _update()
$Label1 = GUICtrlCreateLabel(DriveGetLabel($romz[1]), 8, 0, 100, 17, $SS_CENTER)
$Label2 = GUICtrlCreateLabel(DriveGetLabel($romz[2]), 8, 40, 100, 17, $SS_CENTER)
$Label3 = GUICtrlCreateLabel(DriveGetLabel($romz[3]), 8, 80, 100, 17, $SS_CENTER)
$Label4 = GUICtrlCreateLabel(DriveGetLabel($romz[4]), 8, 120, 100, 17, $SS_CENTER)
$Label5 = GUICtrlCreateLabel(DriveGetLabel($romz[5]), 8, 160, 100, 17, $SS_CENTER)
EndFunc