Jump to content

GDI+ as sliding toolbar


sandin
 Share

Recommended Posts

Even though regular toolbar is more useful and easier to use, this is something made just for appearance.

When you move your mouse on the edge of the window, or 100px left or right from the window (while window is active) toolbar will slide, and allow you to have more toolbar icons in less space.

Posted Image

There are two known bugs:

- After restoring window from minimized state, GDI+ disappear, though this can be fixed through WM_PAINT

- For some strange reason, when you move your mouse to the right (then slider is going to the left), and after a while when you move your mouse left (then slider is going to the right) but only a little bit, so the slider is moving slowly, then I have some image displacement and flickering (but only for the first few icons), it might have something to do with the math of image movement, but it's working fine on the other side (and the math is similar)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Include <Misc.au3>
#Include <GuiEdit.au3>

_GDIPlus_Startup()

Opt("OnExitFunc", "endscript") ;func @ exiting script

dim $icons[10] ;number of icons used
dim $icon_info[10][6] ;number of icons used and their information
global $shell32 = @SystemDir & "\shell32.dll" ;shell32.dll location, the file for icon extraction
Global $cur_first = 0, $cur_last = 9, $moving = False, $timer_10, $hGraphic, $timer_end_txt, $inside = False ;some global variables

$timer_10 = TimerInit() ;this timer is limiting sliding to max speed of 10ms/px
$timer_end_txt = TimerInit() ;this timer is used for toolbar label to vanish (check While 1 section)

_set_icon_info() ;setting icons info, check the function for detail info

$Form1 = GUICreate("pr0 toolbar #1", 253, 300) ;gui creation
GUISetBkColor(0) ;gui black background color
GUICtrlCreateGroup("", 12, 76, 229, 212) ;group around edit
$Edit1 = GUICtrlCreateEdit("Click any icon in the toolbar...", 15, 85, 223, 200, $WS_VSCROLL+0x0040+0x0004+0x1000) ;edit control to display icons clicking
GUICtrlSetBkColor(-1, 0x333333) ;gray background of edit ctrl
GUICtrlSetColor(-1, 0xFFFFFF) ;white letters inside of edit ctrl
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
$toolbar_display_txt = GUICtrlCreateLabel("", 10, 49+7, 233, 17, 0x01) ;label to display curent selected toolbar icon with "CENTER" style = 0x01
GUICtrlSetColor(-1, 0xFFFFFF) ;above label color is white
GUICtrlSetFont(-1, 12, 800, 2, "Arial") ;above label's font = arial, 800=bold
WinSetTrans($form1, "", 255) ;setting transp to 255 (max) will make GDI always visible (without disappearing when moved on the edge of the desktop, or when overlaped by another window
                                ;note - must be before declaring graphic GDI in order for this to work
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1) ;creating graphic for drawing toolbar icons
_extract_icons() ;extracting icons from shell32.dll, check func for detail info

GUISetState(@SW_SHOW, $form1) ;display main GUI

$stemp = GUICreate("", 30, 14, 185, 293, BitOR($WS_POPUP, $WS_CHILD), $WS_EX_MDICHILD, $Form1) ;just another trick-window to make CLEAR label inside of main window's EDIT, pretty neat ;)
WinSetTrans($stemp, "", 255) ;setting trans to 255 to clear bugs when moving main window
GUISetBkColor(0x333333) ;background color is the same as EDIT in main window
$clear_label = GUICtrlCreateLabel("clear", 0, 0, 30, 14, 0x01) ;clear label with "CENTER" style = 0x01
GUICtrlSetCursor(-1, 0) ;"finger" cursor on this label above
GUICtrlSetColor(-1, 0xFF0000) ;red color label
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUISetState(@SW_SHOW, $stemp) ;display clear label inside of edit control

for $i = 0 to 4
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32) ;drawing first 4 icons into GDI (window)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $clear_label ;edit label in the "trick" child-window inside of EDIT control
            GUICtrlSetData($Edit1, "")
    EndSwitch
    
    Local $c = GUIGetCursorInfo($Form1) ;get mouse location inside of GUI
        Local $x_coord = $c[0] ;mouse x coordinate inside of GUI
        Local $y_coord = $c[1] ;mouse y coordinate isnide of GUI
        if $y_coord < 52 AND $y_coord > 0 AND WinActive($Form1) Then ;top and bottom coordinate of toolbar
            if TimerDiff($timer_10) >= 10 then ;sliding is chaotic if there is no speed limitation, 10ms in this case is just enough
                $timer_10 = TimerInit()
                Switch $x_coord
                    case -100 to 41 ;left corner - moving icons to the right
                        $inside = true ;is mouse inside of sliding area? yes!
                        _shrink_all() ;if there is any icon that is enlarged, it'll be decreased
                        $moving = true ;is slider mooving? yes!
                        Local $speed
                        Local $x_coord1 = $x_coord
                        if $x_coord1 < 0 then
                            $x_coord1 = 0 ;if this isn't limited to 0 then the speed would continue to increase if the mouse is outside (but near) window
                        EndIf
                        $speed = int(((41-$x_coord1)/15)^2) ;acceleration and speed of sliding icons is increased parabolical, and not linear, that's why ^2
                        if $speed < 1 then $speed = 1 ;min speed should be 1px
                        for $i = 0 to 9
                            $icon_info[$i][3] += $speed ;changing x starting coordinate for each icon
                            $icon_info[$i][4] += $speed ;changing x starting coordinate for each icon
                            
                            if Int($icon_info[$cur_first][3]) >= 25 Then ;this is where last icon become first
                                Local $previous = $cur_first
                                $cur_first -= 1
                                if $cur_first < 0 then $cur_first = 9
                                $icon_info[$cur_first][3] = int($icon_info[$previous][3]) - 57
                                $icon_info[$cur_first][4] = int($icon_info[$previous][4]) - 57
                            EndIf
                            
                            if $icon_info[$i][3] < 253+25 then ;icons that aren't visible shouldn't move at all (and thus save pc resources)
                                Local $width_x = 10
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][4], 15, $width_x, 32);Right side filling black line
                                _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32);icon image
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][3]-$width_x, 15, $width_x, 32);Left side filling black line
                            EndIf
                        Next
                    case 212 to 253+100 ;right corner - moving to the left
                        $inside = true
                        _shrink_all()
                        $moving = true
                        Local $speed
                        Local $x_coord1 = $x_coord
                        if $x_coord1 > 253 then
                            $x_coord1 = 253
                        EndIf
                        $speed = Int((($x_coord1-212)/15)^2)
                        if $speed < 1 then $speed = 1
                        for $i = 0 to 9
                            $icon_info[$i][3] -= $speed
                            $icon_info[$i][4] -= $speed
                            
                            if int($icon_info[$cur_last][3]) <= 228 Then ;this is where first icon become last
                                Local $previous = $cur_last
                                $cur_last += 1
                                if $cur_last > 9 then $cur_last = 0
                                $icon_info[$cur_last][3] = int($icon_info[$previous][3]) + 57
                                $icon_info[$cur_last][4] = int($icon_info[$previous][4]) + 57

                            EndIf
                            
                            if $icon_info[$i][4]+25 > 0 then
                                Local $width_x = 10
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][3]-$width_x, 15, $width_x, 32);Left side filling black line
                                _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32)
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][4], 15, $width_x, 32);Right side filling black line
                            EndIf
                        Next
                    case Else
                        $moving = False
                        if $inside = True Then
                            $inside = False
                            Local $founded = 10
                            for $i = 0 to 9
                                if $icon_info[$i][2] = True Then
                                    $founded = $i
                                    ExitLoop
                                EndIf
                            Next
                            if $founded <> 10 then
                                if $icon_info[$founded][5] = false Then
                                    _easy_rise($icons[$founded], $icon_info[$founded][3]-2, 12, 37, 37)
                                    $icon_info[$founded][5] = true
                                EndIf
                            EndIf
                        EndIf
                EndSwitch
            EndIf
                switch $x_coord
                    case $icon_info[0][3]-5 to $icon_info[0][4]+5 ;1st icon, mouse is hovering above 1st icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(0)
                    case $icon_info[1][3]-5 to $icon_info[1][4]+5 ;2nd icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(1)
                    case $icon_info[2][3]-5 to $icon_info[2][4]+5 ;3rd icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(2)
                    case $icon_info[3][3]-5 to $icon_info[3][4]+5 ;4th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(3)
                    case $icon_info[4][3]-5 to $icon_info[4][4]+5 ;5th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(4)
                    case $icon_info[5][3]-5 to $icon_info[5][4]+5 ;6th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(5)
                    case $icon_info[6][3]-5 to $icon_info[6][4]+5 ;7th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(6)
                    case $icon_info[7][3]-5 to $icon_info[7][4]+5 ;8th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(7)
                    case $icon_info[8][3]-5 to $icon_info[8][4]+5 ;9th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(8)
                    case $icon_info[9][3]-5 to $icon_info[9][4]+5 ;10th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(9)
                    case Else
                        _shrink_all()
                EndSwitch
        Else
            _shrink_all()
        EndIf
    if Round(TimerDiff($timer_end_txt)) >= 500 then GUICtrlSetData($toolbar_display_txt, "") ;if mouse wasn't hovering above any icon for 0.5sec, display txt should vanish
    if WinActive($stemp) then WinActivate($form1) ;if the child window with label "clear" inside of EDIT ctrl is active, then main window should activate and set as current
