Jump to content

DeskBox


torels
 Share

Recommended Posts

Hi there

I wrote this script in the past few days. School is finishing and I hardly got some homework recently, so I had plenty of time to work on something I needed and to make it at least nice-looking ;)

WHat is doeas is create an icon on you desktop that, when hovered, grows and shows all the icons you decided to put in the "box"

To delete items just press the X on the top part of the window so it will become X. This means you are in "Delete Mode" so instead of executing whatever you click, the script deletes it from the box :D

Just click it back again to switch off the "Delete Mode"

The + on the top of the window, lets you add icons to the "box"

I hope you like it :D

Comments are welcome

here is the script:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#NoTrayIcon

Global $Width, $Icon_Handles[1], $Label_Handles[1], $Maxed = False, $DelMode = False, $t = 0
Global $Win, $IniPath = @TempDir & "\DeskBox.ini"
Global $IconSize = 32

$Icons = _GetAllInfo()

$Gui_X = IniRead($IniPath, "Settings", "X", 50)
$Gui_Y = IniRead($IniPath, "Settings", "Y", 50)
$AutoRun = IniRead($IniPath, "Settings", "AutoRun", 1)
If $AutoRun = 1 Then
    RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DeskBox", "REG_SZ", @ScriptFullPath)
Else
    RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DeskBox")
EndIf
$Gui = GUICreate("", 60, 60, $Gui_X, $Gui_Y, $WS_POPUP, $WS_EX_TOOLWINDOW, WinGetHandle("[CLASS:Progman]"))
GUISetBkColor(0x404040)
WinSetTrans($Gui, "", 220)
_GuiRoundCorners($Gui, 0, 0, 4, 4)

$Title = GUICtrlCreateLabel("DeskBox", 0, 46, 60, 14, $SS_CENTER)
GUICtrlSetBkColor(-1, 0x202020)
GUICtrlSetResizing($Title, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT)
GUICtrlSetColor($Title, 0xCCCCCC)

$Bar = GUICtrlCreateLabel("", 0, 0, 60, 16)
GUICtrlSetResizing($Bar, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT)
GUICtrlSetBkColor($Bar, 0xbbFF00)

$Add = GUICtrlCreateLabel("+", 45, 0, 15, 14, $SS_CENTER)
GUICtrlSetResizing($Add, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH)
GUICtrlSetBkColor($Add, 0xbbFF00)
GUICtrlSetTip($Add, "Add Element")

$Del = GUICtrlCreateLabel("x", 30, 0, 15, 14, $SS_CENTER)
GUICtrlSetResizing($Del, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH)
GUICtrlSetBkColor($Del, 0xbbFF00)
GUICtrlSetTip($Del, "Delete Element")

$Info = GUICtrlCreateLabel("i", 15, 0, 15, 14, $SS_CENTER)
GUICtrlSetResizing($Info, $GUI_DOCKRIGHT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH)
GUICtrlSetBkColor($Info, 0xbbFF00)
GUICtrlSetTip($Info, "Info")

ControlDisable($Gui, "", $Bar)
GUISetState()
While 1
    If $t > 2000 Then
        GUICtrlSetData($Title, "DeskBox")
        $t = ""
    EndIf
    $msg = GUIGetMsg()
    For $i = 1 To UBound($Icon_Handles) - 1
        If $msg = $Icon_Handles[$i] Or $msg = $Label_Handles[$i] Then
            _Execute($Icons[$i])
        EndIf
    Next
    Switch $msg
        Case $Add
            $Open = FileOpenDialog("Chose File", @DesktopDir, "all files (*.*)")
            If Not @error Then
                If StringInStr($Open, "]") Or StringInStr($Open, "[") Then
                    TrayTip("Error!", "Please remove any ''['' or '']'' chars from the file's name you want to add", 10, 16)
                Else
                    IniWrite($IniPath, $Open, "filename", $Open)
                EndIf
            EndIf
            $Icons = _GetAllInfo()
            $Maxed = False
        Case $Del
            If $DelMode = False Then
                GUICtrlSetColor($Del, 0xFF0000)
                GUICtrlSetTip($Del, "Delete Mode ON")
                $DelMode = True
            Else
                GUICtrlSetColor($Del, 0x000000)
                GUICtrlSetTip($Del, "Delete Mode OFF")
                $DelMode = False
            EndIf
        Case $Info
            GUICtrlSetData($Title, "CopyLeft 2009 torels_")
            $t = TimerInit()
    EndSwitch
    
    If _IsPressed("01") Then _WindowDrag()
    
    $Win = WinGetPos($Gui)
    If (MouseGetPos(0) > $Win[0] + $Win[2] + 10 Or MouseGetPos(0) < $Win[0] - 10) Then ;out X
        Min()
        ContinueLoop
    EndIf
    If (MouseGetPos(1) > $Win[1] + $Win[3] - 15 Or MouseGetPos(1) < $Win[1] - 10) Then ;out Y
        Min()
        ContinueLoop
    EndIf
    If (MouseGetPos(0) > $Win[0] And MouseGetPos(0) < $Win[0] + $Win[2]) Then ;in X
        If $Maxed = False Then Max($Win, $Width)
        ContinueLoop
    EndIf
    If (MouseGetPos(1) > $Win[1] And MouseGetPos(1) < $Win[1] + $Win[3]) Then ;in Y
        If $Maxed = False Then Max($Win, $Width)
        ContinueLoop
    EndIf
