#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Fileversion=2.0.1.2 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #AutoIt3Wrapper_Au3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/sfc #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/striponly #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include Opt("GUIOnEventMode", 1) Global Const $WS_EX_COMPOSITED = 0x02000000 ;makes pictures show transition smoother Global Const $WM_EXITSIZEMOVE = 0x232 Global Const $WM_DROPFILES = 0x233 Global Const $DF_NAME = @SystemDir & '\shell32.dll' Global Const $DF_INDEX = 0 Global Const $IniPath = @ScriptDir & "\DeskBox.ini" Global Const $GUISize = 60 Global Const $GUIX = IniRead($IniPath, "Settings", "X", @DesktopWidth - $GUISize - 20) Global Const $GUIY = IniRead($IniPath, "Settings", "Y", 20) Global Const $IconSize = 32 Global $Maximized = False, $DeleteMode = False, $GlobalWindowPosition, $IconsAcross Dim $IconHandles[1], $LabelHandles[1] Dim $Icons = _GetIconInfo() $GUI = GUICreate("", $GUISize, $GUISize, $GUIX, $GUIY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_COMPOSITED, $WS_EX_ACCEPTFILES), WinGetHandle("[CLASS:Progman]")) GUISetBkColor(0x404040) WinSetTrans($GUI, "", 220) _GuiRoundCorners($GUI, 0, 0, 8, 8) GUICtrlCreateLabel("DeskBox", 0, $GUISize - 14, $GUISize, 14, $SS_CENTER, $GUI_WS_EX_PARENTDRAG) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT) GUICtrlSetBkColor(-1, 0x202020) GUICtrlSetColor(-1, 0xCCCCCC) GUICtrlCreateLabel("", 0, 0, $GUISize - 45, 14, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT) GUICtrlSetBkColor(-1, 0xBBFF00) $DeleteButton = GUICtrlCreateLabel("x", $GUISize - 45, 0, 15, 14, $SS_CENTER) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) GUICtrlSetOnEvent(-1, "ButtonHandler") GUICtrlSetBkColor(-1, 0xBBFF00) GUICtrlSetTip(-1, "Delete Element") $AddButton = GUICtrlCreateLabel("+", $GUISize - 30, 0, 15, 14, $SS_CENTER) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) GUICtrlSetOnEvent(-1, "ButtonHandler") GUICtrlSetBkColor(-1, 0xBBFF00) GUICtrlSetTip(-1, "Add Element") $CloseButton = GUICtrlCreateLabel("X", $GUISize - 15, 0, 15, 14, $SS_CENTER) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) GUICtrlSetOnEvent(-1, "ButtonHandler") GUICtrlSetBkColor(-1, 0xBBFF00) GUICtrlSetTip(-1, "Close") GUIRegisterMsg($WM_SIZE, "WM_SIZEMOVE") GUIRegisterMsg($WM_EXITSIZEMOVE, "WM_SIZEMOVE") GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES") If $GUIX + $GUISize > @DesktopWidth Then WinMove($GUI, "", @DesktopWidth - $GUISize, Default) If $GUIY + $GUISize > @DesktopHeight Then WinMove($GUI, "", @DesktopHeight - $GUISize, Default) If $GUIX < 0 Then WinMove($GUI, "", 0, Default) If $GUIY < 0 Then WinMove($GUI, "", Default, 0) _GuiRoundCorners($GUI, 0, 0, 8, 8) WriteWindowPosition() GUISetState(@SW_SHOW, $GUI) While 1 If Not BitAND(WinGetState(WinGetHandle("[Active]")), 32) And Not _IsPressed("01") Then $MGP = MouseGetPos() If Not $Maximized And _WinAPI_PointInRect($MGP[0], $MGP[1], $GlobalWindowPosition[0], $GlobalWindowPosition[1] + 14, $GlobalWindowPosition[2], $GlobalWindowPosition[3] - 28) Then Maximize() ElseIf $Maximized And Not _WinAPI_PointInRect($MGP[0], $MGP[1], $GlobalWindowPosition[0], $GlobalWindowPosition[1], $GlobalWindowPosition[2], $GlobalWindowPosition[3]) Then Minimize() EndIf Sleep(100) ;speed up response time Else Sleep(350) ;light footprint when cannot be seen or file is being dragged (or other times when mouse is down) EndIf WEnd Func _GetFileTitle($sFile) Local $splitpath = StringSplit($sFile, "\") Return $splitpath[UBound($splitpath) - 1] EndFunc ;==>_GetFileTitle Func _GetIconInfo() Local $Sections = IniReadSectionNames($IniPath) Local $aRet[2][2] = [[0, 0]] Local $FileName Local $i If IsArray($Sections) And ($Sections[1] <> "Settings" Or UBound($Sections) > 2) Then ReDim $aRet[$Sections[0] + 1][2] ;make sure there are enough elements For $i = 1 To $Sections[0] $FileName = IniRead($IniPath, $Sections[$i], "FileName", "") If StringRight($FileName, 4) = ".lnk" Then Local $Shortcut = FileGetShortcut($FileName) $FileName = $Shortcut[0] EndIf If FileExists($FileName) Then $aRet[0][0] += 1 $aRet[$aRet[0][0]][0] = $Sections[$i] $aRet[$aRet[0][0]][1] = $FileName ElseIf $Sections[$i] <> "Settings" Then IniDelete($IniPath, $Sections[$i]) EndIf Next ReDim $aRet[$aRet[0][0] + 1][2] ;resize the array in case some files didn't exist ElseIf (IsArray($Sections) And $Sections[1] = "Settings") Or Not IsArray($Sections) Then IniWrite($IniPath, "My Computer", "FileName", @HomeDrive & "\") $aRet[0][0] += 1 $aRet[$aRet[0][0]][0] = "My Computer" $aRet[$aRet[0][0]][1] = @HomeDrive & "\" EndIf $IconsAcross = Ceiling(Sqrt(UBound($aRet) - 1)) ;try to make icons into a square arrangement Return $aRet EndFunc ;==>_GetIconInfo Func _GetRegDefIcon($path) Local $FileName, $Count, $Name, $Ext, $Curver, $DefaultIcon, $Ret[2] = [$DF_NAME, $DF_INDEX] $FileName = StringTrimLeft($path, StringInStr($path, '\', 0, -1)) $Count = StringInStr($FileName, '.', 0, -1) If $Count > 0 Then $Count = StringLen($FileName) - $Count + 1 EndIf $Name = StringStripWS(StringTrimRight($FileName, $Count), 3) $Ext = StringStripWS(StringRight($FileName, $Count - 1), 8) If StringLen($Ext) = 0 Then Return $Ret EndIf $Curver = StringStripWS(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $Ext, '') & '\CurVer', ''), 3) If (@error) Or (StringLen($Curver) = 0) Then $DefaultIcon = _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $Ext, '') & '\DefaultIcon', ''), '''', '')) Else $DefaultIcon = _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & $Curver & '\DefaultIcon', ''), '''', '')) EndIf $Count = StringInStr($DefaultIcon, ',', 0, -1) If $Count > 0 Then $Count = StringLen($DefaultIcon) - $Count $Ret[0] = StringStripWS(StringTrimRight($DefaultIcon, $Count + 1), 3) If $Count > 0 Then $Ret[1] = StringStripWS(StringRight($DefaultIcon, $Count), 8) EndIf Else $Ret[0] = StringStripWS(StringTrimRight($DefaultIcon, $Count), 3) EndIf If StringLeft($Ret[0], 1) = '%' Then $Count = DllCall('shell32.dll', 'int', 'ExtractIcon', 'int', 0, 'str', $path, 'int', -1) If $Count[0] = 0 Then $Ret[0] = $DF_NAME If StringLower($Ext) = 'exe' Then $Ret[1] = 2 Else $Ret[1] = 0 EndIf Else $Ret[0] = StringStripWS($path, 3) $Ret[1] = 0 EndIf Else If (StringLen($Ret[0]) > 0) And (StringInStr($Ret[0], '\', 0) = 0) Then $Ret[0] = @SystemDir & '\' & $Ret[0] EndIf EndIf If Not FileExists($Ret[0]) Then $Ret[0] = $DF_NAME $Ret[1] = $DF_INDEX EndIf Return $Ret EndFunc ;==>_GetRegDefIcon Func _GuiRoundCorners($hWnd, $i_x1, $i_y1, $i_x3, $i_y3) Local $Pos, $Ret, $Ret2 $Pos = WinGetPos($hWnd) $Ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $Pos[2], "long", $Pos[3], "long", $i_x3, "long", $i_y3) If $Ret[0] Then $Ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $Ret[0], "int", 1) If $Ret2[0] Then Return 1 Else Return 0 EndIf Else Return 0 EndIf EndFunc ;==>_GuiRoundCorners Func _WinAPI_PointInRect($iX, $iY, $iLeft, $iTop, $iWidth, $iHeight) Local $aResult Local $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($tRect, "Left", $iLeft) DllStructSetData($tRect, "Top", $iTop) DllStructSetData($tRect, "Right", $iLeft + $iWidth) DllStructSetData($tRect, "Bottom", $iTop + $iHeight) $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY) If @error Then Return SetError(@error, 0, False) Return $aResult[0] <> 0 EndFunc ;==>_WinAPI_PointInRect Func ButtonHandler() Switch @GUI_CtrlId Case $CloseButton Exit Case $AddButton $Open = FileOpenDialog("Chose File", @DesktopDir, "Executables (*.exe)|Shortcuts (*.lnk)|All Files (*.*)", 3) If Not @error Then IniWrite($IniPath, $Open, "FileName", $Open) $Icons = _GetIconInfo() Minimize() Maximize() EndIf Case $DeleteButton $DeleteMode = Not $DeleteMode If $DeleteMode Then GUICtrlSetColor($DeleteButton, 0xFF0000) GUICtrlSetTip($DeleteButton, "Delete Mode ON") Else GUICtrlSetColor($DeleteButton, 0x000000) GUICtrlSetTip($DeleteButton, "Delete Mode OFF") EndIf EndSwitch EndFunc ;==>ButtonHandler Func ExecuteHandler() ConsoleWrite("UBound($IconHandles) - 1: " & UBound($IconHandles) - 1 & @CRLF) For $i = 1 To UBound($IconHandles) - 1 If @GUI_CtrlId = $IconHandles[$i] Then ExitLoop Next ;~ If $i > $Icons[0][0] Then Return ConsoleWrite("$i: " & $i & @CRLF) ConsoleWrite("$Icons[$i][1]: " & $Icons[$i][1] & @CRLF) If $DeleteMode Then If UBound($Icons) > 2 Then IniDelete($IniPath, $Icons[$i][0]) $DeleteMode = Not $DeleteMode If $DeleteMode Then GUICtrlSetColor($DeleteButton, 0xFF0000) GUICtrlSetTip($DeleteButton, "Delete Mode ON") Else GUICtrlSetColor($DeleteButton, 0x000000) GUICtrlSetTip($DeleteButton, "Delete Mode OFF") EndIf Minimize() $Icons = _GetIconInfo() Else $DeleteMode = Not $DeleteMode If $DeleteMode Then GUICtrlSetColor($DeleteButton, 0xFF0000) GUICtrlSetTip($DeleteButton, "Delete Mode ON") Else GUICtrlSetColor($DeleteButton, 0x000000) GUICtrlSetTip($DeleteButton, "Delete Mode OFF") EndIf Minimize() MsgBox(64, "ERROR", "At least one file must be in the box!", 0, $GUI) EndIf Else If StringRight($Icons[$i][1], 4) = ".lnk" Then Local $Shortcut = FileGetShortcut($Icons[$i][1]) ShellExecute($Shortcut[0]) Else ShellExecute($Icons[$i][1]) EndIf EndIf EndFunc ;==>ExecuteHandler Func Maximize() If $IconsAcross > 0 Then Local $VerticalSpacing = 5 Local $Size = 14 + 19 + (($IconsAcross) * $IconSize) + ((15 + $VerticalSpacing) * $IconsAcross) If $Size < $GUISize Then $Size = $GUISize Local $HorizontalSpacing = ($Size - (($IconsAcross) * $IconSize) - ($VerticalSpacing * 2)) / ($IconsAcross - 1) Local $Icon, $Label, $X, $Y, $i For $i = $GlobalWindowPosition[2] To $Size Step 7 * $IconsAcross WinMove($GUI, "", Default, Default, $i, $i) _GuiRoundCorners($GUI, 0, 0, 8, 8) Sleep(40 / $IconsAcross) Next WinMove($GUI, "", Default, Default, $Size, $Size) If $GlobalWindowPosition[0] + $GlobalWindowPosition[2] > @DesktopWidth Then WinMove($GUI, "", @DesktopWidth - $Size, Default) If $GlobalWindowPosition[1] + $GlobalWindowPosition[3] > @DesktopHeight Then WinMove($GUI, "", @DesktopHeight - $Size, Default) If $GlobalWindowPosition[0] < 0 Then WinMove($GUI, "", 0, Default) If $GlobalWindowPosition[1] < 0 Then WinMove($GUI, "", Default, 0) _GuiRoundCorners($GUI, 0, 0, 8, 8) WriteWindowPosition() For $i = 1 To UBound($IconHandles) - 1 GUICtrlDelete($IconHandles[$i]) Next For $i = 1 To UBound($LabelHandles) - 1 GUICtrlDelete($LabelHandles[$i]) Next ReDim $IconHandles[1] ReDim $LabelHandles[1] $i = 1 For $Y = 1 To $IconsAcross For $X = 1 To $IconsAcross If StringRight($Icons[$i][1], 4) = ".exe" Or StringRight($Icons[$i][1], 4) = ".lnk" Or StringRight($Icons[$i][1], 4) = ".ani" Then $Icon = GUICtrlCreateIcon($Icons[$i][1], -1, $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)), $IconSize, $IconSize) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetTip(-1, $Icons[$i][1]) _ArrayAdd($IconHandles, $Icon) $Label = GUICtrlCreateLabel($Icons[$i][0], $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)) + $IconSize, $IconSize, 15, $SS_LEFTNOWORDWRAP) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetFont(-1, 8) GUICtrlSetColor(-1, 0xEEEEEE) GUICtrlSetTip(-1, $Icons[$i][0]) _ArrayAdd($LabelHandles, $Label) ElseIf StringInStr(FileGetAttrib($Icons[$i][1]), "D") Then $Icon = GUICtrlCreateIcon("shell32.dll", -5, $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)), $IconSize, $IconSize) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetTip(-1, $Icons[$i][1]) _ArrayAdd($IconHandles, $Icon) $Label = GUICtrlCreateLabel($Icons[$i][0], $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)) + $IconSize, $IconSize, 15, $SS_LEFTNOWORDWRAP) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetFont(-1, 8) GUICtrlSetColor(-1, 0xEEEEEE) GUICtrlSetTip(-1, $Icons[$i][0]) _ArrayAdd($LabelHandles, $Label) Else $DefaultIcon = _GetRegDefIcon($Icons[$i][1]) $Icon = GUICtrlCreateIcon($DefaultIcon[0], $DefaultIcon[1], $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)), $IconSize, $IconSize) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetTip(-1, $Icons[$i][1]) _ArrayAdd($IconHandles, $Icon) $Label = GUICtrlCreateLabel($Icons[$i][0], $VerticalSpacing + (($X - 1) * $IconSize) + ($HorizontalSpacing * ($X - 1)), 14 + $VerticalSpacing + (($Y - 1) * $IconSize) + ((15 + $VerticalSpacing) * ($Y - 1)) + $IconSize, $IconSize, 15, $SS_LEFTNOWORDWRAP) GUICtrlSetOnEvent(-1, "ExecuteHandler") GUICtrlSetFont(-1, 8) GUICtrlSetColor(-1, 0xEEEEEE) GUICtrlSetTip(-1, $Icons[$i][0]) _ArrayAdd($LabelHandles, $Label) EndIf $i += 1 If $i > UBound($Icons) - 1 Then ExitLoop Next If $i > UBound($Icons) - 1 Then ExitLoop Next $Maximized = True EndIf EndFunc ;==>Maximize Func Minimize() If $IconsAcross > 0 Then For $i = 1 To UBound($IconHandles) - 1 GUICtrlDelete($IconHandles[$i]) Next For $i = 1 To UBound($LabelHandles) - 1 GUICtrlDelete($LabelHandles[$i]) Next WinMove($GUI, "", $GlobalWindowPosition[0], $GlobalWindowPosition[1], $GUISize, $GUISize) _GuiRoundCorners($GUI, 0, 0, 8, 8) $Maximized = False EndIf EndFunc ;==>Minimize Func WM_DROPFILES($hWnd, $Msg, $wParam, $lParam) Local $tDrop, $aRet, $iCount, $File ;string buffer for file path $tDrop = DllStructCreate("char[260]") ;get file count $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "uint", -1, "ptr", DllStructGetPtr($tDrop), "int", DllStructGetSize($tDrop)) $iCount = $aRet[0] ;get file paths For $i = 0 To $iCount - 1 $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "int", DllStructGetSize($tDrop)) $File = DllStructGetData($tDrop, 1) IniWrite($IniPath, _GetFileTitle($File), "FileName", $File) Next ;finalize DllCall("shell32.dll", "int", "DragFinish", "hwnd", $wParam) If $Maximized Then Minimize() $Icons = _GetIconInfo() Return $GUI_RUNDEFMSG EndFunc ;==>WM_DROPFILES Func WM_SIZEMOVE($hWnd, $Msg, $wParam, $lParam) If $hWnd = $GUI Then WriteWindowPosition() Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZEMOVE Func WriteWindowPosition() $GlobalWindowPosition = WinGetPos($GUI) IniWrite($IniPath, "Settings", "X", $GlobalWindowPosition[0]) IniWrite($IniPath, "Settings", "Y", $GlobalWindowPosition[1]) EndFunc ;==>WriteWindowPosition