WEnd
    
func _for_icon($number)
    $timer_end_txt = TimerInit() ;timer for vanishing txt label that display txt of curent icon
    if $icon_info[$number][2] = False then ;prevent constant shrinking and enlarging
        GUICtrlSetData($toolbar_display_txt, $icon_info[$number][1]) ;set label txt to curent icon info
        if $moving = False then ;if the slider isn't moving then it's OK to resize icons
            _shrink_all() 
            _easy_rise($icons[$number], $icon_info[$number][3]-2, 12, 37, 37) ;should enlarge selected icon
            $icon_info[$number][5] = true ;setting the curent icon as enlarged
        EndIf
        $icon_info[$number][2] = True ;setting the curent icon as selected
    EndIf
    If _IsPressed(01) then ;if mouse click is down on the selected icon
        if $icon_info[$number][5] = false Then
            _easy_rise($icons[$number], $icon_info[$number][3]-2, 12, 37, 37)
            $icon_info[$number][5] = true
        EndIf
        Do
        Until NOT _IsPressed(01) ;waiting for mouse key to release (like on regular buttons)
        Local $c = GUIGetCursorInfo($Form1)
        Local $x_coord = $c[0]
        Local $y_coord = $c[1]
        if $x_coord > $icon_info[$number][3]-5 AND $x_coord < $icon_info[$number][4]+5 AND $y_coord < 42 AND $y_coord > 0 AND WinActive($Form1) Then ;if the mouse click is released while cursor was still on that icon and while GUI is active...
        Switch $number
            case 0
                ;func for icon 1
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "1st Icon Clicked - " & $icon_info[0][1]) ;edit this, and set any function you want to be called when you hit 1st icon
            case 1
                ;func for icon 2
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "2nd Icon Clicked - " & $icon_info[1][1])
            case 2
                ;func for icon 3
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "3rd Icon Clicked - " & $icon_info[2][1])
            case 3
                ;func for icon 4
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "4th Icon Clicked - " & $icon_info[3][1])
            case 4
                ;func for icon 5
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "5th Icon Clicked - " & $icon_info[4][1])
            case 5
                ;func for icon 6
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "6th Icon Clicked - " & $icon_info[5][1])
            case 6
                ;func for icon 7
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "7th Icon Clicked - " & $icon_info[6][1])
            case 7
                ;func for icon 8
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "8th Icon Clicked - " & $icon_info[7][1])
            case 8
                ;func for icon 9
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "9th Icon Clicked - " & $icon_info[8][1])
            case 9
                ;func for icon 10
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "10th Icon Clicked - " & $icon_info[9][1])
        EndSwitch
        EndIf
    EndIf
EndFunc

func _shrink_all()
    for $i = 0 to 9
        if $icon_info[$i][2] = True Then ;if icon is selected
            if $icon_info[$i][5] = True then ;if icon is enlarged
                _easy_shrink($icons[$i], $icon_info[$i][3], 15, 32, 32)
                $icon_info[$i][5] = False
            EndIf
            $icon_info[$i][2] = false
        EndIf
    Next
EndFunc

func _easy_rise($immmmage, $iX, $iY, $iW, $iH, $maxxx=6, $step = 1) ;image to be resized, x-coord of the image, y-coord of the image, width of the image, height of the image, max enlargement, speed of enlargement
    for $i = 1 to $maxxx Step $step
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX-$i, $iY-$i, $iW+2*$i, $iH+2*$i) ;enlarging icon
        Sleep(1) ;making it smooth
    Next    
EndFunc

func _easy_shrink($immmmage, $iX, $iY, $iW, $iH, $maxxx=6, $step = 1)
    Local $cntr = 0
    for $i = $maxxx to 1 Step -$step
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX-$i, $iY-$i, $iW+2*$i, $iH+2*$i) ;shrinking icon
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i-$step, $step+3, $iH+2*$i+2*$step);black goes Left
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i+$iW+2*$i-$step+1, $iY-$i-$step, $step+3, $iH+2*$i+2*$step);black goes Right
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i-$step-3, $iW+2*$i+($step+3)*2, $step+3);black goes Above
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i+$iH+2*$i, $iW+2*$i+($step+3)*2, $step+3);black goes Bellow
        $cntr = $i
        Sleep(1)
    Next
    if $iW+2*$cntr <> $iW OR $iH+2*$cntr <> $iH then ;if shrinking didn't went to the exact size it was supposed to, this will make it regular size again
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX, $iY, $iW, $iH) ;drawing icon @ it's original size
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY, $step+3, $iH);Left
        _GDIPlus_GraphicsFillRect($hGraphic, $iX+$iW, $iY, $step+3, $iH);Right
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY-$step-3, $iW+2*($step+3), $step+3);Above
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY+$iH, $iW+2*($step+3), $step+3);Bellow
    EndIf
EndFunc