WEnd

Func Max($aWin, $Size)
    ControlShow($Gui, "", $Add)
    ControlShow($Gui, "", $Bar)
    ControlShow($Gui, "", $Del)
    ControlShow($Gui, "", $Info)
    For $i = $aWin[2] To $Size Step 10
        WinMove($Gui, "", $aWin[0], $aWin[1], $aWin[2] + $i, $aWin[2] + $i + 15 * $Width / $IconSize)
        _GuiRoundCorners($Gui, 0, 0, 4, 4)
    Next
    For $i = 1 To UBound($Icon_Handles) - 1
        GUICtrlDelete($Icon_Handles[$i])
    Next
    For $i = 1 To UBound($Label_Handles) - 1
        GUICtrlDelete($Label_Handles[$i])
    Next
    $i = 1
    $string = ""
    ReDim $Icon_Handles[1]
    For $y = 0 To $Width / $IconSize
        For $x = 0 To $Width / $IconSize
            If StringRight($Icons[$i], 4) = ".exe" Or StringRight($Icons[$i], 4) = ".lnk" Or StringRight($Icons[$i], 4) = ".ani" Then
                $Icon = GUICtrlCreateIcon($Icons[$i], -1, $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y, $IconSize, $IconSize)
                _ArrayAdd($Icon_Handles, $Icon)
                GUICtrlSetTip($Icon, $Icons[$i])
                $l = GUICtrlCreateLabel(_GetFileName($Icons[$i]), $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y + $IconSize, $IconSize, 15)
                GUICtrlSetColor(-1, 0xEEEEEE)
                GUICtrlSetTip($l, $Icons[$i])
                _ArrayAdd($Label_Handles, $l)
            ElseIf FileGetAttrib($Icons[$i]) = "D" Then
                $Icon = GUICtrlCreateIcon("shell32.dll", -5, $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y, $IconSize, $IconSize)
                _ArrayAdd($Icon_Handles, $Icon)
                GUICtrlSetTip($Icon, $Icons[$i])
                $l = GUICtrlCreateLabel(_GetFileName($Icons[$i]), $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y + $IconSize, $IconSize, 15)
                GUICtrlSetColor(-1, 0xEEEEEE)
                GUICtrlSetTip($l, $Icons[$i])
                _ArrayAdd($Label_Handles, $l)
            Else
                $Icon = GUICtrlCreateIcon(_GetIcon($Icons[$i]), -1, $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y, $IconSize, $IconSize)
                _ArrayAdd($Icon_Handles, $Icon)
                GUICtrlSetTip($Icon, $Icons[$i])
                $l = GUICtrlCreateLabel(_GetFileName($Icons[$i]), $x * $IconSize + 5 * $x, $y * $IconSize + 17 + 20 * $y + $IconSize, $IconSize, 15)
                GUICtrlSetColor(-1, 0xEEEEEE)
                GUICtrlSetTip($l, $Icons[$i])
                _ArrayAdd($Label_Handles, $l)
            EndIf
            $i += 1
            If $i > UBound($Icons)-1 Then ExitLoop
        Next
        If $i > UBound($Icons)-1 Then ExitLoop
    Next
    $Maxed = True
    $Win = WinGetPos($Gui)
EndFunc   ;==>Max

Func Min()
    If $Maxed = True Then
        ControlHide($Gui, "", $Add)
        ControlHide($Gui, "", $Bar)
        ControlHide($Gui, "", $Del)
        ControlHide($Gui, "", $Info)
        For $i = 1 To UBound($Icon_Handles) - 1
            GUICtrlDelete($Icon_Handles[$i])
        Next
        For $i = 1 To UBound($Label_Handles) - 1
            GUICtrlDelete($Label_Handles[$i])
        Next
        WinMove($Gui, "", $Win[0], $Win[1], 60, 60)
        _GuiRoundCorners($Gui, 0, 0, 4, 4)
        $Maxed = False
    EndIf
