Mat Posted October 26, 2009 Share Posted October 26, 2009 A very successful spin off from a considerably larger project to test the GUI and hotkeys, that I'm now using all the time, so thought I might share. No settings, as I've just spent a long time writing an 800 line (and growing) settings dialog for the parent project, and have no intentions of a repeat of that ordeal. If you want to change something then edit the source code! Cool stuff: * Drag & drop onto the creation wizard checks the filetype, and changes the data dependent on that. Try an au3. * Most of the code is the creation wizard. The actual program is tiny. * Hotkey + GUI combo works well, and the auto-hide feature. expandcollapse popup#NoTrayIcon If WinExists ("Quick launcher") Then ProcessClose (WinGetProcess ("Quick launcher")) AutoItWinSetTitle ("Quick launcher") Opt ("GUIOnEventMode", 1) Opt ("GUIResizeMode" , 802) Global $ahIcons[1] = [0] Global $hGUI = GUICreate ("Run snippet", 254, 34, 0, 0, 0x86000000, 152) GUISetOnEvent (-3, "_HideGUI") GUISetOnEvent (-13, "_Dropped") GUISetBkColor (0xFFFFFF) Local $aIcons = _RegReadSectionNames ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons"), $nTier = 0 If $aIcons[0] = 0 Then MsgBox (16, "Error", "No Icons!") _CreateIconWizard () Exit EndIf $ahIcons = $aIcons For $i = 1 to $aIcons[0] If Mod ($i, 10) = 0 Then $nTier += 1 $sIcon = _RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $aIcons[$i], "Icon", @SystemDir & "\shell32.dll,0") $nInd = StringRegExpReplace ($sIcon, ".*,(\d+)\z", "\1") + 0 $sIcon = StringRegExpReplace ($sIcon, "(.*),\d+\z", "\1") $ahIcons[$i] = GUICtrlCreateIcon ($sIcon, $nInd, 4 + (Mod ($i - 1, 10) * 36), 2 + $nTier * 36, 32, 32) GUICtrlSetOnEvent (-1, "_EventClicked") GUICtrlSetCursor (-1, 0) GUICtrlSetTip (-1, $aIcons[$i]) GUICtrlSetState (-1, 8) $hCxt = GUICtrlCreateContextMenu ($ahIcons[$i]) GUICtrlCreateMenuItem ($aIcons[$i], $hCxt) GUICtrlSetOnEvent (-1, "_MenuClicked") GUICtrlCreateMenuItem ("", $hCxt) GUICtrlCreateMenuItem ("Add Icon", $hCxt) GUICtrlSetOnEvent (-1, "_CreateIconWizard") GUICtrlCreateMenuItem ("delete: " & $aIcons[$i], $hCxt) GUICtrlSetOnEvent (-1, "_MenuClicked") GUICtrlCreateMenuItem ("edit: " & $aIcons[$i], $hCxt) GUICtrlSetOnEvent (-1, "_MenuClicked") GUICtrlCreateMenuItem ("Exit", $hCxt) GUICtrlSetOnEvent (-1, "_Exit") Next $nWidth = 4 + ($i - 1) * 36 If $nTier <> 0 Then $nWidth = 364 WinMove ($hGUI, "", default, default, $nWidth, 4 + ($nTier + 1) * 34) If HotkeySet ("!{ESC}", "_ShowGUI") = 0 Then Exit MsgBox (16, "Error!!", "Hotkey is already in use!") While 1 If Not WinActive ($hGUI, "") Then _HideGUI () Sleep (20) WEnd Func _Dropped () _CreateIconWizard (@GUI_DRAGFILE) Endfunc ; ==> _Dropped func _CreateIconWizard ($sFile = -1, $sName = "") ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ _HideGUI () Opt ("GUIOnEventMode", 0) $hCreateUI = GUICreate ("Create an icon!", 238, 172, -1, -1, 13369344, 153) GUICtrlCreateLabel ("Name:" , 2, 4, 60, 20) $hName_Inp = GUICtrlCreateInput ("" , 64, 2, 172, 20) GUICtrlCreateGroup ("Icon", 2, 24, 234, 88) ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $sIcon = "C:\WINDOWS\system32\SHELL32.dll" $nInd = 24 $hIco_Inp = GUICtrlCreateInput ($sIcon & "," & $nInd , 10, 40, 220, 20) GUICtrlSetState (-1, 8) $hIco_Sel = GUICtrlCreateButton ("Select" , 10, 62, 90, 20) GUICtrlSetState (-1, 8) $hIco_Aut = GUICtrlCreateButton ("@AutoitExe icon" , 10, 84, 90, 20) GUICtrlSetState (-1, 8) $hIco_Def = GUICtrlCreateButton ("Default icon" , 102, 62, 90, 20) GUICtrlSetState (-1, 8) $hIco_Ref = GUICtrlCreateButton ("Refresh icon" , 102, 84, 90, 20) GUICtrlSetState (-1, 8) $hIco_Ico = GUICtrlCreateIcon (@AutoitExe, 0 , 198, 66, 32, 32) GUICtrlSetImage (-1, $sIcon, $nInd) GUICtrlSetState (-1, 8) GUICtrlCreateGroup ("Command", 2, 112, 234, 36) ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $hCmd_Inp = GUICtrlCreateInput ("" , 10, 124, 200, 20) GUICtrlSetState (-1, 8) $hCmd_Btn = GUICtrlCreateButton ("..." , 210, 124, 20, 20) GUICtrlSetState (-1, 8) $hBtn_Acc = GUICtrlCreateButton ("Ok" , 150, 150, 80, 20) GUICtrlSetState (-1, 8) $hBtn_Canc = GUICtrlCreateButton ("Cancel" , 68, 150, 80, 20) GUICtrlSetState (-1, 8) If Not IsDeclared ("sFile") Then $sFile = -1 ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ If $sFile = -2 Then GUICtrlSetData ($hName_Inp , $sName) $sIcon = _RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName, "icon", "C:\WINDOWS\system32\SHELL32.dll,24") $nInd = StringRegExpReplace ($sIcon, ".*,(\d+)\z", "\1") + 0 $sIcon = StringRegExpReplace ($sIcon, "(.*),\d+\z", "\1") GUICtrlSetImage ($hIco_Ico , $sIcon , $nInd) GUICtrlSetData ($hIco_Inp , $sIcon & "," & $nInd) GUICtrlSetData ($hCmd_Inp , _RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName, "command", "")) ElseIf $sFile <> -1 Then GUICtrlSetData ($hName_Inp , StringRegExpReplace ($sFile, ".*\\(.*?)\..*)", "\1")) GUICtrlSetImage ($hIco_Ico , $sFile , 0) GUICtrlSetData ($hIco_Inp , $sFile & ",0") GUICtrlSetData ($hCmd_Inp , $sFile ) EndIf GUISetState (@SW_SHOW, $hCreateUI) ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ While 1 $nMsg = GUIGetMsg () Switch $nMsg Case -3, $hBtn_Canc ExitLoop Case -13 ; drop $sExt = StringRegExpReplace (@GUI_DRAGFILE, ".*\.", "") If $sExt = "ico" Then GUICtrlSetData ($hIco_Inp, @GUI_DRAGFILE & ",0") GUICtrlSetImage ($hIco_Ico, @GUI_DRAGFILE, 0) ElseIf $sExt = "exe" Then GUICtrlSetData ($hName_Inp, StringRegExpReplace (StringTrimRight (@GUI_DRAGFILE, 4), ".*\\(.*?)", "\1")) GUICtrlSetData ($hCmd_Inp, @GUI_DRAGFILE) GUICtrlSetData ($hIco_Inp, @GUI_DRAGFILE & ",0") GUICtrlSetImage ($hIco_Ico, @GUI_DRAGFILE, 0) ElseIf $sExt = "au3" Then GUICtrlSetData ($hName_Inp, StringRegExpReplace (StringTrimRight (@GUI_DRAGFILE, 4), ".*\\(.*?)", "\1")) GUICtrlSetData ($hCmd_Inp, """" & @AutoitExe & """ /AutoIt3ExecuteScript """ & @GUI_DRAGFILE & """") GUICtrlSetData ($hIco_Inp, @AutoitExe & ",0") GUICtrlSetImage ($hIco_Ico, @AutoitExe, 0) Else GUICtrlSetData ($hName_Inp, StringRegExpReplace (StringTrimRight (@GUI_DRAGFILE, 4), ".*\\(.*?)", "\1")) GUICtrlSetData ($hCmd_Inp, @GUI_DRAGFILE) GUICtrlSetData ($hIco_Inp, @GUI_DRAGFILE & ",0") GUICtrlSetImage ($hIco_Ico, @GUI_DRAGFILE, 0) EndIf Case $hIco_Sel, $hIco_Def, $hIco_Ref, $hIco_Ico $sIcon = GUICtrlRead ($hIco_Inp) $nInd = StringRegExpReplace ($sIcon, ".*,(\d+)\z", "\1") + 0 $sIcon = StringRegExpReplace ($sIcon, "(.*),\d+\z", "\1") If $nMsg = $hIco_Sel Then $aIcon = DllCall("shell32.dll", "int", "PickIconDlg", "hwnd", $hCreateUI, "wstr", $sIcon, "int", 1000, "int*", $nInd - 1) $sIcon = StringReplace ($aIcon[2], "%SystemRoot%", @WindowsDir) $nInd = $aIcon[4] + 1 ElseIf $nMsg = $hIco_Def Then $sIcon = "C:\WINDOWS\system32\SHELL32.dll" $nInd = 24 ElseIf $nMsg = $hIco_Aut Then MsgBox (0, "", "") $sIcon = @AutoitExe $nInd = 0 Else $sIcon = GUICtrlRead ($hIco_Inp) $nInd = StringRegExpReplace ($sIcon, ".*,(\d+)\z", "\1") + 0 ; I was having problems with GUICtrlSetImage $sIcon = StringRegExpReplace ($sIcon, "(.*),\d+\z", "\1") EndIf GUICtrlSetData ($hIco_Inp, $sIcon & "," & $nInd) GUICtrlSetImage ($hIco_Ico, $sIcon, $nInd) Case $hCmd_Btn GUISetState (@SW_HIDE, $hCreateUI) $line = _Wizard () If $line <> "" Then GUICtrlSetData ($hCmd_Inp, $line) GUISetState (@SW_SHOW, $hCreateUI) Case $hBtn_Acc $sName = GUICtrlRead ($hName_Inp) If $sName = "" Then ContinueLoop 1 + 0 * MsgBox (16, "Error", "Name cannot be blank!") If _RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName, "command", "") <> "" Then If MsgBox (20, "Error", "Name already exist!" & @CRLF & @CRLF & "Overwrite?") <> 6 Then ContinueLoop EndIf $sIcon = GUICtrlRead ($hIco_Inp) $nInd = StringRegExpReplace ($sIcon, ".*,(\d+)\z", "\1") + 0 $sIcon = StringRegExpReplace ($sIcon, "(.*),\d+\z", "\1") If Not FileExists ($sIcon) Then ContinueLoop 1 + 0 * MsgBox (16, "Error", "Icon file does not exist!!") $line = GUICtrlRead ($hCmd_Inp) If $line = "" Then ContinueLoop 1 + 0 * MsgBox (16, "Error", "command line not valid!") _CreateIcon ($sIcon & "," & $nInd, $sName, $line) _Restart () ExitLoop EndSwitch WEnd GUIDelete ($hCreateUI) Opt ("GUIOnEventMode", 1) Return EndFunc ; ==> _CreateIconWizard ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func _CreateIcon ($sIconPath, $sName, $sCommand) RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName, "Icon" , "REG_SZ", $sIconPath) RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName, "Command", "REG_SZ", $sCommand) EndFunc ; ==> _CreateIcon Func _HideGUI () GUISetState (@SW_Hide, $hGUI) EndFunc ; ==> _HideGUI Func _Exit () Exit EndFunc ; ==> _Exit Func _ShowGUI () $nIsOpen = 1 $aPos = MouseGetPos () $aPos2 = WinGetPos ($hGUI, "") If $aPos[0] > @DesktopWidth - $aPos2[2] Then $aPos[0] -= $aPos2[2] - 4 If $aPos[1] > @DesktopHeight - $aPos2[3] Then $aPos[1] -= $aPos2[3] - 4 WinMove ($hGUI, "", $aPos[0] - 2, $aPos[1] - 2) GUISetState (@SW_Show, $hGUI) EndFunc ; ==> _ShowGUI Func _EventClicked () _HideGUI () $i = _GetIndex (@GUI_CtrlId) If $i < 0 Then Return Run (RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & RegEnumKey ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\", $i), "command")) EndFunc ; ==> _EventClicked Func _MenuClicked () _HideGUI () If StringLeft (GUICtrlRead (@GUI_CtrlID, 1), 6) = "edit: " Then Return _CreateIconWizard (-2, StringTrimLeft (GUICtrlRead (@GUI_CTRLID, 1), 6)) If StringLeft (GUICtrlRead (@GUI_CTRLID, 1), 8) = "delete: " Then Return _DeleteIcon (StringTrimLeft (GUICtrlRead (@GUI_CTRLID, 1), 8)) Run (RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & GUICtrlRead (@GUI_CTRLID, 1), "command")) EndFunc ; ==> _MenuClicked Func _DeleteIcon ($sName) RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Quick launcher\Icons\" & $sName) _Restart () EndFunc ; ==> _DeleteIcon Func _GetIndex ($hIcon) For $i = 1 to $ahIcons[0] If $ahIcons[$i] = $hIcon Then Return $i Next Return -1 EndFunc ; ==> _GetIndex Func _Wizard () Local $sCmdLine = "", $sFil_Cur = "" $hWizUI = GUICreate ("Create command line.", 500, 90, -1, -1, 0x00C00000 + 0x00080000 + 0x00040000, 0x00000080 + 0x00000001 + 0x00000008) $hTab = GUICtrlCreateTab (2, 2, 496, 20) GUICtrlCreateTabItem ("Input...") GUICtrlCreateLabel ("Command Line:", 2, 24, 80, 20) $hInp_Inp = GUICtrlCreateInput ("", 84, 24, 390, 20) GUICtrlCreateTabItem ("Executable") GUICtrlCreateLabel (".exe file path:", 2, 24, 80, 20) $hExe_Inp = GUICtrlCreateInput ("", 84, 24, 390, 20) $hExe_Btn = GUICtrlCreateButton ("...", 474, 24, 20, 20) GUICtrlCreateLabel ("* Arguments:", 2, 46, 80, 20) $hExe_Par = GUICtrlCreateInput ("", 84, 46, 410, 20) GUICtrlCreateTabItem ("File") GUICtrlCreateLabel (" file path:", 2, 24, 80, 20) $hFil_Inp = GUICtrlCreateInput ("", 84, 24, 390, 20) $hFil_Btn = GUICtrlCreateButton ("...", 474, 24, 20, 20) $hFil_Lst = GUICtrlCreateCombo ("", 2, 46, 100, 20, 0x0003) GUICtrlCreateLabel ("* Additional params:", 108, 48, 105, 20) $hFil_Add = GUICtrlCreateInput ("", 206, 46, 285, 20) GUICtrlCreateTabItem ("Web site") $hWeb_Rad = GUICtrlCreateRadio ("URL:", 2, 24, 60, 20) GUICtrlSetState (-1, 1) $hWeb_Url = GUICtrlCreateInput ("http:\\", 64, 24, 430, 20) GUICtrlCreateRadio ("Mailto:", 2, 46, 60, 20) $hWeb_Mto = GUICtrlCreateInput ("", 64, 46, 430, 20) GUICtrlCreateTabItem ("Folder") GUICtrlCreateLabel ("Folder directory:", 2, 24, 80, 20) $hFol_Inp = GUICtrlCreateInput ("", 84, 24, 390, 20) $hFol_Btn = GUICtrlCreateButton ("...", 474, 24, 20, 20) $hFol_Lst = GUICtrlCreateCombo ("", 2, 46, 100, 20, 0x0003) GUICtrlSetData (-1, "Normal View") GUICtrlSetData (-1, "Explorer View") GUICtrlCreateLabel ("* Additional params:", 108, 48, 105, 20) $hFol_Add = GUICtrlCreateInput ("", 206, 46, 285, 20) GUICtrlCreateTabItem ("Advanced") GUICtrlCreateLabel ("Execute Line:", 2, 24, 80, 20) $hAdv_Inp = GUICtrlCreateInput ("", 84, 24, 410, 20) $hAdv_Rad = GUICtrlCreateRadio ("Errors to STD stream. *", 2, 46, 130, 20) GUICtrlCreateTabItem ("") GUICtrlCreateLabel ("* = optional.", 2, 68, 80, 20) $hDlg_tst = GUICtrlCreateButton ("Test run", 252, 68, 80, 20) $hDlg_can = GUICtrlCreateButton ("Cancel", 334, 68, 80, 20) $hDlg_don = GUICtrlCreateButton ("Finished", 416, 68, 80, 20) GUISetState () While 1 $msg = GUIGetMsg () Switch $msg Case -3, $hDlg_can GUIDelete ($hWizUI) Return SetError (1, 0, "") Case $hDlg_Don, $hDlg_tst Switch ControlCommand ($hWizUI, "", $hTab, "CurrentTab", "") Case 1 ; Input... $sCmdLine = GUICtrlRead ($hInp_Inp) Case 2 ; executable $sCmdLine = """" & GUICtrlRead ($hExe_Inp) & """ " & GUICtrlRead ($hExe_Par) Case 3 ; file $cur = GUICtrlRead ($hFil_Lst) If $cur = "" Then $sCmdLine = """" & GUICtrlRead ($hFil_Inp) & """" ElseIf $cur = "(default Program)" Then $sCmdLine = "%WinDir%\System32\Rundll32.exe Url,FileProtocolHandler " & FileGetShortName (GUICtrlRead ($hFil_Inp)) Else $cur = RegRead ("HKCR\" & $temp & "\shell\" & $cur & "\Command", "") $pos = StringInStr ($cur, "%1") If $Pos <> 0 Then $quote = "" If StringMid ($cur, $pos - 1, 1) <> """" Then $quote = """" $sCmdLine = StringReplace (StringReplace ( _ $cur, "%1", $quote & GUICtrlRead ($hFil_Inp) & $quote), "%*", "") & GUICtrlRead ($hFil_Add) If $msg = $hDlg_don Then ExitLoop Run ($sCmdLine) ContinueLoop EndIf If StringLeft ($cur, 1) = """" Then $cur = StringTrimLeft ($cur, 1) $cur = StringRegExpReplace ($cur, """.*", "") Else $cur = StringRegExpReplace ($cur, "(\S*).*", "\1") $cur = FileGetLongName ($cur) EndIf $sCmdLine = """" & $cur & """ """ & GUICtrlRead ($hFil_Inp) & """ " & GUICtrlRead ($hFil_Add) EndIf Case 4 ; web site If BitAnd (GUICtrlRead ($hWeb_Rad), 1) Then $sCmdLine = "%WinDir%\System32\Rundll32.exe Url,FileProtocolHandler " & GUICtrlRead ($hWeb_Url) Else $sCmdLine = "%WinDir%\System32\Rundll32.exe Url,FileProtocolHandler Mailto:" & GUICtrlRead ($hWeb_Mto) EndIf Case 5 ; folder $view = "/n" If GUICtrlRead ($hFol_Lst) = "Explorer View" Then $view = "/e" $sCmdLine = "explorer.exe " & $view & " """ & GUICtrlRead ($hFol_Inp) & """ " & GUICtrlRead ($hFol_Add) Case 6 ; advanced $sErr = "" If BitAnd (GUICtrlRead ($hAdv_Rad), 1) Then $sErr = "/ErrorStdOut" $sCmdLine = """" & @AutoitExe & """ " & $sErr & " /AutoIt3ExecuteLine """ & _ StringReplace (GUICtrlRead ($hAdv_Inp), """", """""") & """" EndSwitch If $msg = $hDlg_don Then ExitLoop Run ($sCmdLine) Case $hExe_Btn $sFile = FileOpenDialog ("Open exe...", @WorkingDir, "Executables (*.exe)|All Files (*.*)", 3, "*.exe", $hWizUI) If @Error Then ContinueLoop GUICtrlSetData ($hExe_Inp, $sFile) Case $hFil_Btn $sFile = FileOpenDialog ("Open File...", @WorkingDir, "All Files (*.*)", 3, "", $hWizUI) If @Error Then ContinueLoop GUICtrlSetData ($hFil_Inp, $sFile) Case $hFol_Btn $sFile = FileSelectFolder ("Select Folder...", "", 7, @WorkingDir, $hWizUI) If @Error Then ContinueLoop GUICtrlSetData ($hFol_Inp, $sFile) EndSwitch If $sFil_cur = GUICtrlRead ($hFil_Inp) Then ContinueLoop $sFil_cur = GUICtrlRead ($hFil_Inp) GUICtrlSetData ($hFil_Lst, "") If Not FileExists ($sFil_Cur) Then ContinueLoop $temp = RegRead ("HKCR\." & StringRegExpReplace ($sFil_Cur, ".*\.", ""), "") If @Error Then ContinueLoop $i = 0 GUICtrlSetData ($hFil_Lst, "(default Program)") While 1 $i += 1 RegEnumKey ("HKCR\" & $temp & "\shell\", $i) If @Error <> 0 Then ExitLoop GUICtrlSetData ($hFil_Lst, RegEnumKey ("HKCR\" & $temp & "\shell\", $i)) WEnd WEnd GUIDelete ($hWizUI) Return $sCmdLine EndFunc ; ==> _Wizard Func _Restart () If @Compiled Then Run ("""" & @ScriptFullPath & """") Else Run ("""" & @AutoitExe & """ """ & @ScriptFullPath & """") EndIf Exit EndFunc ; ==> _Restart Func _RegRead ($key, $name, $ret) Local $Result = RegRead ($key, $name) If @Error Then Return $ret Return $Result EndFunc ;==>_RegRead Func _RegReadSectionNames ($key) Local $aRet[1], $i = 0 $aRet[0] = 0 While 1 $i += 1 $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop ReDim $aRet[UBound ($aRet, 1) + 1] $aRet[UBound ($aRet, 1) - 1] = $var If @Error Then ReDim $aRet[UBound ($aRet, 1) - 1] $aRet[0] += 1 WEnd Return $aRet Endfunc ;==>_RegReadSectionNames Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
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