func _extract_icons()
    for $i = 0 to 9
        Local $Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$shell32,"int*",(-1*$icon_info[$i][0])-1) ;extract icon from file
        Local $hIcon = $Ret[0] ;icon's handle
        Local $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0) ;create bitmap from icon's handle
        _GDIPlus_ImageSaveToFile($pBitmap[2],@ScriptDir & "\test_image" & $i & ".bmp") ;why am I saving it instead of using it's handle? Using it's handle will make parts around icon transparent,
        _GDIPlus_ImageDispose($pBitmap[2]) ;                                             thus ruining resize/select mode, but saving it as image will fill up the transparent parts with black color
        $icons[$i] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\test_image" & $i & ".bmp") ;and now loading this file
        _WinAPI_DestroyIcon($Ret[0]) ;and clearing resources by destroying icon's handle we don't need anymore...
    Next
EndFunc

func _set_icon_info()
    ;icon value:
    $icon_info[0][0] = "-13"; = memory
    $icon_info[1][0] = "-204"; = Camera
    $icon_info[2][0] = "-197"; = Phone
    $icon_info[3][0] = "-131"; = MS Live
    $icon_info[4][0] = "-166"; = Gear
    $icon_info[5][0] = "-172"; = Search
    $icon_info[6][0] = "-169"; = Sound
    $icon_info[7][0] = "-171";= MSN
    $icon_info[8][0] = "-200"; = HDD
    $icon_info[9][0] = "-201"; = PDA
    
    ;icon name:
    $icon_info[0][1] = "Memory"; = memory
    $icon_info[1][1] = "Camera"; = Camera
    $icon_info[2][1] = "Phone"; = Phone
    $icon_info[3][1] = "MS Live"; = MS Live
    $icon_info[4][1] = "Gear"; = Gear
    $icon_info[5][1] = "Search"; = Search
    $icon_info[6][1] = "Sound"; = Sound
    $icon_info[7][1] = "MSN";= MSN
    $icon_info[8][1] = "HDD"; = HDD
    $icon_info[9][1] = "PDA"; = PDA
    
    ;icon hover:
    $icon_info[0][2] = False; = memory
    $icon_info[1][2] = False; = Camera
    $icon_info[2][2] = False; = Phone
    $icon_info[3][2] = False; = MS Live
    $icon_info[4][2] = False; = Gear
    $icon_info[5][2] = False; = Search
    $icon_info[6][2] = False; = Sound
    $icon_info[7][2] = False;= MSN
    $icon_info[8][2] = False; = HDD
    $icon_info[9][2] = False; = PDA
    
    ;icon enlarged:
    $icon_info[0][5] = False; = memory
    $icon_info[1][5] = False; = Camera
    $icon_info[2][5] = False; = Phone
    $icon_info[3][5] = False; = MS Live
    $icon_info[4][5] = False; = Gear
    $icon_info[5][5] = False; = Search
    $icon_info[6][5] = False; = Sound
    $icon_info[7][5] = False;= MSN
    $icon_info[8][5] = False; = HDD
    $icon_info[9][5] = False; = PDA
    
    ;icon start/end coordinate x:
    Local $x_x = 0
    for $i = 0 to 9
        $x_x += 25
        $icon_info[$i][3] = $x_x ; = start X coordinate
        $x_x += 32
        $icon_info[$i][4] = $x_x ; = end X coordinate
    Next
EndFunc

func endscript() ;clearing resources @ the and of the script
    _GDIPlus_GraphicsDispose($hGraphic)
    for $i = 0 to 9
        _GDIPlus_ImageDispose($icons[$i])
        FileDelete(@ScriptDir & "\test_image" & $i & ".bmp")
    Next
    _GDIPlus_Shutdown()
EndFunc
Link to comment
Share on other sites

Nice.

I've already played with gdi+ and same issue with repaint.

Solution : register wm_activate so when restore, (lParam set to 1), you repaint.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

  • 2 weeks later...

Hi, neato and nice work :D

Thanks for sharing your fine efforts.

I made some mild mods to your code to do away with the creating bmp files and deleting them.