EndFunc   ;==>Min

Func _Execute($sFileName)
    If $DelMode = True Then
        If UBound($Icons)>2 Then
            IniDelete($IniPath, $sFileName)
            $Icons = _GetAllInfo()
            $Maxed = False
        Else
            MsgBox(0,"Error","Atleast One file must be in the box!")
            $Icons = _GetAllInfo()
            $Maxed = False
        EndIf
    Else
        ShellExecute($sFileName)
    EndIf
EndFunc   ;==>_Execute

Func _GetFileName($sFile)
    Local $sRet = "", $i = 1
    Do
        $i += 1
    Until StringLeft(StringRight($sFile, $i), 1) = "\"
    $sFile = StringMid($sFile, StringLen($sFile) - $i + 2, $i)
    If Not FileGetAttrib($sFile) = "D" Then ;Not a Directory
        $i = 1
        Do
            $i += 1
        Until StringRight(StringLeft($sFile, $i), 1) = "."
        $sFile = StringMid($sFile, 1, $i - 1)
    EndIf
    Return $sFile
EndFunc   ;==>_GetFileName

Func _WindowDrag()
    While _IsPressed("01")
        DllCall("user32.dll", "int", "SendMessage", "hWnd", $Gui, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
        $Win = WinGetPos($Gui)
        IniWrite($IniPath, "Settings", "X", $Win[0])
        IniWrite($IniPath, "Settings", "Y", $Win[1])
    WEnd
EndFunc   ;==>_WindowDrag

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    Dim $pos, $ret, $ret2
    $pos = WinGetPos($h_win)
    $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", $h_win, "long", $ret[0], "int", 1)
        If $ret2[0] Then
            Return 1
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc   ;==>_GuiRoundCorners

Func _GetAllInfo()
    $sections = IniReadSectionNames($IniPath)
    $W=0
    If Not IsArray($sections) Then
        $Open = FileOpenDialog("Chose File", @DesktopDir, "all files (*.*)")
        If Not @error Then
            If StringInStr($Open, "]") Or StringInStr($Open, "[") Then
                MsgBox(0,"Error!", "Please remove any ''['' or '']'' chars from the file's name you want to add")
                Return
            Else
                IniWrite($IniPath, $Open, "filename", $Open)
                $sections = IniReadSectionNames($IniPath)
                $W=1
            EndIf
        EndIf
    EndIf
    $Width = $IconSize * Ceiling(Sqrt($sections[0]+$W))
    Dim $aRet[1]
    For $i = 1 To $sections[0]
        If $sections[$i] <> "Settings" Then _ArrayAdd($aRet, IniRead($IniPath, $sections[$i], "filename", ""))
    Next
    Return $aRet
EndFunc   ;==>_GetAllInfo

Func _GetIcon($file, $ReturnType = 0)
    $FileType = StringSplit($file, ".")
    $FileType = $FileType[UBound($FileType) - 1]
    $FileParam = RegRead("HKEY_CLASSES_ROOT\." & $FileType, "")
    $DefaultIcon = RegRead("HKEY_CLASSES_ROOT\" & $FileParam & "\DefaultIcon", "")
    
    If Not @error Then
        $IconSplit = StringSplit($DefaultIcon, ",")
        ReDim $IconSplit[3]
        $Iconfile = $IconSplit[1]
        $IconID = $IconSplit[2]
    Else
        $Iconfile = @SystemDir & "\shell32.dll"
        $IconID = -219
    EndIf
    
    If $ReturnType = 0 Then
        Return $Iconfile
    Else
        Return $IconID
    EndIf
EndFunc   ;==>_GetIcon

EDIT: Now It's Working!

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

you need to add some files to the "box" by using the FileOpenDialog at the beginning of the script :D

it only runs if there are no files :D

otherwise if you did this try running it again... it works here ;)

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

This is how it is crashing

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#NoTrayIcon

Global $Width, $Icon_Handles[1], $Label_Handles[1], $Maxed = False, $DelMode = False, $t = 0
Global $Win, $IniPath = @TempDir & "\DeskBox.ini"
Global $IconSize = 32

$Icons = _GetAllInfo()


;;*** Jumps to the Function...

Func _GetAllInfo()
    $sections = IniReadSectionNames($IniPath)
    $Width = $IconSize * Ceiling(Sqrt($sections[0])) ;  ***** AND CRASHES HERE *****
    Dim $aRet[1]
    For $i = 1 To $sections[0]
        If $sections[$i] <> "Settings" Then _ArrayAdd($aRet, IniRead($IniPath, $sections[$i], "filename", ""))
    Next
    Return $aRet
EndFunc   ;==>_GetAllInfo

This is first run. there is no ini file or file open

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Ok it's working now :D

I excuse myself for the problems it was giving :D

I actually worked all the time with an existing INI file XD

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Just a little more error checking...

Func _GetAllInfo()
    $sections = IniReadSectionNames($IniPath)
    $W=0
    If Not IsArray($sections) Then
        $Open = FileOpenDialog("Chose File", @DesktopDir, "all files (*.*)")
        If Not @error Then
            If StringInStr($Open, "]") Or StringInStr($Open, "[") Then
                MsgBox(0,"Error!", "Please remove any ''['' or '']'' chars from the file's name you want to add")
                Return
            Else
                IniWrite($IniPath, $Open, "filename", $Open)
                $sections = IniReadSectionNames($IniPath)
                $W=1
            EndIf
        Else    
            MsgBox(4096, "Error", "This program requires an ini file to use...    ", 5)
            Return ; or Exit ; 
        EndIf
    EndIf
    $Width = $IconSize * Ceiling(Sqrt($sections[0]+$W))
    Dim $aRet[1]
    For $i = 1 To $sections[0]
        If $sections[$i] <> "Settings" Then _ArrayAdd($aRet, IniRead($IniPath, $sections[$i], "filename", ""))
    Next
    Return $aRet
EndFunc   ;==>_GetAllInfo

ADDED

Else

MsgBox(4096, "Error", "This program requires an ini file to use... ", 5)

Return ; or Exit ;

EndIf

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Just a little more error checking...

Func _GetAllInfo()
    $sections = IniReadSectionNames($IniPath)
    $W=0
    If Not IsArray($sections) Then
        $Open = FileOpenDialog("Chose File", @DesktopDir, "all files (*.*)")
        If Not @error Then
            If StringInStr($Open, "]") Or StringInStr($Open, "[") Then
                MsgBox(0,"Error!", "Please remove any ''['' or '']'' chars from the file's name you want to add")
                Return
            Else
                IniWrite($IniPath, $Open, "filename", $Open)
                $sections = IniReadSectionNames($IniPath)
                $W=1
            EndIf
        Else    
            MsgBox(4096, "Error", "This program requires an ini file to use...    ", 5)
            Return ; or Exit ; 
        EndIf
    EndIf
    $Width = $IconSize * Ceiling(Sqrt($sections[0]+$W))
    Dim $aRet[1]
    For $i = 1 To $sections[0]
        If $sections[$i] <> "Settings" Then _ArrayAdd($aRet, IniRead($IniPath, $sections[$i], "filename", ""))
    Next
    Return $aRet
EndFunc   ;==>_GetAllInfo

ADDED

Else

MsgBox(4096, "Error", "This program requires an ini file to use... ", 5)

Return ; or Exit ;

EndIf

8)

