rdwray Posted January 23, 2011 Share Posted January 23, 2011 (edited) Here is desktop bar that will allow virtually anything to be launched:Compact.Place anywhere horizontal or vertical.Drag and drop or browse for object to run.Alt+F1 for help.Right click and hold to move.Right click and release for options.EmailShortcuts (.lnk)Favorites (.url)Control Panel programs (.msc)Control Panel programs (.exe)etc...Need a 24x24 bit icon named "Generic.ico" for items that don't have an associcated icon.It is possible to modify the apperance, but I would not advise messing with any of the logic. All comments welcome.See updated code in message below...expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Icon_Add=Generic.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> $_MissingIconIdx = 4 Opt("TrayAutoPause",0) Opt("MustDeclareVars", 0) Opt("TrayIconDebug", 1) ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. Global $newCursor = 16, $oldCursor HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0,24, 24, $BS_ICON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON) LoadIcon($i) $y += 24 Next EndIf GUISetBkColor(0xFF0000, $hGuiBar) GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com/",".net/",".org/",".edu/",".info/",".us/",".biz/",".gov/",".mil/"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringLeft($sc[$i][1], 7) = "mailto:" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringRight($sc[$i][1], 4) = ".exe" Then ; Executable. ToolTip(GUICtrlRead($bCtrl[$i])) If @Compiled And GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then _GUICtrlButton_SetImageList($bCtrl[$i], _GetImageListHandle(@AutoItExe, $_MissingIconIdx), 4) ; Use icon located in program. Else If GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then GUICtrlSetImage($bCtrl[$i], "Generic.ico") ; Use external icon. EndIf ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(24, 24, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/96988-winapi-findexecutable-replacement/page__p__697477__hl__assocquerystringw__fromsearch__1#entry697477 Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER + $WS_SIZEBOX, $WS_EX_ACCEPTFILES) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetState(-1,$GUI_DROPACCEPTED) ; Drag and drop files. GUISetState() GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) GUISetState(@SW_HIDE, $hGuiOpt) Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) If _IsPressed("01", $dll) And WinActive($hGuiBar) Then RunProg() If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) GUIctrlSetCursor($ID[4], 0) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) If StringMid($sc[$bID -2][1], 5, 3) = "://" Then If StringRight($sc[$bID -2][1], 1) <> "/" then ; Back slash is required by Windows. $sc[$bID -2][1] = $sc[$bID -2][1] & "/" GUICtrlSetData($file, $sc[$bID -2][1]) EndIf EndIf If StringRight($sc[$bID -2][1], 4) = ".lnk" Then $sc[$bID -2][1] = StringLeft($sc[$bID -2][1], StringLen($sc[$bID -2][1]) -4) GUICtrlSetData($file, $sc[$bID -2][1]) ; MsgBox("", "", StringMid($sc[$bID -2][1], 5, 3)) EndIf $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) If $WinPos2[0] + $WinPos2[2] > @DesktopWidth Then WinMove("ShortCutBar", "", @DesktopWidth - $WinPos2[2], $WinPos2[1]) ; +-3 allows for some movement error when trying to run program. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg(); If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then if StringRight($sc[$ID[4]-2][1], 4) <> ".exe" And StringRight($sc[$ID[4]-2][1],1) <> "}" Then ShellExecute($sc[$ID[4]-2][1]) ; Open folder. else DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0) Run($sc[$ID[4]-2][1]) ; Run progarms. DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1) EndIf EndIf Sleep(100) ; Got to give enough time for program to open or more than 1 copy will be ran. EndFunc Func Help() Local $help = "Enter entire program path or button will may be blank. There are 3 ways to enter the path: 1) Enter it manually. 2) Use the browse button. 3) Find the program or file and drag it to the file box. If you select a shortcut, make sure the .lnk extension if removed." & @CRLF & @CRLF _ & "If program does not have an icon associated with it, a generic icon will be on the button." & @CRLF & @CRLF _ & "Any file type can be entered, it's associated program's icon will be shown. Example: file.txt will show Notepad's icon." & @CRLF & @CRLF _ & "To enter a email address precede it with 'mailto:'; the default email program's icon will be on the button."& @CRLF & @CRLF _ & "If a file's full path is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the name for shortcut box, it will show up in the tooltip." & @CRLF & @CRLF _ & "Bar can be placed anywhere and it will be remembered."& @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar. If the bar isn't move more than 3 pixels, the options dialog will open." MsgBox(0, "Shortcut Bar Help", $help) EndFunc Edited April 7, 2011 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
wakillon Posted January 23, 2011 Share Posted January 23, 2011 Well done ! May be a little capture for illustrated should be helpfull ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Zibit Posted January 24, 2011 Share Posted January 24, 2011 i like it ^^ it reminds me of rocketdock Creator Of Xtreme DevelopersPixel Pattern UDFTray GUI UDFMathssend & recive register scriptMouse Control via Webcam Link to comment Share on other sites More sharing options...
rdwray Posted April 7, 2011 Author Share Posted April 7, 2011 (edited) Updated the code so that the position of the bar would be saved without opening the options window and pressing the save button: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Icon_Add=Generic.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> $_MissingIconIdx = 4 Opt("TrayAutoPause",0) Opt("MustDeclareVars", 0) Opt("TrayIconDebug", 1) ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $SC_CLOSE = 0xF060 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. Global $newCursor = 16, $oldCursor HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0,24, 24, $BS_ICON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON) LoadIcon($i) $y += 24 Next EndIf GUISetBkColor(0xFF0000, $hGuiBar) GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com/",".net/",".org/",".edu/",".info/",".us/",".biz/",".gov/",".mil/"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringLeft($sc[$i][1], 7) = "mailto:" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringRight($sc[$i][1], 4) = ".exe" Then ; Executable. ToolTip(GUICtrlRead($bCtrl[$i])) If @Compiled And GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then _GUICtrlButton_SetImageList($bCtrl[$i], _GetImageListHandle(@AutoItExe, $_MissingIconIdx), 4) ; Use icon located in program. Else If GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then GUICtrlSetImage($bCtrl[$i], "Bible24.ico") ; Use external icon. EndIf ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(24, 24, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/96988-winapi-findexecutable-replacement/page__p__697477__hl__assocquerystringw__fromsearch__1#entry697477 Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER + $WS_SIZEBOX, $WS_EX_ACCEPTFILES) ; Disable close button "X". $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $hGuiOpt, "int", 0) $hSysMenu = $dSysMenu[0] DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hGuiOpt) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetState(-1,$GUI_DROPACCEPTED) ; Drag and drop files. GUISetState() GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) GUISetState(@SW_HIDE, $hGuiOpt) Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) If _IsPressed("01", $dll) And WinActive($hGuiBar) Then RunProg() If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If Not _IsPressed("02", $dll) And $moved = true Then WriteFile() $moved = False EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) GUIctrlSetCursor($ID[4], 0) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) If StringMid($sc[$bID -2][1], 5, 3) = "://" Then If StringRight($sc[$bID -2][1], 1) <> "/" then ; Back slash is required by Windows. $sc[$bID -2][1] = $sc[$bID -2][1] & "/" GUICtrlSetData($file, $sc[$bID -2][1]) EndIf EndIf If StringRight($sc[$bID -2][1], 4) = ".lnk" Then $sc[$bID -2][1] = StringLeft($sc[$bID -2][1], StringLen($sc[$bID -2][1]) -4) GUICtrlSetData($file, $sc[$bID -2][1]) ; MsgBox("", "", StringMid($sc[$bID -2][1], 5, 3)) EndIf $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) If $WinPos2[0] + $WinPos2[2] > @DesktopWidth Then WinMove("ShortCutBar", "", @DesktopWidth - $WinPos2[2], $WinPos2[1]) ; +-3 allows for some movement error when trying edit options. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg(); If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then if StringRight($sc[$ID[4]-2][1], 4) <> ".exe" And StringRight($sc[$ID[4]-2][1],1) <> "}" Then ShellExecute($sc[$ID[4]-2][1]) ; Open folder. else DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0) Run($sc[$ID[4]-2][1]) ; Run progarms. DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1) EndIf EndIf Sleep(100) ; Got to give enough time for program to open or more than 1 copy will be ran. EndFunc Func Help() Local $help = "Enter entire program path or button will may be blank. There are 3 ways to enter the path: 1) Enter it manually. 2) Use the browse button. 3) Find the program or file and drag it to the file box. If you select a shortcut, make sure the .lnk extension if removed." & @CRLF & @CRLF _ & "If program does not have an icon associated with it, a generic icon will be on the button." & @CRLF & @CRLF _ & "Any file type can be entered, it's associated program's icon will be shown. Example: file.txt will show Notepad's icon." & @CRLF & @CRLF _ & "To enter a email address precede it with 'mailto:'; the default email program's icon will be on the button."& @CRLF & @CRLF _ & "If a file's full path is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the name for shortcut box, it will show up in the tooltip." & @CRLF & @CRLF _ & "Bar can be placed anywhere and it will be remembered."& @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar. If the bar isn't move more than 3 pixels, the options dialog will open." MsgBox(0, "Shortcut Bar Help", $help) EndFunc Edited April 11, 2011 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
rdwray Posted May 24, 2011 Author Share Posted May 24, 2011 Another update to prevent multiple occurrences of a program running when the mouse button is held down when clicking a button. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Icon_Add=Generic.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> $_MissingIconIdx = 4 Opt("TrayAutoPause",0) Opt("MustDeclareVars", 0) Opt("TrayIconDebug", 1) ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $SC_CLOSE = 0xF060 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. Global $newCursor = 16, $oldCursor Global $running = 0 HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0,24, 24, $BS_ICON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON) LoadIcon($i) $y += 24 Next EndIf GUISetBkColor(0xFF0000, $hGuiBar) GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com/",".net/",".org/",".edu/",".info/",".us/",".biz/",".gov/",".mil/"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringLeft($sc[$i][1], 7) = "mailto:" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringRight($sc[$i][1], 4) = ".exe" Then ; Executable. ToolTip(GUICtrlRead($bCtrl[$i])) If @Compiled And GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then _GUICtrlButton_SetImageList($bCtrl[$i], _GetImageListHandle(@AutoItExe, $_MissingIconIdx), 4) ; Use icon located in program. Else If GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then GUICtrlSetImage($bCtrl[$i], "Bible24.ico") ; Use external icon. EndIf ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(24, 24, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/96988-winapi-findexecutable-replacement/page__p__697477__hl__assocquerystringw__fromsearch__1#entry697477 Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER + $WS_SIZEBOX, $WS_EX_ACCEPTFILES) ; Disable close button "X". $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $hGuiOpt, "int", 0) $hSysMenu = $dSysMenu[0] DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hGuiOpt) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetState(-1,$GUI_DROPACCEPTED) ; Drag and drop files. GUISetState() GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) GUISetState(@SW_HIDE, $hGuiOpt) Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) If _IsPressed("01", $dll) And WinActive($hGuiBar) And $running = 0 Then $running = 1 RunProg() EndIf If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If Not _IsPressed("02", $dll) And $moved = true Then WriteFile() $moved = False EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) GUIctrlSetCursor($ID[4], 0) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) If StringMid($sc[$bID -2][1], 5, 3) = "://" Then If StringRight($sc[$bID -2][1], 1) <> "/" then ; Back slash is required by Windows. $sc[$bID -2][1] = $sc[$bID -2][1] & "/" GUICtrlSetData($file, $sc[$bID -2][1]) EndIf EndIf If StringRight($sc[$bID -2][1], 4) = ".lnk" Then $sc[$bID -2][1] = StringLeft($sc[$bID -2][1], StringLen($sc[$bID -2][1]) -4) GUICtrlSetData($file, $sc[$bID -2][1]) ; MsgBox("", "", StringMid($sc[$bID -2][1], 5, 3)) EndIf $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) If $WinPos2[0] + $WinPos2[2] > @DesktopWidth Then WinMove("ShortCutBar", "", @DesktopWidth - $WinPos2[2], $WinPos2[1]) ; +-3 allows for some movement error when trying edit options. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg(); If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then if StringRight($sc[$ID[4]-2][1], 4) <> ".exe" And StringRight($sc[$ID[4]-2][1],1) <> "}" Then ShellExecute($sc[$ID[4]-2][1]) ; Open folder. else DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0) Run($sc[$ID[4]-2][1]) ; Run progarms. DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1) EndIf EndIf Sleep(100) ; Got to give enough time for program to open or more than 1 copy will be ran. $running = 0 EndFunc Func Help() Local $help = "Enter entire program path or button will may be blank. There are 3 ways to enter the path: 1) Enter it manually. 2) Use the browse button. 3) Find the program or file and drag it to the file box. If you select a shortcut, make sure the .lnk extension is removed." & @CRLF & @CRLF _ & "If program does not have an icon associated with it, a generic icon will be on the button." & @CRLF & @CRLF _ & "Any file type can be entered, it's associated program's icon will be shown. Example: file.txt will show Notepad's icon." & @CRLF & @CRLF _ & "To enter a email address precede it with 'mailto:'; the default email program's icon will be on the button."& @CRLF & @CRLF _ & "If a file's full path is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the name for shortcut box, it will show up in the tooltip." & @CRLF & @CRLF _ & "Bar can be placed anywhere and it will be remembered."& @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar. If the bar isn't move more than 3 pixels, the options dialog will open." MsgBox(0, "Shortcut Bar Help", $help) EndFunc “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
rdwray Posted June 4, 2011 Author Share Posted June 4, 2011 This is the final and no more changes are coming. There was a problem with the tooltip in which if you passed over a button and moved off of the bar and back to the same button, the tooltip would not appear. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Icon_Add=Generic.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> $_MissingIconIdx = 4 Opt("TrayAutoPause",0) Opt("MustDeclareVars", 0) Opt("TrayIconDebug", 1) ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $SC_CLOSE = 0xF060 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. Global $newCursor = 16, $oldCursor HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "\ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0,24, 24, $BS_ICON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON) LoadIcon($i) $y += 24 Next EndIf GUISetBkColor(0xFF0000, $hGuiBar) GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com/",".net/",".org/",".edu/",".info/",".us/",".biz/",".gov/",".mil/"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringLeft($sc[$i][1], 7) = "mailto:" then ; Mail $var = RegRead("HKEY_CLASSES_ROOT\mailto\DefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringRight($sc[$i][1], 4) = ".exe" Then ; Executable. ToolTip(GUICtrlRead($bCtrl[$i])) If @Compiled And GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then _GUICtrlButton_SetImageList($bCtrl[$i], _GetImageListHandle(@AutoItExe, $_MissingIconIdx), 4) ; Use icon located in program. Else If GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then GUICtrlSetImage($bCtrl[$i], "Bible24.ico") ; Use external icon. EndIf ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":\" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "\Internet Explorer\iexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(24, 24, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/96988-winapi-findexecutable-replacement/page__p__697477__hl__assocquerystringw__fromsearch__1#entry697477 Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER + $WS_SIZEBOX, $WS_EX_ACCEPTFILES) ; Disable close button "X". $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $hGuiOpt, "int", 0) $hSysMenu = $dSysMenu[0] DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hGuiOpt) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetState(-1,$GUI_DROPACCEPTED) ; Drag and drop files. GUISetState() GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) GUISetState(@SW_HIDE, $hGuiOpt) Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) ; Check for keyup instead of down. If the cursor is moved off of the button the program will not run. If _IsPressed("01", $dll) Then Sleep(100) If Not _IsPressed("01", $dll) And WinActive($hGuiBar) Then RunProg() EndIf If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If Not _IsPressed("02", $dll) And $moved = true Then WriteFile() $moved = False EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) GUIctrlSetCursor($ID[4], 0) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") $oldBut = "" EndIf Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) If StringMid($sc[$bID -2][1], 5, 3) = "://" Then If StringRight($sc[$bID -2][1], 1) <> "/" then ; Back slash is required by Windows. $sc[$bID -2][1] = $sc[$bID -2][1] & "/" GUICtrlSetData($file, $sc[$bID -2][1]) EndIf EndIf If StringRight($sc[$bID -2][1], 4) = ".lnk" Then $sc[$bID -2][1] = StringLeft($sc[$bID -2][1], StringLen($sc[$bID -2][1]) -4) GUICtrlSetData($file, $sc[$bID -2][1]) ; MsgBox("", "", StringMid($sc[$bID -2][1], 5, 3)) EndIf $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) If $WinPos2[0] + $WinPos2[2] > @DesktopWidth Then WinMove("ShortCutBar", "", @DesktopWidth - $WinPos2[2], $WinPos2[1]) ; +-3 allows for some movement error when trying edit options. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "\ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "\ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "\ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg(); If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then if StringRight($sc[$ID[4]-2][1], 4) <> ".exe" And StringRight($sc[$ID[4]-2][1],1) <> "}" Then ShellExecute($sc[$ID[4]-2][1]) ; Open folder. else DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0) Run($sc[$ID[4]-2][1]) ; Run progarms. DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1) EndIf EndIf Sleep(100) ; Got to give enough time for program to open or more than 1 copy will be ran. EndFunc Func Help() Local $help = "Enter entire program path or button will may be blank. There are 3 ways to enter the path: 1) Enter it manually. 2) Use the browse button. 3) Find the program or file and drag it to the file box. If you select a shortcut, make sure the .lnk extension if removed." & @CRLF & @CRLF _ & "If program does not have an icon associated with it, a generic icon will be on the button." & @CRLF & @CRLF _ & "Any file type can be entered, it's associated program's icon will be shown. Example: file.txt will show Notepad's icon." & @CRLF & @CRLF _ & "To enter a email address precede it with 'mailto:'; the default email program's icon will be on the button."& @CRLF & @CRLF _ & "If a file's full path is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the name for shortcut box, it will show up in the tooltip." & @CRLF & @CRLF _ & "Bar can be placed anywhere and it will be remembered."& @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar. If the bar isn't move more than 3 pixels, the options dialog will open." MsgBox(0, "Shortcut Bar Help", $help) EndFunc “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 4, 2011 Share Posted June 4, 2011 You specify that there should be an icon called generic.ico for any items that don't have a default icon, but you changed the code from the April 7th version on by using Bible24.ico instead. Also, an option for this style BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW) might be a good option so that the button bar stays on top of other windows, otherwise the bar kept disappearing for me and not behind other windows but completely. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 4, 2011 Author Share Posted June 4, 2011 (edited) You specify that there should be an icon called generic.ico for any items that don't have a default icon, but you changed the code from the April 7th version on by using Bible24.ico instead. Also, an option for this style BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW) might be a good option so that the button bar stays on top of other windows, otherwise the bar kept disappearing for me and not behind other windows but completely. Opps, copy and paste is hazardous to programming, that is the .ico I am using. Correction below: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Icon_Add=Generic.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #Include <ButtonConstants.au3> #Include <Misc.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <GuiConstants.au3> #include <GuiImageList.au3> $_MissingIconIdx = 4 Opt("TrayAutoPause",0) Opt("MustDeclareVars", 0) Opt("TrayIconDebug", 1) ; Variables Global $ASSOCF_VERIFY = 0x00000040 Global $ASSOCSTR_EXECUTABLE = 2 Global $SC_CLOSE = 0xF060 Global $dll = DllOpen("user32.dll") ; _IsKeypressed events. Global $i, $x, $y, $str, $WinPos ; Generic values Global $ID, $hGuiBar, $bCtrl[27], $sc[27][3], $wOrt, $wLeft, $wTop ; GuiBar window. Global $hGuiOpt, $file, $alias, $key, $showbar, $clear, $orient, $Save, $close, $exit ; Options window. Global $moved, $bID, $teststr ; Misc. Global $newCursor = 16, $oldCursor HotKeySet("!{F1}", "Help") ;=====================Read in data.===================== LoadData() Func LoadData() For $i = 1 to 26 ; Must have same value as control ID or tooltip crashes program. $sc[$i][1] = IniRead(@ScriptDir & "ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, "") $sc[$i][2] = IniRead(@ScriptDir & "ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, "") Next $wOrt = IniRead(@ScriptDir & "ShortCuts.ini", "Orientation", "Orient", "") $wLeft = IniRead(@ScriptDir & "ShortCuts.ini", "Position", "Left", "") $wTop = IniRead(@ScriptDir & "ShortCuts.ini", "Position", "Top", "") EndFunc ;=====================Create bar.===================== CreateBar() Func CreateBar() $x = 0 $y = 0 If $wOrt = "" Then $wOrt = 4 ; In case .ini is not found. .ini is generated on first save or exit. If $wOrt = 4 Then ; Horizontal. $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW $hGuiBar = GUICreate("ShortCutBar", 24 * 26, 24, $wLeft, $wTop, $WS_POPUP, $WS_EX_TOOLWINDOW) ; GUICtrlSetDefBkColor (0xff0000, $hGuiBar ) ; Keeps icons from appearing. GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", $x, 0,24, 24, $BS_ICON) ; GUICtrlSetBkColor( $bCtrl[$i], 0xff0000) ; Keeps icons from appearing. LoadIcon($i) $x += 24 Next Else ; Verical. $hGuiBar = GUICreate("ShortCutBar", 24, 24 * 26,$wLeft, $wTop, $WS_POPUP ,$WS_EX_TOOLWINDOW) GUISetFont(11, 400, 0, "Algerian") For $i = 1 to 26 $bCtrl[$i] = GUICtrlCreateButton("", 0, $y, 24, 24, $BS_ICON) LoadIcon($i) $y += 24 Next EndIf GUISetBkColor(0xFF0000, $hGuiBar) GUISetState(@SW_SHOW, $hGuiBar) EndFunc ; CreateBar() Func LoadIcon($i) Local $prog, $iconfound, $int ; Full internet string: ".ac",".af",".al",".am",".as",".at",".au",".az",".be",".biz",".bt",".ca",".cc",".ch",".cn",".coop",".cx",".cz",".de",".dk",".dz",".ec",".edu",".ee",".eg",".es",".fo",".fr",".ga",".gf",".gl",".gov",".gr",".gs",".hk",".il",".in",".info",".io",".is",".it",".jp",".kr",".kz",".li",".lu",".ly",".mc",".mil",".mm",".ms",".mx",".net",".nl",".no",".nu",".nz",".org",".pl",".pt",".ro",".ru",".se",".sg",".sg",566".tc",".st",".tc",".tf",".th",".tj",".tm",".to",".uk",".us", Local $http[9] = [".com/",".net/",".org/",".edu/",".info/",".us/",".biz/",".gov/",".mil/"] ; Executable If $sc[$i][1] = "" Then ; No data. GUICtrlSetData($bCtrl[$i], Chr($i + 64)) ElseIf StringLeft($sc[$i][1], 7) = "mailto:" then ; Mail $var = RegRead("HKEY_CLASSES_ROOTmailtoDefaultIcon", "") $var = StringLeft($var, Stringlen($var) -2) GUICtrlSetImage($bCtrl[$i], $var, 1, 0) ElseIf StringRight($sc[$i][1], 4) = ".exe" Then ; Executable. ToolTip(GUICtrlRead($bCtrl[$i])) If @Compiled And GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then _GUICtrlButton_SetImageList($bCtrl[$i], _GetImageListHandle(@AutoItExe, $_MissingIconIdx), 4) ; Use icon located in program. Else If GUICtrlSetImage($bCtrl[$i], $sc[$i][1], 1, 0) = 0 Then GUICtrlSetImage($bCtrl[$i], "Generic.ico") ; Use external icon. EndIf ElseIf StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) = "." Then ; Misc files $prog = _FileAssociation(StringRight($sc[$i][1], 4)) ; Get associated program for file type. If $prog ="" Then $prog = "Shell32.dll" ; Generic icon used when program not found. GUICtrlSetImage($bCtrl[$i], $prog, 1, 0) ElseIf StringMid($sc[$i][1], 2, 2) = ":" And StringMid($sc[$i][1], Stringlen($sc[$i][1]) -3, 1) <> "." Then ; Folders GUICtrlSetImage($bCtrl[$i], "Shell32.dll", 4, 0) ; Folder icon. EndIf ; Internet For $int = 0 to 8 If StringRight($sc[$i][1], StringLen($http[$int])) = $http[$int] Then GUICtrlSetImage($bCtrl[$i], @ProgramFilesDir & "Internet Exploreriexplore.exe", 1, 0) EndIf Next EndFunc ; LoadIcon($i) ; using image list to set image and text on button Func _GetImageListHandle($sFile, $nIconID = 0) Local $hImage = _GUIImageList_Create(24, 24, 5, 3) ; use small icons (16x16) _GUIImageList_AddIcon($hImage, $sFile, $nIconID) Return $hImage EndFunc ;==>_GetImageListHandle ; _FileAssociation By WideBoyDixon ; http://www.autoitscript.com/forum/topic/...cquerystringw__fromsearch__1#e Func _FileAssociation($sExt) Local $aCall Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _ "dword", $ASSOCF_VERIFY, _ "dword", $ASSOCSTR_EXECUTABLE, _ "wstr", $sExt, _ "ptr", 0, _ "wstr", "", _ "dword*", 65536) If @error Then Return SetError(1, 0, ""); call failed EndIf If Not $aCall[0] Then Return SetError(0, 0, $aCall[5]) ElseIf $aCall[0] = 0x80070002 Then Return SetError(0, 0, "{unknown}"); COM Error 0x80070002, ?The system cannot find the file specified.' ElseIf $aCall[0] = 0x80004005 Then Return SetError(0, 0, "{fail}"); E_FAIL Else Return SetError(2, $aCall[0], ""); EndIf EndFunc ; _FileAssociation() ;=====================Create Options.===================== $hGuiOpt = GUICreate("Options", 500, 350, (@DesktopWidth / 2) -250, (@DesktopHeight / 2) - 150, $WS_BORDER + $WS_SIZEBOX, $WS_EX_ACCEPTFILES) ; Disable close button "X". $dSysMenu = DllCall("User32.dll", "hwnd", "GetSystemMenu", "hwnd", $hGuiOpt, "int", 0) $hSysMenu = $dSysMenu[0] DllCall("User32.dll", "int", "RemoveMenu", "hwnd", $hSysMenu, "int", $SC_CLOSE, "int", 0) DllCall("User32.dll", "int", "DrawMenuBar", "hwnd", $hGuiOpt) GUISetFont(11, 400, 0, "Tahoma") GUICtrlCreateLabel("Press Alt+F1 for help...", 20, 10) GUICtrlCreateLabel("Enter program path or:", 90, 40) $browse = GUICtrlCreateButton("Browse", 280, 30) $file = GUICtrlCreateInput("", 90, 70, 390, 30) GUICtrlSetState(-1,$GUI_DROPACCEPTED) ; Drag and drop files. GUISetState() GUICtrlSetData($file, $sc[1][1]) GUICtrlCreateLabel("Enter name for shortcut:", 90, 110) $alias = GUICtrlCreateInput("", 90, 140, 390, 30) $Clear = GUICtrlCreateButton("&Clear", 200, 180, 120) GUICtrlSetData($alias, $sc[1][2]) GUICtrlCreateLabel("Select" & @CRLF & "Key", 20, 45) $key = GUICtrlCreateList("A", 20, 90, 50, 150) For $i = 66 to 89 $str &= Chr($i) & "|" Next $str &= "Z" GUICtrlSetData($key, $str, "A") $orient = GUICtrlCreateCheckbox("Checked = Verticle; Uncheck = Horizontal", 90, 220, 390) GUICtrlSetState($orient, $wOrt) GUICtrlCreateLabel("Save after each change!", 150, 250) $Save = GUICtrlCreateButton("&Save", 65, 280, 120) $close = GUICtrlCreateButton("&Close Options", 189, 280, 120) $exit = GUICtrlCreateButton("&Exit Program", 313, 280, 120) GUISetState(@SW_HIDE, $hGuiOpt) Main() Func Main() Local $tPOINT, $hWnd Local $oldBut, $oldkey $moved = False While 1 $ID = GUIGetCursorInfo($hGuiBar) $tPOINT = _WinApi_GetMousePos() $hWnd = _WinApi_WindowFromPoint($tPOINT) $hParent = _WinApi_GetParent($hWnd) ; Check for keyup instead of down. If the cursor is moved off of the button the program will not run. If _IsPressed("01", $dll) Then Sleep(100) If Not _IsPressed("01", $dll) And WinActive($hGuiBar) Then RunProg() EndIf If _IsPressed("02", $dll) And WinActive($hGuiBar) Then MoveBar($hGuiBar) If $moved = False And $ID[4] > 2 Then ; If $moved = true the bar was moved - don't open options. GUICtrlSetData($key, Chr($ID[4] + 62)) GUICtrlSetData($file, $sc[$ID[4]-2][1]) GUICtrlSetData($alias, $sc[$ID[4]-2][2]) $bID = $ID[4] ; Open different window, save ID of button selected. GUISetState(@SW_SHOW, $hGuiOpt) ; Open options window if the shortcur bar has not been moved. _WinAPI_SetFocus($save) EndIf EndIf If Not _IsPressed("02", $dll) And $moved = true Then WriteFile() $moved = False EndIf If $hParent = $hGuiBar And $ID[4] > 2 And $ID[4] <> $oldBut Then If $sc[$ID[4]-2][2] <> "" Then Tooltip($sc[$ID[4]-2][2]) GUIctrlSetCursor($ID[4], 0) else ToolTip("Press Alt+F1 for help." & @CRLF _ & "Right click to open options." & @CRLF _ & "Right click and hold to move.") EndIf $oldBut = $ID[4] EndIf If $hParent <> $hGuiBar Then ToolTip("") $oldBut = "" EndIf Switch GUIGetMsg(0) Case $browse GUICtrlSetData($file, FileOpenDialog("Select file for shortcut", @HomeDrive, "All (*.*)", 1 )) Case $clear GUICtrlSetData($file, "") GUICtrlSetData($alias, "") Case $key ; Load data based on key value. If GUICtrlRead($key) <> $oldkey Then $oldkey = (Asc(GUICtrlRead($key))-64) GUICtrlSetData($file, $sc[$oldkey][1]) GUICtrlSetData($alias, $sc[$oldkey][2]) $bID = $oldkey + 2 ; Update in case of concurrent save. EndIf Case $orient WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $save $sc[$bID -2][1] = GUICtrlRead($file) If StringMid($sc[$bID -2][1], 5, 3) = "://" Then If StringRight($sc[$bID -2][1], 1) <> "/" then ; Back slash is required by Windows. $sc[$bID -2][1] = $sc[$bID -2][1] & "/" GUICtrlSetData($file, $sc[$bID -2][1]) EndIf EndIf If StringRight($sc[$bID -2][1], 4) = ".lnk" Then $sc[$bID -2][1] = StringLeft($sc[$bID -2][1], StringLen($sc[$bID -2][1]) -4) GUICtrlSetData($file, $sc[$bID -2][1]) ; MsgBox("", "", StringMid($sc[$bID -2][1], 5, 3)) EndIf $sc[$bID -2][2] = GUICtrlRead($alias) WriteFile() GUIDelete($hGuiBar) LoadData() CreateBar() Case $close GUISetState(@SW_HIDE, $hGuiOpt) Case $exit WriteFile() ; Save position of window. GUIDelete($hGuiOpt) ; Delete Options window. GUIDelete($hGuiBar) ; Delete Shortcut window. Exit EndSwitch Wend EndFunc ;<<--Main() Func MoveBar($hWnd) Local $PosDiff[2], $WinPos2 While 1 Local $MousePos = MouseGetPos () $WinPos = WinGetPos ($hWnd,"") $PosDiff[0] = $WinPos[0] - $MousePos[0] $PosDiff[1] = $WinPos[1] - $MousePos[1] While _IsPressed ("02", $dll) $MousePos = MouseGetPos () WinMove ($hWnd, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1]) WEnd Sleep (10) ExitLoop WEnd $WinPos2 = WinGetPos ($hWnd,"") If $WinPos2[0] < 0 Then WinMove("ShortCutBar", "", 0, $WinPos2[1]) If $WinPos2[1] < 0 Then WinMove("ShortCutBar", "", $WinPos2[0], 0) If $WinPos2[0] + $WinPos2[2] > @DesktopWidth Then WinMove("ShortCutBar", "", @DesktopWidth - $WinPos2[2], $WinPos2[1]) ; +-3 allows for some movement error when trying edit options. If ($WinPos[0] < $WinPos2[0] - 3) Or ($WinPos[1] < $WinPos2[1] - 3) Or _ ($WinPos[0] > $WinPos2[0] + 3) Or ($WinPos[1] > $WinPos2[1] + 3)Then $moved = True ; If the window was moved, don't run program on return. Else $moved = False EndIf Sleep (10) EndFunc Func WriteFile() For $i = 1 to 26 IniWrite(@ScriptDir & "ShortCuts.ini", "ShortCuts" & $i, "Key" & $i, Chr($i + 64)) IniWrite(@ScriptDir & "ShortCuts.ini", "ShortCuts" & $i, "Program" & $i, $sc[$i][1]) IniWrite(@ScriptDir & "ShortCuts.ini", "ShortCuts" & $i, "Alias" & $i, $sc[$i][2]) Next IniWrite(@ScriptDir & "ShortCuts.ini", "Orientation", "Orient", GUICtrlRead($orient)) $WinPos = WinGetPos("ShortCutBar") If $WinPos[0] = "" then $WinPos[0] = 0 If $WinPos[1] = "" then $WinPos[1] = 0 IniWrite(@ScriptDir & "ShortCuts.ini", "Position", "Left", $WinPos[0]) IniWrite(@ScriptDir & "ShortCuts.ini", "Position", "Top", $WinPos[1]) EndFunc Func RunProg(); If $ID[4] > 2 And $sc[$ID[4]-2][1] <> "" then if StringRight($sc[$ID[4]-2][1], 4) <> ".exe" And StringRight($sc[$ID[4]-2][1],1) <> "}" Then ShellExecute($sc[$ID[4]-2][1]) ; Open folder. else DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0) Run($sc[$ID[4]-2][1]) ; Run progarms. DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 1) EndIf EndIf Sleep(100) ; Got to give enough time for program to open or more than 1 copy will be ran. EndFunc Func Help() Local $help = "The first thing needed is a generic 24x24 icon - see line 5 of program" & @CRLF & @CRLF _ & "Enter entire program path or button may be blank. There are 3 ways to enter the path: 1) Enter it manually. 2) Use the browse button. 3) Find the program or file and drag it to the file box. If you select a shortcut, make sure the .lnk extension is removed." & @CRLF & @CRLF _ & "If the program does not have an icon associated with it, a generic icon will be on the button." & @CRLF & @CRLF _ & "Any file type can be entered, it's associated program's icon will be shown if it is registered. Example: file.txt will show Notepad's icon." & @CRLF & @CRLF _ & "To enter an email address precede it with 'mailto:'; the default email program's icon will be on the button."& @CRLF & @CRLF _ & "If a file's full path is entered in the program box, the associated program's icon will be on the button." & @CRLF & @CRLF _ & "if a website is entered, it must be complete; your browser's icon will be on the button." & @CRLF & @CRLF _ & "Enter anything in the shortcut box to identify what is in the file box, it will show up in a tooltip." & @CRLF & @CRLF _ & "Right click to open options." & @CRLF & @CRLF _ & "Right click and hold to move bar. If the bar isn't move more than 3 pixels, the options dialog will open." _ & "Bar can be placed anywhere and it will be remembered." MsgBox(0, "Shortcut Bar Help", $help) EndFunc Edited March 9, 2012 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 4, 2011 Share Posted June 4, 2011 Really nice script by the way, I forgot to mention it before. I'm thinking of making use of it on my computer and eliminate some of the desktop clutter I have for the stuff I access the most. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 4, 2011 Author Share Posted June 4, 2011 Really nice script by the way, I forgot to mention it before. I'm thinking of making use of it on my computer and eliminate some of the desktop clutter I have for the stuff I access the most.Just in case you want to know, I have it running twice by putting it into separate folder. Don't try and put it into one folder because of the .ini file unless you want to rename it in the script. “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
Maffe811 Posted June 4, 2011 Share Posted June 4, 2011 well you could make it so if fileExist(banana) then change this script to 2... ? And another thing, cause i havent downloaded, is the grey bg removable ? Cause i have an idea: What if you have a tray icon and you have a menu iten named "Hide/show" Then on click it would move the bar off screen! Then when you click the menu again it shows and automaticly goes ontop of all programs and windows! Idk... i had a brilliant idea but i lost it... [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
rdwray Posted June 4, 2011 Author Share Posted June 4, 2011 (edited) well you could make it so if fileExist(banana) then change this script to 2... ?And another thing, cause i havent downloaded, is the grey bg removable ?Cause i have an idea:What if you have a tray icon and you have a menu iten named "Hide/show"Then on click it would move the bar off screen! Then when you click the menu again it shows and automaticly goes ontop of all programs and windows!Idk... i had a brilliant idea but i lost it... I didn't want it ontop since I normally don't work full screen with with any apps, I placed the bar at the top center and another one just below it. The script is up for grabs if anyone wants to make suggestions with snippets. This one is fairly simple for someone to build on the graphics if they leave the process logic as is - I spent a lot of time to get it right with help from the forum. Edited June 4, 2011 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
Maffe811 Posted June 4, 2011 Share Posted June 4, 2011 I just had an idea! You should make the grapichs like rocketdock does! End pices and the bar backround! 3 different images in... appdata\shortcutsbar so pepole can easily customize it [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
liuyifan494 Posted June 5, 2011 Share Posted June 5, 2011 The effect is so cool,thank you for sharing! 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