Also extracted the icons at a slighty higher res, this way the look a little sharper when moused over (providing the icon has a larger size, if not then it won't make things worse.)

You can notice the difference in MSN, Camera, PDA icons when they're moused over.

Swapped the 2 ~ 4 fill rectangles you were using as a black boarder on resizing/moving for a 10p rectangle.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <GuiEdit.au3>

_GDIPlus_Startup()

Opt("OnExitFunc", "endscript") ;func @ exiting script

Dim $icons[10] ;number of icons used
Dim $icon_info[10][6] ;number of icons used and their information
Global $shell32 = @SystemDir & "\shell32.dll" ;shell32.dll location, the file for icon extraction
Global $cur_first = 0, $cur_last = 9, $moving = False, $timer_10, $hGraphic, $timer_end_txt, $inside = False ;some global variables
Global $hPen = _GDIPlus_PenCreate(0xFF000000, 10) ;Used as a 10p black boarder around each icon when sizing or moving.

$timer_10 = TimerInit() ;this timer is limiting sliding to max speed of 10ms/px
$timer_end_txt = TimerInit() ;this timer is used for toolbar label to vanish (check While 1 section)

_set_icon_info() ;setting icons info, check the function for detail info

$Form1 = GUICreate("pr0 toolbar #1", 253, 300) ;gui creation
GUISetBkColor(0) ;gui black background color
$hLabel = GUICtrlGetHandle(GUICtrlCreateLabel("", 0, 0, 253, 56)) ;used this to draw the icons on, saves resizing the pen width when drawing the boarder, otherwise the boarder goes over the $toolbar_display_txt
GUICtrlCreateGroup("", 12, 76, 229, 212) ;group around edit
$Edit1 = GUICtrlCreateEdit("Click any icon in the toolbar...", 15, 85, 223, 200, $WS_VSCROLL + 0x0040 + 0x0004 + 0x1000) ;edit control to display icons clicking
GUICtrlSetBkColor(-1, 0x333333) ;gray background of edit ctrl
GUICtrlSetColor(-1, 0xFFFFFF) ;white letters inside of edit ctrl
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$toolbar_display_txt = GUICtrlCreateLabel("", 10, 49 + 7, 233, 17, 0x01) ;label to display curent selected toolbar icon with "CENTER" style = 0x01
GUICtrlSetColor(-1, 0xFFFFFF) ;above label color is white
GUICtrlSetFont(-1, 12, 800, 2, "Arial") ;above label's font = arial, 800=bold
WinSetTrans($Form1, "", 255) ;setting transp to 255 (max) will make GDI always visible (without disappearing when moved on the edge of the desktop, or when overlaped by another window
;note - must be before declaring graphic GDI in order for this to work
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hLabel) ;creating graphic for drawing toolbar icons
_extract_icons() ;extracting icons from shell32.dll, check func for detail info

GUISetState(@SW_SHOW, $Form1) ;display main GUI

$stemp = GUICreate("", 30, 14, 185, 293, BitOR($WS_POPUP, $WS_CHILD), $WS_EX_MDICHILD, $Form1) ;just another trick-window to make CLEAR label inside of main window's EDIT, pretty neat ;)
WinSetTrans($stemp, "", 255) ;setting trans to 255 to clear bugs when moving main window
GUISetBkColor(0x333333) ;background color is the same as EDIT in main window
$clear_label = GUICtrlCreateLabel("clear", 0, 0, 30, 14, 0x01) ;clear label with "CENTER" style = 0x01
GUICtrlSetCursor(-1, 0) ;"finger" cursor on this label above
GUICtrlSetColor(-1, 0xFF0000) ;red color label
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUISetState(@SW_SHOW, $stemp) ;display clear label inside of edit control

For $i = 0 To 4
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32) ;drawing first 4 icons into GDI (window)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $clear_label ;edit label in the "trick" child-window inside of EDIT control
            GUICtrlSetData($Edit1, "")
    EndSwitch

    Local $c = GUIGetCursorInfo($Form1) ;get mouse location inside of GUI
    Local $x_coord = $c[0] ;mouse x coordinate inside of GUI
    Local $y_coord = $c[1] ;mouse y coordinate isnide of GUI
    If $y_coord < 52 And $y_coord > 0 And WinActive($Form1) Then ;top and bottom coordinate of toolbar
        If TimerDiff($timer_10) >= 10 Then ;sliding is chaotic if there is no speed limitation, 10ms in this case is just enough
            $timer_10 = TimerInit()
            Switch $x_coord
                Case - 100 To 41 ;left corner - moving icons to the right
                    $inside = True ;is mouse inside of sliding area? yes!
                    _shrink_all() ;if there is any icon that is enlarged, it'll be decreased
                    $moving = True ;is slider mooving? yes!
                    Local $speed
                    Local $x_coord1 = $x_coord
                    If $x_coord1 < 0 Then
                        $x_coord1 = 0 ;if this isn't limited to 0 then the speed would continue to increase if the mouse is outside (but near) window
                    EndIf
                    $speed = Int(((41 - $x_coord1) / 15) ^ 2) ;acceleration and speed of sliding icons is increased parabolical, and not linear, that's why ^2
                    If $speed < 1 Then $speed = 1 ;min speed should be 1px
                    For $i = 0 To 9
                        $icon_info[$i][3] += $speed ;changing x starting coordinate for each icon
                        $icon_info[$i][4] += $speed ;changing x starting coordinate for each icon

                        If Int($icon_info[$cur_first][3]) >= 25 Then ;this is where last icon become first
                            Local $previous = $cur_first
                            $cur_first -= 1
                            If $cur_first < 0 Then $cur_first = 9
                            $icon_info[$cur_first][3] = Int($icon_info[$previous][3]) - 57
                            $icon_info[$cur_first][4] = Int($icon_info[$previous][4]) - 57
                        EndIf

                        If $icon_info[$i][3] < 253 + 25 Then ;icons that aren't visible shouldn't move at all (and thus save pc resources)
                            Local $width_x = 10
                            _GDIPlus_GraphicsDrawRect($hGraphic, $icon_info[$i][3] - 5, 15 - 5, 32 + 10, 32 + 10, $hPen) ;boarder bigger then icon
                            _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32);icon image
                        EndIf
                    Next
                Case 212 To 253 + 100 ;right corner - moving to the left
                    $inside = True
                    _shrink_all()
                    $moving = True
                    Local $speed
                    Local $x_coord1 = $x_coord
                    If $x_coord1 > 253 Then
                        $x_coord1 = 253
                    EndIf
                    $speed = Int((($x_coord1 - 212) / 15) ^ 2)
                    If $speed < 1 Then $speed = 1
                    For $i = 0 To 9
                        $icon_info[$i][3] -= $speed
                        $icon_info[$i][4] -= $speed

                        If Int($icon_info[$cur_last][3]) <= 228 Then ;this is where first icon become last
                            Local $previous = $cur_last
                            $cur_last += 1
                            If $cur_last > 9 Then $cur_last = 0
                            $icon_info[$cur_last][3] = Int($icon_info[$previous][3]) + 57
                            $icon_info[$cur_last][4] = Int($icon_info[$previous][4]) + 57

                        EndIf

                        If $icon_info[$i][4] + 25 > 0 Then
                            Local $width_x = 10
                            _GDIPlus_GraphicsDrawRect($hGraphic, $icon_info[$i][3] - 5, 15 - 5, 32 + 10, 32 + 10, $hPen) ;boarder bigger then icon
                            _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32) ;icon image
                        EndIf
                    Next
                Case Else
                    $moving = False
                    If $inside = True Then
                        $inside = False
                        Local $founded = 10
                        For $i = 0 To 9
                            If $icon_info[$i][2] = True Then
                                $founded = $i
                                ExitLoop
                            EndIf
                        Next
                        If $founded <> 10 Then
                            If $icon_info[$founded][5] = False Then
                                _easy_rise($icons[$founded], $icon_info[$founded][3] - 2, 12, 37, 37)
                                $icon_info[$founded][5] = True
                            EndIf
                        EndIf
                    EndIf
            EndSwitch
        EndIf
        Switch $x_coord
            Case $icon_info[0][3] - 5 To $icon_info[0][4] + 5 ;1st icon, mouse is hovering above 1st icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(0)
            Case $icon_info[1][3] - 5 To $icon_info[1][4] + 5 ;2nd icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(1)
            Case $icon_info[2][3] - 5 To $icon_info[2][4] + 5 ;3rd icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(2)
            Case $icon_info[3][3] - 5 To $icon_info[3][4] + 5 ;4th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(3)
            Case $icon_info[4][3] - 5 To $icon_info[4][4] + 5 ;5th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(4)
            Case $icon_info[5][3] - 5 To $icon_info[5][4] + 5 ;6th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(5)
            Case $icon_info[6][3] - 5 To $icon_info[6][4] + 5 ;7th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(6)
            Case $icon_info[7][3] - 5 To $icon_info[7][4] + 5 ;8th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(7)
            Case $icon_info[8][3] - 5 To $icon_info[8][4] + 5 ;9th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(8)
            Case $icon_info[9][3] - 5 To $icon_info[9][4] + 5 ;10th icon
                If $x_coord >= 0 And $x_coord <= 253 Then _for_icon(9)
            Case Else
                _shrink_all()
        EndSwitch
    Else
        _shrink_all()
    EndIf
    If Round(TimerDiff($timer_end_txt)) >= 500 Then GUICtrlSetData($toolbar_display_txt, "") ;if mouse wasn't hovering above any icon for 0.5sec, display txt should vanish
    If WinActive($stemp) Then WinActivate($Form1) ;if the child window with label "clear" inside of EDIT ctrl is active, then main window should activate and set as current
WEnd