Yeah good on you :D

Anyway... what's the impression you had about the program... except it was Buggy :D

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

The concept is great and if i could fix the bugs, i'm thinking i could maybe use it daily. Love it, except it keeps opening pictures in picasa over and over again and sometimes there are some problems with windows overlays.

Fine tune it and i'll sure give you 5 stars for it and a big thank you. :D

Link to comment
Share on other sites

No that's not my program!

it desn't prompt anything at any time! XD

Probably it's because you are pressing Del and Hotkeys aren't in the script (yet ;) ). It' the only explanaition I can think of.

I don't know why but here everything seems working fine.

It takes my zip files, it doesn't open 2 or more windows whatsoever and nothing else

The only problem I had was the overlaying windows sometimes, but nothing really annoying. And it happened sopradically.

And... what's the problem with Picasa ?! I can't think of how it can pissibly do that XD

btw... I intend an Icon+Label for "Icon". Basically it's the same thing you get in your desktop under a graphical (not a control one) point of view :P

anyway, if anyone finds a big and a fix to it and wants to post it he is welcome :D

Edit: for "an Icon on your desktop" I mean something looking like an icon, but we all know it's actually a window :D

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

yeah... excuse me for my bad english and my bad expressions

what I ment was: The thing that prompts you to remove the file isn't my program. It's something else. If you go and take a look at the code you won't find any msgbox or whatsoever prompting the user :D

anyway... let's say it's kind of working. And, I repeat, it works perfectly for me :D

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

that prompt closes both with and without the fix you proposed in post #6

it only occours when you are in delete mode and you only have one item in the box. If you click it (in order todelete it) it will stop you because otherwise the script will crash

and it only opens one window. This is all in a non-compiled script.

I'm running XP SP3, latest AutoIt release.

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Very interesting......

I am going to try to mod it so it uses an icon instead of a box, and to add snap. This would make it blend into the desktop better

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...