Mehomic Posted March 2, 2012 Posted March 2, 2012 Hi Everybods,Since my CD fascia button does not engage with the CD Tray button, obvious misalignment fromthe usual movement in plastics. I decided I needed some way of "controlling" access to the said drive.Upon extensive googling and searching here at the AutoIt forum; I did not find any thing suitable that would fit my needs.I decided to script my "own" from the Scite help file and the many tips and tricks I have learned from this forum.CDTray.au3expandcollapse popup#cs============================================================== Filename: cdtray.au3 Author: Mehomic Date: 02-Mar-2012 Version: 1.0.5.0 #ce============================================================== #NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Opt("TrayIconHide", 1) Opt("TrayAutoPause", 0) $my_gui = GUICreate("OPEN/CLOSE CD Tray", 300, 160, (@DesktopWidth - 300) / 2, (@DesktopHeight - 160) / 2) ; w=130 GUISetBkColor("0xDADADA") ; set gui background colour $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("E&xit (Alt + F4)", $filemenu) $helpmenu = GUICtrlCreateMenu("About") $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu) $opencdtray = GUICtrlCreateButton("Open CD Tray", 28, 20, 95, 25) GUICtrlSetState(-1, $GUI_ENABLE) $closecdtray = GUICtrlCreateButton("Close CD Tray", 177, 20, 95, 25) GUICtrlSetState(-1, $GUI_ENABLE) $cancelbutton = GUICtrlCreateButton("Cancel", 103, 70, 95, 25) GUICtrlSetState(-1, $GUI_ENABLE)[/size] [size=3]$status = GUICtrlCreateLabel("Ready to start...", 35, 110, 230, 17, $SS_SUNKEN + $SS_CENTER) ;GUICtrlSetBkColor(-1, -2); sets background color of label transparent GUICtrlSetFont(-1, 9, 300, 0, "Arial") ;<< set font, size, weight GUICtrlSetColor(-1, 0x000000) ;<< set font color (black) GUICtrlSetBkColor(-1, 0xDDDDDD) ;<< set backgorund color of label (grey)[/size] [size=3]GUISetState() Global $GETCDDRIVE = DriveGetDrive("CDROM") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cancelbutton ExitLoop Case $exititem ExitLoop Case $infoitem MsgBox(0, "About", " Open and Close the CDTray") Case $opencdtray If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "Open/Close CD Drive", "It appears an error has occurred in" & @CRLF & "retrieving the CDROM drive letter.") Else GUICtrlSetData($status, "Opening CD Tray") GUICtrlSetColor(-1, 0x006600) ; font color green ;$GETCDDRIVE = DriveGetDrive("CDROM") CDTray($GETCDDRIVE[1] & "\", "open") GUICtrlSetData($status, "Please insert/remove your media") Sleep(1500) EndIf Case $closecdtray If @error Then ; An error occurred when retrieving the drives. MsgBox(4096, "Open/Close CD Drive", "It appears an error has occurred in" & @CRLF & "retrieving the CDROM drive letter.") Else GUICtrlSetData($status, "Closing the CD Tray") GUICtrlSetColor(-1, 0x006600) ; font color green ;$GETCDDRIVE = DriveGetDrive("CDROM") CDTray($GETCDDRIVE[1] & "\", "close") GUICtrlSetData($status, "Thank You") Sleep(4000) GUICtrlSetData($status, "Ready to start.....") GUICtrlSetColor(-1, 0x000000) ;<< set font color (black) EndIf EndSwitch WEnd GUIDelete() Exit[/size] [size=3]; ; ------------------------------------------ end of file ----------------------------------------------- ;[/size] [size=3]Enjoy........PS This is my first attempt at using AutoitMehomic
monter Posted March 2, 2012 Posted March 2, 2012 Upon extensive googling and searching here at the AutoIt forum; I did not find any thing suitable that would fit my needs.Didn't you find my script or my CDtray was too much complicated (or too simple)? monter.FM [font="Tahoma;"]Full programs:[/font][font="'Microsoft Sans Serif';"] LogOnOff - keeps alive user session, after set time it performs logoff (instead of locking [acronym="Personal Computer"]PC[/acronym], useful in some corporations working with [acronym="Active Directory"]AD[/acronym]).[/font] ČharCönvěr - character set converter. [font="'Microsoft Sans Serif';"]CDTray - automated opening/closing the [acronym="Compact Disc"]CD[/acronym] tray.[/font] [font="'Microsoft Sans Serif';"]Example scripts: [/font][font="'Microsoft Sans Serif';"]RecentFolders - managing recently used folder list with combobox.[/font] [font="'Microsoft Sans Serif';"]AutoUpdater - periodic auto-checking, auto-updating and auto-relaunching newest script version.[/font] Changed host from monter.homeip.net to monter.homenet.org - replace address in my scripts to get back them to work.
Mehomic Posted March 3, 2012 Author Posted March 3, 2012 Didn't you find my script or my CDtray was too much complicated (or too simple)? Yes, I did peruse your script but I found it overly complicated for the simple task of opening and closing the CDTray.There must be thousands of users who have trouble in operating their CD Tray in the same manner that I had.Code Mehomic
guinness Posted March 3, 2012 Posted March 3, 2012 Mehomic, With your code how you're using @error after the 'Case' statement won't really work as what would the error be exactly? Also you don't have to have separate Case statements for when the user wants to Exit, you can place this on one line e.g. Case $iExit, $iClose etc... Also in terms of length your code is good but it can be optimised a little, so this is what I came up with in 10 mins. Now it could be optimised further, but in terms of readability it fits the bill. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; Advanced Au3Check parameters. #NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Example() Func Example() Local $aArray[2][3] = [["close", "Closing the CD tray", 0x000000],["open", "Opening the CD tray.", 0x006600]], $iHeight = 160, $iRun = 0, $iState = 0, $iWidth = 300, _ $sDrive = "" Local $hGUI = GUICreate("Open/Close CD Utility.", $iWidth, $iHeight, -1, -1) Local $iAbout = GUICtrlCreateButton("?", 5, $iHeight - 30, 25, 25) Local $iCancel = GUICtrlCreateButton("Canc&el", $iWidth - 90, $iHeight - 30, 85, 25) Local $iOpen = GUICtrlCreateButton("&Open", 30, 30, 85, 25) Local $iClose = GUICtrlCreateButton("&Close", $iWidth - 95 - 30, 30, 85, 25) GUICtrlSetState($iClose, $GUI_DISABLE) Local $iStatus = GUICtrlCreateLabel("", 20, 80, $iWidth - 40, 20, $SS_SUNKEN + $SS_CENTER) GUISetState(@SW_SHOW, $hGUI) Local $aCDROM = DriveGetDrive("CDROM") If @error Then GUICtrlSetState($iClose, $GUI_DISABLE) GUICtrlSetState($iOpen, $GUI_DISABLE) GUICtrlSetData($iStatus, "No CD-Rom detected...Please restart.") Else $sDrive = $aCDROM[1] & "" EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iCancel ExitLoop Case $iAbout MsgBox(4096, "About", "CD-Rom open and closing utility by guinness (c) " & @YEAR, 0, $hGUI) Case $iClose, $iOpen $iState = Number(Not $iState) GUICtrlSetData($iStatus, $aArray[$iState][1]) GUICtrlSetColor(-1, $aArray[$iState][2]) CDTray($sDrive, $aArray[$iState][0]) If @error Then $iState = Number(Not $iState) ; Set the state back to the previous option. GUICtrlSetData($iStatus, "An unexpected error occurred.") GUICtrlSetColor(-1, 0xFF0000) Else GUICtrlSetData($iStatus, "Task was completed.") If Not $iRun Then ; Enable Close, because the user has opened the CD-Rom for the first time. $iRun = 1 GUICtrlSetState($iClose, $GUI_ENABLE) EndIf EndIf EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
forever0donotknowme Posted March 3, 2012 Posted March 3, 2012 what is difference between above script and my script about fonuction for open cd #RequireAdmin $var = DriveGetDrive("CDROM") CDTray($var[1],"open")
JohnOne Posted March 3, 2012 Posted March 3, 2012 There must be thousands of users who have trouble in operating their CD Tray in the same manner that I had.Somehow, I very much doubt it.Your code is two basic functions wrapped in a needless gui.Sorry to be so blunt, but on another day this would be locked as a worthless example. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now