Func _for_icon($number)
    $timer_end_txt = TimerInit() ;timer for vanishing txt label that display txt of curent icon
    If $icon_info[$number][2] = False Then ;prevent constant shrinking and enlarging
        GUICtrlSetData($toolbar_display_txt, $icon_info[$number][1]) ;set label txt to curent icon info
        If $moving = False Then ;if the slider isn't moving then it's OK to resize icons
            _shrink_all()
            _easy_rise($icons[$number], $icon_info[$number][3] - 2, 12, 37, 37) ;should enlarge selected icon
            $icon_info[$number][5] = True ;setting the curent icon as enlarged
        EndIf
        $icon_info[$number][2] = True ;setting the curent icon as selected
    EndIf
    If _IsPressed(01) Then ;if mouse click is down on the selected icon
        If $icon_info[$number][5] = False Then
            _easy_rise($icons[$number], $icon_info[$number][3] - 2, 12, 37, 37)
            $icon_info[$number][5] = True
        EndIf
        Do
        Until Not _IsPressed(01) ;waiting for mouse key to release (like on regular buttons)
        Local $c = GUIGetCursorInfo($Form1)
        Local $x_coord = $c[0]
        Local $y_coord = $c[1]
        If $x_coord > $icon_info[$number][3] - 5 And $x_coord < $icon_info[$number][4] + 5 And $y_coord < 42 And $y_coord > 0 And WinActive($Form1) Then ;if the mouse click is released while cursor was still on that icon and while GUI is active...
            Switch $number
                Case 0
                    ;func for icon 1
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "1st Icon Clicked - " & $icon_info[0][1]) ;edit this, and set any function you want to be called when you hit 1st icon
                Case 1
                    ;func for icon 2
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "2nd Icon Clicked - " & $icon_info[1][1])
                Case 2
                    ;func for icon 3
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "3rd Icon Clicked - " & $icon_info[2][1])
                Case 3
                    ;func for icon 4
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "4th Icon Clicked - " & $icon_info[3][1])
                Case 4
                    ;func for icon 5
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "5th Icon Clicked - " & $icon_info[4][1])
                Case 5
                    ;func for icon 6
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "6th Icon Clicked - " & $icon_info[5][1])
                Case 6
                    ;func for icon 7
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "7th Icon Clicked - " & $icon_info[6][1])
                Case 7
                    ;func for icon 8
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "8th Icon Clicked - " & $icon_info[7][1])
                Case 8
                    ;func for icon 9
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "9th Icon Clicked - " & $icon_info[8][1])
                Case 9
                    ;func for icon 10
                    _GUICtrlEdit_AppendText($Edit1, @CRLF & "10th Icon Clicked - " & $icon_info[9][1])
            EndSwitch
        EndIf
    EndIf
EndFunc   ;==>_for_icon

Func _shrink_all()
    For $i = 0 To 9
        If $icon_info[$i][2] = True Then ;if icon is selected
            If $icon_info[$i][5] = True Then ;if icon is enlarged
                _easy_shrink($icons[$i], $icon_info[$i][3], 15, 32, 32)
                $icon_info[$i][5] = False
            EndIf
            $icon_info[$i][2] = False
        EndIf
    Next
EndFunc   ;==>_shrink_all

Func _easy_rise($immmmage, $iX, $iY, $iW, $iH, $maxxx = 6, $step = 1) ;image to be resized, x-coord of the image, y-coord of the image, width of the image, height of the image, max enlargement, speed of enlargement
    For $i = 1 To $maxxx Step $step
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX - $i, $iY - $i, $iW + 2 * $i, $iH + 2 * $i) ;enlarging icon
        Sleep(1) ;making it smooth
    Next
EndFunc   ;==>_easy_rise

Func _easy_shrink($immmmage, $iX, $iY, $iW, $iH, $maxxx = 6, $step = 1)
    Local $cntr = 0
    For $i = $maxxx To 1 Step -$step
        _GDIPlus_GraphicsDrawRect($hGraphic, $iX - $i - 5, $iY - $i - 5, $iW + 2 * $i + 10, $iH + 2 * $i + 10, $hPen)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX - $i, $iY - $i, $iW + 2 * $i, $iH + 2 * $i) ;shrinking icon

        $cntr = $i
        Sleep(1)
    Next
    If $iW + 2 * $cntr <> $iW Or $iH + 2 * $cntr <> $iH Then ;if shrinking didn't went to the exact size it was supposed to, this will make it regular size again
        _GDIPlus_GraphicsDrawRect($hGraphic, $iX - 5, $iY - 5, $iW + 10, $iH + 10, $hPen)
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX, $iY, $iW, $iH) ;drawing icon @ it's original size

    EndIf
EndFunc   ;==>_easy_shrink

Func _extract_icons()
    Local $hIcon, $hBitmap1, $hBitmap2, $hGraphic, $hBmp1
    $hBmp1 = _WinAPI_CreateBitmap(48, 48, 1, 32) ;create a blank bitmap
    For $i = 0 To 9
        $hIcon = _WinAPI_PrivateExtractIcon($shell32, (-1 * $icon_info[$i][0]) - 1, 48, 48) ;extract the icon I used 48x48, this way the icon looks a touch clearer when moused over
        $hBitmap1 = _GDIPlus_BitmapCreateFromHICON($hIcon) ;create bitmap from icon's handle
        _WinAPI_DestroyIcon($hIcon) ;destroy the icon
        $hBitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1) ;create a compatible GDI+ bitmap from the blank bitmap
        $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap2) ;Get context of compatible GDI+ bitmap
        _GDIPlus_GraphicsClear($hGraphic, 0xFF000000);set the back color to black
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap1, 0, 0, 48, 48);draw the bitmap icon on the compatible black GDI+ bitmap
        _GDIPlus_GraphicsDispose($hGraphic) ;dispose of the context.
        _GDIPlus_BitmapDispose($hBitmap1) ;dispose of the icon bitmap
        $icons[$i] = $hBitmap2 ;use the new black background icon bitmap
    Next
    _WinAPI_DeleteObject($hBmp1) ;delete the blank bitmap
EndFunc   ;==>_extract_icons

Func _set_icon_info()
    ;icon value:
    $icon_info[0][0] = "-13"; = memory
    $icon_info[1][0] = "-204"; = Camera
    $icon_info[2][0] = "-197"; = Phone
    $icon_info[3][0] = "-131"; = MS Live
    $icon_info[4][0] = "-166"; = Gear
    $icon_info[5][0] = "-172"; = Search
    $icon_info[6][0] = "-169"; = Sound
    $icon_info[7][0] = "-171";= MSN
    $icon_info[8][0] = "-200"; = HDD
    $icon_info[9][0] = "-201"; = PDA

    ;icon name:
    $icon_info[0][1] = "Memory"; = memory
    $icon_info[1][1] = "Camera"; = Camera
    $icon_info[2][1] = "Phone"; = Phone
    $icon_info[3][1] = "MS Live"; = MS Live
    $icon_info[4][1] = "Gear"; = Gear
    $icon_info[5][1] = "Search"; = Search
    $icon_info[6][1] = "Sound"; = Sound
    $icon_info[7][1] = "MSN";= MSN
    $icon_info[8][1] = "HDD"; = HDD
    $icon_info[9][1] = "PDA"; = PDA

    ;icon hover:
    $icon_info[0][2] = False; = memory
    $icon_info[1][2] = False; = Camera
    $icon_info[2][2] = False; = Phone
    $icon_info[3][2] = False; = MS Live
    $icon_info[4][2] = False; = Gear
    $icon_info[5][2] = False; = Search
    $icon_info[6][2] = False; = Sound
    $icon_info[7][2] = False;= MSN
    $icon_info[8][2] = False; = HDD
    $icon_info[9][2] = False; = PDA

    ;icon enlarged:
    $icon_info[0][5] = False; = memory
    $icon_info[1][5] = False; = Camera
    $icon_info[2][5] = False; = Phone
    $icon_info[3][5] = False; = MS Live
    $icon_info[4][5] = False; = Gear
    $icon_info[5][5] = False; = Search
    $icon_info[6][5] = False; = Sound
    $icon_info[7][5] = False;= MSN
    $icon_info[8][5] = False; = HDD
    $icon_info[9][5] = False; = PDA

    ;icon start/end coordinate x:
    Local $x_x = 0
    For $i = 0 To 9
        $x_x += 25
        $icon_info[$i][3] = $x_x ; = start X coordinate
        $x_x += 32
        $icon_info[$i][4] = $x_x ; = end X coordinate
    Next
EndFunc   ;==>_set_icon_info

Func endscript() ;clearing resources @ the and of the script
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    For $i = 0 To 9
        _GDIPlus_ImageDispose($icons[$i])
    Next
    _GDIPlus_Shutdown()
EndFunc   ;==>endscript

Func _GDIPlus_BitmapCreateFromHICON($hIcon)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHICON", "ptr", $hIcon, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($aResult[0], 0, $aResult[2])
EndFunc   ;==>_GDIPlus_BitmapCreateFromHICON

Func _WinAPI_PrivateExtractIcon($sFile, $iIndex = 0, $iW = 0, $iH = 0, $iFlags = 0)
    Local $aResult, $tHICON, $pHICON
    $tHICON = DllStructCreate("hwnd[1]")
    $pHICON = DllStructGetPtr($tHICON)
    $aResult = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sFile, 'int', $iIndex, 'int', $iW, 'int', $iH, 'ptr', $pHICON, 'ptr', 0, 'int', 1, 'int', $iFlags)
    If @error Then Return SetError(@error, 0, -1)
    If $aResult[0] = 0xFFFFFFFF Then Return SetError(4, 0, -1)
    Return DllStructGetData($tHICON, 1, 1)
EndFunc   ;==>_WinAPI_PrivateExtractIcon

I'm looking at drawing the icons onto a buffer then set the buffer to a pic control, this way no boarders/back mask/wm repaint will not be needed.

Cheers

Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

I have a question with setting the background color.

I have edited this script to be vertical instead of horizontal icons. I don't want a black background though. So when you hover over an icon, when it shrinks back down to a smaller icon. it's surrounded by a black box. How do i get it so that black turns to whatever color i set the background color to?

Link to comment
Share on other sites

I've found a solution to setting a different background color.

On the fill rect function calls, eg:

_GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i-$step, $step+3, $iH+2*$i+2*$step, $brush)

you need to append a $brush as one of the parameters

you can create a brush by:

$brush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

The hex value is not a normal RGB hex value. it's an ARGB (RGBA?) value. the first 2 hex values are the opacity (alpha value). So if you set the background of the gui up at the top to a red (0xFF0000) you will need to make it (0xFFFF0000) for creating the brush.

So in general a brush is created with 0xFF + (RGBHEX)

Edited by stray
Link to comment
Share on other sites

  • 1 year later...

Even though regular toolbar is more useful and easier to use, this is something made just for appearance.

When you move your mouse on the edge of the window, or 100px left or right from the window (while window is active) toolbar will slide, and allow you to have more toolbar icons in less space.

Posted Image

There are two known bugs:

- After restoring window from minimized state, GDI+ disappear, though this can be fixed through WM_PAINT

- For some strange reason, when you move your mouse to the right (then slider is going to the left), and after a while when you move your mouse left (then slider is going to the right) but only a little bit, so the slider is moving slowly, then I have some image displacement and flickering (but only for the first few icons), it might have something to do with the math of image movement, but it's working fine on the other side (and the math is similar)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Include <Misc.au3>
#Include <GuiEdit.au3>

_GDIPlus_Startup()

Opt("OnExitFunc", "endscript") ;func @ exiting script

dim $icons[10] ;number of icons used
dim $icon_info[10][6] ;number of icons used and their information
global $shell32 = @SystemDir & "shell32.dll" ;shell32.dll location, the file for icon extraction
Global $cur_first = 0, $cur_last = 9, $moving = False, $timer_10, $hGraphic, $timer_end_txt, $inside = False ;some global variables

$timer_10 = TimerInit() ;this timer is limiting sliding to max speed of 10ms/px
$timer_end_txt = TimerInit() ;this timer is used for toolbar label to vanish (check While 1 section)

_set_icon_info() ;setting icons info, check the function for detail info

$Form1 = GUICreate("pr0 toolbar #1", 253, 300) ;gui creation
GUISetBkColor(0) ;gui black background color
GUICtrlCreateGroup("", 12, 76, 229, 212) ;group around edit
$Edit1 = GUICtrlCreateEdit("Click any icon in the toolbar...", 15, 85, 223, 200, $WS_VSCROLL+0x0040+0x0004+0x1000) ;edit control to display icons clicking
GUICtrlSetBkColor(-1, 0x333333) ;gray background of edit ctrl
GUICtrlSetColor(-1, 0xFFFFFF) ;white letters inside of edit ctrl
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$toolbar_display_txt = GUICtrlCreateLabel("", 10, 49+7, 233, 17, 0x01) ;label to display curent selected toolbar icon with "CENTER" style = 0x01
GUICtrlSetColor(-1, 0xFFFFFF) ;above label color is white
GUICtrlSetFont(-1, 12, 800, 2, "Arial") ;above label's font = arial, 800=bold
WinSetTrans($form1, "", 255) ;setting transp to 255 (max) will make GDI always visible (without disappearing when moved on the edge of the desktop, or when overlaped by another window
                                ;note - must be before declaring graphic GDI in order for this to work
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1) ;creating graphic for drawing toolbar icons
_extract_icons() ;extracting icons from shell32.dll, check func for detail info

GUISetState(@SW_SHOW, $form1) ;display main GUI

$stemp = GUICreate("", 30, 14, 185, 293, BitOR($WS_POPUP, $WS_CHILD), $WS_EX_MDICHILD, $Form1) ;just another trick-window to make CLEAR label inside of main window's EDIT, pretty neat ;)
WinSetTrans($stemp, "", 255) ;setting trans to 255 to clear bugs when moving main window
GUISetBkColor(0x333333) ;background color is the same as EDIT in main window
$clear_label = GUICtrlCreateLabel("clear", 0, 0, 30, 14, 0x01) ;clear label with "CENTER" style = 0x01
GUICtrlSetCursor(-1, 0) ;"finger" cursor on this label above
GUICtrlSetColor(-1, 0xFF0000) ;red color label
GUICtrlSetFont(-1, 8, 400, -1, "Arial") ;arial font for edit ctrl
GUISetState(@SW_SHOW, $stemp) ;display clear label inside of edit control

for $i = 0 to 4
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32) ;drawing first 4 icons into GDI (window)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $clear_label ;edit label in the "trick" child-window inside of EDIT control
            GUICtrlSetData($Edit1, "")
    EndSwitch
    
    Local $c = GUIGetCursorInfo($Form1) ;get mouse location inside of GUI
        Local $x_coord = $c[0] ;mouse x coordinate inside of GUI
        Local $y_coord = $c[1] ;mouse y coordinate isnide of GUI
        if $y_coord < 52 AND $y_coord > 0 AND WinActive($Form1) Then ;top and bottom coordinate of toolbar
            if TimerDiff($timer_10) >= 10 then ;sliding is chaotic if there is no speed limitation, 10ms in this case is just enough
                $timer_10 = TimerInit()
                Switch $x_coord
                    case -100 to 41 ;left corner - moving icons to the right
                        $inside = true ;is mouse inside of sliding area? yes!
                        _shrink_all() ;if there is any icon that is enlarged, it'll be decreased
                        $moving = true ;is slider mooving? yes!
                        Local $speed
                        Local $x_coord1 = $x_coord
                        if $x_coord1 < 0 then
                            $x_coord1 = 0 ;if this isn't limited to 0 then the speed would continue to increase if the mouse is outside (but near) window
                        EndIf
                        $speed = int(((41-$x_coord1)/15)^2) ;acceleration and speed of sliding icons is increased parabolical, and not linear, that's why ^2
                        if $speed < 1 then $speed = 1 ;min speed should be 1px
                        for $i = 0 to 9
                            $icon_info[$i][3] += $speed ;changing x starting coordinate for each icon
                            $icon_info[$i][4] += $speed ;changing x starting coordinate for each icon
                            
                            if Int($icon_info[$cur_first][3]) >= 25 Then ;this is where last icon become first
                                Local $previous = $cur_first
                                $cur_first -= 1
                                if $cur_first < 0 then $cur_first = 9
                                $icon_info[$cur_first][3] = int($icon_info[$previous][3]) - 57
                                $icon_info[$cur_first][4] = int($icon_info[$previous][4]) - 57
                            EndIf
                            
                            if $icon_info[$i][3] < 253+25 then ;icons that aren't visible shouldn't move at all (and thus save pc resources)
                                Local $width_x = 10
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][4], 15, $width_x, 32);Right side filling black line
                                _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32);icon image
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][3]-$width_x, 15, $width_x, 32);Left side filling black line
                            EndIf
                        Next
                    case 212 to 253+100 ;right corner - moving to the left
                        $inside = true
                        _shrink_all()
                        $moving = true
                        Local $speed
                        Local $x_coord1 = $x_coord
                        if $x_coord1 > 253 then
                            $x_coord1 = 253
                        EndIf
                        $speed = Int((($x_coord1-212)/15)^2)
                        if $speed < 1 then $speed = 1
                        for $i = 0 to 9
                            $icon_info[$i][3] -= $speed
                            $icon_info[$i][4] -= $speed
                            
                            if int($icon_info[$cur_last][3]) <= 228 Then ;this is where first icon become last
                                Local $previous = $cur_last
                                $cur_last += 1
                                if $cur_last > 9 then $cur_last = 0
                                $icon_info[$cur_last][3] = int($icon_info[$previous][3]) + 57
                                $icon_info[$cur_last][4] = int($icon_info[$previous][4]) + 57

                            EndIf
                            
                            if $icon_info[$i][4]+25 > 0 then
                                Local $width_x = 10
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][3]-$width_x, 15, $width_x, 32);Left side filling black line
                                _GDIPlus_GraphicsDrawImageRect($hGraphic, $icons[$i], $icon_info[$i][3], 15, 32, 32)
                                _GDIPlus_GraphicsFillRect($hGraphic, $icon_info[$i][4], 15, $width_x, 32);Right side filling black line
                            EndIf
                        Next
                    case Else
                        $moving = False
                        if $inside = True Then
                            $inside = False
                            Local $founded = 10
                            for $i = 0 to 9
                                if $icon_info[$i][2] = True Then
                                    $founded = $i
                                    ExitLoop
                                EndIf
                            Next
                            if $founded <> 10 then
                                if $icon_info[$founded][5] = false Then
                                    _easy_rise($icons[$founded], $icon_info[$founded][3]-2, 12, 37, 37)
                                    $icon_info[$founded][5] = true
                                EndIf
                            EndIf
                        EndIf
                EndSwitch
            EndIf
                switch $x_coord
                    case $icon_info[0][3]-5 to $icon_info[0][4]+5 ;1st icon, mouse is hovering above 1st icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(0)
                    case $icon_info[1][3]-5 to $icon_info[1][4]+5 ;2nd icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(1)
                    case $icon_info[2][3]-5 to $icon_info[2][4]+5 ;3rd icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(2)
                    case $icon_info[3][3]-5 to $icon_info[3][4]+5 ;4th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(3)
                    case $icon_info[4][3]-5 to $icon_info[4][4]+5 ;5th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(4)
                    case $icon_info[5][3]-5 to $icon_info[5][4]+5 ;6th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(5)
                    case $icon_info[6][3]-5 to $icon_info[6][4]+5 ;7th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(6)
                    case $icon_info[7][3]-5 to $icon_info[7][4]+5 ;8th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(7)
                    case $icon_info[8][3]-5 to $icon_info[8][4]+5 ;9th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(8)
                    case $icon_info[9][3]-5 to $icon_info[9][4]+5 ;10th icon
                        if $x_coord >= 0 AND $x_coord <= 253 then _for_icon(9)
                    case Else
                        _shrink_all()
                EndSwitch
        Else
            _shrink_all()
        EndIf
    if Round(TimerDiff($timer_end_txt)) >= 500 then GUICtrlSetData($toolbar_display_txt, "") ;if mouse wasn't hovering above any icon for 0.5sec, display txt should vanish
    if WinActive($stemp) then WinActivate($form1) ;if the child window with label "clear" inside of EDIT ctrl is active, then main window should activate and set as current
WEnd
    
func _for_icon($number)
    $timer_end_txt = TimerInit() ;timer for vanishing txt label that display txt of curent icon
    if $icon_info[$number][2] = False then ;prevent constant shrinking and enlarging
        GUICtrlSetData($toolbar_display_txt, $icon_info[$number][1]) ;set label txt to curent icon info
        if $moving = False then ;if the slider isn't moving then it's OK to resize icons
            _shrink_all()
            _easy_rise($icons[$number], $icon_info[$number][3]-2, 12, 37, 37) ;should enlarge selected icon
            $icon_info[$number][5] = true ;setting the curent icon as enlarged
        EndIf
        $icon_info[$number][2] = True ;setting the curent icon as selected
    EndIf
    If _IsPressed(01) then ;if mouse click is down on the selected icon
        if $icon_info[$number][5] = false Then
            _easy_rise($icons[$number], $icon_info[$number][3]-2, 12, 37, 37)
            $icon_info[$number][5] = true
        EndIf
        Do
        Until NOT _IsPressed(01) ;waiting for mouse key to release (like on regular buttons)
        Local $c = GUIGetCursorInfo($Form1)
        Local $x_coord = $c[0]
        Local $y_coord = $c[1]
        if $x_coord > $icon_info[$number][3]-5 AND $x_coord < $icon_info[$number][4]+5 AND $y_coord < 42 AND $y_coord > 0 AND WinActive($Form1) Then ;if the mouse click is released while cursor was still on that icon and while GUI is active...
        Switch $number
            case 0
                ;func for icon 1
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "1st Icon Clicked - " & $icon_info[0][1]) ;edit this, and set any function you want to be called when you hit 1st icon
            case 1
                ;func for icon 2
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "2nd Icon Clicked - " & $icon_info[1][1])
            case 2
                ;func for icon 3
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "3rd Icon Clicked - " & $icon_info[2][1])
            case 3
                ;func for icon 4
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "4th Icon Clicked - " & $icon_info[3][1])
            case 4
                ;func for icon 5
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "5th Icon Clicked - " & $icon_info[4][1])
            case 5
                ;func for icon 6
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "6th Icon Clicked - " & $icon_info[5][1])
            case 6
                ;func for icon 7
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "7th Icon Clicked - " & $icon_info[6][1])
            case 7
                ;func for icon 8
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "8th Icon Clicked - " & $icon_info[7][1])
            case 8
                ;func for icon 9
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "9th Icon Clicked - " & $icon_info[8][1])
            case 9
                ;func for icon 10
                _GUICtrlEdit_AppendText($Edit1, @CRLF & "10th Icon Clicked - " & $icon_info[9][1])
        EndSwitch
        EndIf
    EndIf
EndFunc

func _shrink_all()
    for $i = 0 to 9
        if $icon_info[$i][2] = True Then ;if icon is selected
            if $icon_info[$i][5] = True then ;if icon is enlarged
                _easy_shrink($icons[$i], $icon_info[$i][3], 15, 32, 32)
                $icon_info[$i][5] = False
            EndIf
            $icon_info[$i][2] = false
        EndIf
    Next
EndFunc

func _easy_rise($immmmage, $iX, $iY, $iW, $iH, $maxxx=6, $step = 1) ;image to be resized, x-coord of the image, y-coord of the image, width of the image, height of the image, max enlargement, speed of enlargement
    for $i = 1 to $maxxx Step $step
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX-$i, $iY-$i, $iW+2*$i, $iH+2*$i) ;enlarging icon
        Sleep(1) ;making it smooth
    Next    
EndFunc

func _easy_shrink($immmmage, $iX, $iY, $iW, $iH, $maxxx=6, $step = 1)
    Local $cntr = 0
    for $i = $maxxx to 1 Step -$step
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX-$i, $iY-$i, $iW+2*$i, $iH+2*$i) ;shrinking icon
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i-$step, $step+3, $iH+2*$i+2*$step);black goes Left
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i+$iW+2*$i-$step+1, $iY-$i-$step, $step+3, $iH+2*$i+2*$step);black goes Right
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i-$step-3, $iW+2*$i+($step+3)*2, $step+3);black goes Above
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$i-$step-3, $iY-$i+$iH+2*$i, $iW+2*$i+($step+3)*2, $step+3);black goes Bellow
        $cntr = $i
        Sleep(1)
    Next
    if $iW+2*$cntr <> $iW OR $iH+2*$cntr <> $iH then ;if shrinking didn't went to the exact size it was supposed to, this will make it regular size again
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $immmmage, $iX, $iY, $iW, $iH) ;drawing icon @ it's original size
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY, $step+3, $iH);Left
        _GDIPlus_GraphicsFillRect($hGraphic, $iX+$iW, $iY, $step+3, $iH);Right
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY-$step-3, $iW+2*($step+3), $step+3);Above
        _GDIPlus_GraphicsFillRect($hGraphic, $iX-$step-3, $iY+$iH, $iW+2*($step+3), $step+3);Bellow
    EndIf
EndFunc

func _extract_icons()
    for $i = 0 to 9
        Local $Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$shell32,"int*",(-1*$icon_info[$i][0])-1) ;extract icon from file
        Local $hIcon = $Ret[0] ;icon's handle
        Local $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0) ;create bitmap from icon's handle
        _GDIPlus_ImageSaveToFile($pBitmap[2],@ScriptDir & "test_image" & $i & ".bmp") ;why am I saving it instead of using it's handle? Using it's handle will make parts around icon transparent,
        _GDIPlus_ImageDispose($pBitmap[2]) ;                                             thus ruining resize/select mode, but saving it as image will fill up the transparent parts with black color
        $icons[$i] = _GDIPlus_ImageLoadFromFile(@ScriptDir & "test_image" & $i & ".bmp") ;and now loading this file
        _WinAPI_DestroyIcon($Ret[0]) ;and clearing resources by destroying icon's handle we don't need anymore...
    Next
EndFunc

func _set_icon_info()
    ;icon value:
    $icon_info[0][0] = "-13"; = memory
    $icon_info[1][0] = "-204"; = Camera
    $icon_info[2][0] = "-197"; = Phone
    $icon_info[3][0] = "-131"; = MS Live
    $icon_info[4][0] = "-166"; = Gear
    $icon_info[5][0] = "-172"; = Search
    $icon_info[6][0] = "-169"; = Sound
    $icon_info[7][0] = "-171";= MSN
    $icon_info[8][0] = "-200"; = HDD
    $icon_info[9][0] = "-201"; = PDA
    
    ;icon name:
    $icon_info[0][1] = "Memory"; = memory
    $icon_info[1][1] = "Camera"; = Camera
    $icon_info[2][1] = "Phone"; = Phone
    $icon_info[3][1] = "MS Live"; = MS Live
    $icon_info[4][1] = "Gear"; = Gear
    $icon_info[5][1] = "Search"; = Search
    $icon_info[6][1] = "Sound"; = Sound
    $icon_info[7][1] = "MSN";= MSN
    $icon_info[8][1] = "HDD"; = HDD
    $icon_info[9][1] = "PDA"; = PDA
    
    ;icon hover:
    $icon_info[0][2] = False; = memory
    $icon_info[1][2] = False; = Camera
    $icon_info[2][2] = False; = Phone
    $icon_info[3][2] = False; = MS Live
    $icon_info[4][2] = False; = Gear
    $icon_info[5][2] = False; = Search
    $icon_info[6][2] = False; = Sound
    $icon_info[7][2] = False;= MSN
    $icon_info[8][2] = False; = HDD
    $icon_info[9][2] = False; = PDA
    
    ;icon enlarged:
    $icon_info[0][5] = False; = memory
    $icon_info[1][5] = False; = Camera
    $icon_info[2][5] = False; = Phone
    $icon_info[3][5] = False; = MS Live
    $icon_info[4][5] = False; = Gear
    $icon_info[5][5] = False; = Search
    $icon_info[6][5] = False; = Sound
    $icon_info[7][5] = False;= MSN
    $icon_info[8][5] = False; = HDD
    $icon_info[9][5] = False; = PDA
    
    ;icon start/end coordinate x:
    Local $x_x = 0
    for $i = 0 to 9
        $x_x += 25
        $icon_info[$i][3] = $x_x ; = start X coordinate
        $x_x += 32
        $icon_info[$i][4] = $x_x ; = end X coordinate
    Next
EndFunc

func endscript() ;clearing resources @ the and of the script
    _GDIPlus_GraphicsDispose($hGraphic)
    for $i = 0 to 9
        _GDIPlus_ImageDispose($icons[$i])
        FileDelete(@ScriptDir & "test_image" & $i & ".bmp")
    Next
    _GDIPlus_Shutdown()
EndFunc

i am write question link

help me ...

I interest am many quite in AutoitScript.From that is [http://cafe.naver.com/autoitscript[/color]] Korea of cafe(blog) to be operating, [size="2"][color="#ff00ff"]English cannot well[/size].Many help it requests.To read, it stands it thanks.

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...