Jump to content

Butttons and Icons again


Aceguy
 Share

Recommended Posts

im trying to get a button with an .exe image, it works with

line 17 $icon2=GUICtrlCreateIcon("",'',5,25) buth when i change it to a button

$icon2=GUICtrlCreateButton('',5,30,50,50,$BS_ICON ) stops working PLEASE HELP

heres my simple code

#include<GUIConstants.au3>
#include<Math.au3>
#include<File.au3>
#include<String.au3>
#include<Misc.au3>
#include<Array.au3>
#include <Process.au3>



$Form2 = GUICreate("Go Launcher", 224, 72, 303, 300, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))

$Button1 = GUICtrlCreateButton("Add", 8, 8, 65, 17, 0)
$Button2 = GUICtrlCreateButton("Remove", 80, 8, 65, 17, 0)
$Button3 = GUICtrlCreateButton("Change", 152, 8, 65, 17, 0)

;$icon2=GUICtrlCreateIcon("",'',5,25)

$icon2=GUICtrlCreateButton('',5,30,50,50,$BS_ICON  )

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg=$GUI_EVENT_CLOSE 
            MsgBox(0,"","clicked close",2)
            GUIDelete($Form2)
            Exit
        case $msg=$Button1
            _BrowseDirc()
    EndSelect
WEnd
Func _BrowseDirc()
    $Dirc = FileOpenDialog("Please Select the File", @DesktopDir, "exe (*.exe)", 1 + 2)
    $String = StringSplit($Dirc, ".")
    $String2 = StringSplit($String[1], "\")
    $Display = UBound($String2, 1) - 1
    
GUICtrlSetImage($icon2,$Dirc,-1)



;   $info=FileGetShortcut($String & "\.lnk")
    
;_ArrayDisplay($info[0])
EndFunc  ;==>_BrowseDirc
Link to comment
Share on other sites

GUICtrlSetImage ( controlID, filename [, iconname [, icontype]] )

Here's a sample of this code, should help you out alot, note this can be used with an icon OR an image, does not have to be loaded from a .dll

$Button1 = GUICtrlCreateButton ("my picture button", 10,20,40,40, $BS_ICON)
GUICtrlSetImage ($Button1, "shell32.dll",22)

~TK

Link to comment
Share on other sites

GUICtrlSetImage ( controlID, filename [, iconname [, icontype]] )

Here's a sample of this code, should help you out alot, note this can be used with an icon OR an image, does not have to be loaded from a .dll

$Button1 = GUICtrlCreateButton ("my picture button", 10,20,40,40, $BS_ICON)
GUICtrlSetImage ($Button1, "shell32.dll",22)

~TK

If I have a bitmap file in c:\temp\arrow_up.gif

How can you set this image on the button?

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Im haveing trouble with removing a button, please help

#include<GUIConstants.au3>
#include<File.au3>
#include<Array.au3>



dim $launch[50]
dim $button[50]
$IniFile = @MyDocumentsDir & "\Launcher.txt"

$x_size=800
$Form2 = GUICreate("Go Launcher", 245, 70, $x_size, 100, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("Add", 8, 8, 65, 17, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetBkColor(-1,0xffffff)
$Button2 = GUICtrlCreateButton("Remove", 80, 8, 65, 17, 0)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetBkColor(-1,0xffffff)
$log=GUICtrlCreateLabel("",160,8,100,-1)
GUICtrlSetColor(-1,0xffffff)
$box = 1
$x = 0
$c = 1


GUISetState(@SW_SHOW)
GUICtrlSetData($log,"HELLO")
_FileReadToArray($IniFile,$launch)
sleep(250)
_ArrayDelete($launch,1)
sleep(250)
;_ArrayDisplay($launch)

 


for $x_load= 1 to $launch[0]-1
    if $launch[$x_load] <> "0" or $launch[$x_load] <> 0 then
$button[$x_load]=GUICtrlCreateButton("", 5 + $x, 30, 35, 35, $BS_ICON)
    GUICtrlSetImage(-1, $launch[$x_load], 0)
    
    if @error=1 Then
        GUICtrlSetImage($launch[$x_load],@MyDocumentsDir&"\noimage.jpg")
        EndIf
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
;MsgBox(0,$launch[$box], $launch[$x_load],0)
    $launch[$box] = $launch[$x_load]
    $box = $box + 1
    $x = $x + 40
    $c = $c + 1
if $box >7 Then
    $size_main = WinGetPos("Go Launcher")
    WinMove("Go Launcher","", $size_main[0], $size_main[1], $size_main[2] +40)
    endif   
    EndIf
    next


While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then
    

    for $xc=0 to UBound($launch)-1
    if $launch[$xc]='' Then
        $launch[$xc]="0"
        EndIf
    
    Next
    
    _FileWriteFromArray($IniFile,$launch)   
        sleep(500)
        GUIDelete($Form2)
        Exit
    EndIf
    
    If $msg = $Button1 Then
        _BrowseDirc()
    EndIf
    
    if $msg = $Button2 Then

    GUICtrlSetBkColor($Button2,0xff0000)
sleep(50)
    Do
    $a_mpos = GUIGetCursorInfo($Form2)
    if _IsPressed(01) and WinActive("Go Launcher") and $a_mpos[4] >5 then 
GUICtrlSetBkColor($Button2,0xffffff)
        $a_mpos = GUIGetCursorInfo($Form2)
        GUICtrlSetData($log,$a_mpos[4])
    
    if  $a_mpos[4] >5 Then 
    GUICtrlDelete($box+4)
    sleep(50)
    _ArrayDelete($launch,$a_mpos[4]-5)
    sleep(50)
    _ArrayAdd($launch,"0")
    $size_main = WinGetPos("Go Launcher")
    WinMove("Go Launcher","", $size_main[0], $size_main[1], $size_main[2] -40)
    EndIf
    $x = $x - 40
    $c = $c - 1

    for $z=1 to $launch[0]-1
        
        GUICtrlSetImage($button[$z], $launch[$z], 0)
    if @error=1 Then
        GUICtrlSetImage($button[$z],@MyDocumentsDir&"\noimage.jpg")
        EndIf
    Next
        
        sleep(100)
        GUICtrlSetBkColor($Button2,0xffffff)
        ExitLoop
    
    EndIf

until 0=1

    
GUICtrlSetBkColor($Button2,0xffffff)
    
        $box=$box-1
;   MsgBox(0,"",$box,0)
    EndIf
    
    $a_mpos = GUIGetCursorInfo($Form2)
    If IsArray($a_mpos) = 1 And $a_mpos[2]  and $a_mpos[4]>5 and WinActive("Go Launcher") Then

        For $b = 1 To 50
            If $a_mpos[4] = $b Then
        run($launch[$b-5])
        GUICtrlSetData($log, "Please Wait!!")
    ;GUICtrlSetData($log,$a_mpos[4]&" Box "&$box)
        sleep(2000)
        GUICtrlSetData($log,"Ready!")
        EndIf


        Next
    EndIf

WEnd
Func _BrowseDirc()
    
    $Dirc = FileOpenDialog("Please Select the File", @DesktopDir, "exe (*.exe)", 1 + 2)
    if @error=0 Then
        GUICtrlCreateButton("", 5 + $x, 30, 35, 35, $BS_ICON)
    GUICtrlSetImage(-1, $Dirc, 0)
    MsgBox(0,"",@error,0)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    $launch[$box] = $Dirc
    $box = $box + 1
    $x = $x + 40
    $c = $c + 1
if $box >7 Then
    $size_main = WinGetPos("Go Launcher")
    WinMove("Go Launcher","", $size_main[0], $size_main[1], $size_main[2] +40)
endif
EndIf
EndFunc  ;==>_BrowseDirc

plesae help

Link to comment
Share on other sites

Hi,

I don't have an answer to your delete a button issue..

But here's a similar example of doing what your after , I had a spare half hour so I sorta wrote an example.

Instead of the delete button I used a right click context menu on an added button offering delete..

Also added right click context menu to the add button offering to Delete All Buttons.

Instead of FileReadTo/From array I used IniRead/Write..

Instead of the label I used tooltips when you point at a button and it shows the path to what the button launches.

Instead of the gui starting at a hard set 800 pixel to the right of the screen I used @DeskTopWidth - AppWidth

(This way it'll always start on the far right of the screen no matter what resolution the desktop is)

Made it so if the gui is past the edge of the right hand side of the desktop and a button is added then it snaps the gui to to edge of the screen so the new button can be seen.

Made it so there's no limit on how many buttons can be added.

Saves settings to an ini when exiting.

Loads setting from ini on startup.

etc...

#include<GUIConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $Button[1][4], $Context[2], $bX = 40, $aW = 40, $ButtonOld, $Button1, $Gui
Global $IniFile = @ScriptDir & "\GoLauncher.ini"

$Gui = GUICreate("Go Launcher", $aW, 40, @DesktopWidth - ($aW + 5), 100, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("", 0, 1, 40, 40, $BS_ICON)
GUICtrlSetOnEvent(-1, "BrowseDir")
GUICtrlSetImage(-1, "shell32.dll", 4)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE)
GUICtrlSetTip(-1, "Click here to browse for programs to add to Go Launcher")
$Context[0] = GUICtrlCreateContextMenu($Button1)
$Context[1] = GUICtrlCreateMenuItem("Delete All Buttons", $Context[0])
GUICtrlSetOnEvent(-1, "DeleteAllButtons")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $Gui)
GUISetState(@SW_SHOW)

LoadSettings()

While 1
    Sleep(100)
WEnd

Func BrowseDir()
    Local $Dirc = FileOpenDialog("Please Select the File", @DesktopDir, "exe (*.exe)", 3)
    If Not @error Then
        $Button[0][0] += 1
        ReDim $Button[$Button[0][0] + 1][4]
        $Button[$Button[0][0]][0] = GUICtrlCreateButton("", $bX, 1, 40, 40, $BS_ICON)
        GUICtrlSetOnEvent(-1, "Clicked")
        GUICtrlSetImage(-1, $Dirc, 0)
        GUICtrlSetTip(-1, $Dirc)
        GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE)
        $Button[$Button[0][0]][1] = $Dirc
        $Button[$Button[0][0]][2] = GUICtrlCreateContextMenu($Button[$Button[0][0]][0])
        $Button[$Button[0][0]][3] = GUICtrlCreateMenuitem("Delete Button", $Button[$Button[0][0]][2])
        GUICtrlSetOnEvent(-1, "Clicked")
        $bX += 40
        Local $WGP = WinGetPos($Gui)
        If $WGP[0] + ($bX + 5) > @DesktopWidth Then
            WinMove($Gui, "", @DesktopWidth - ($bX + 5), $WGP[1], $WGP[2] + 40)
        Else
            WinMove($Gui, "", $WGP[0], $WGP[1], $WGP[2] + 40)
        EndIf
    EndIf
EndFunc

Func Clicked()
    For $c = 1 To $Button[0][0]
        If @GUI_CtrlId = $Button[$c][0] Then ShellExecute($Button[$c][1])
        If @GUI_CtrlId = $Button[$c][3] Then DeleteButton($c)
    Next
    If $Button[0][0] <> $ButtonOld Then
        ReDim $Button[$Button[0][0] + 1][4]
        $ButtonOld = $Button[0][0]
    EndIf
EndFunc

Func DeleteAllButtons()
    If $Button[0][0] > 0 Then 
        For $a = 0 To $Button[0][0]
            GUICtrlDelete($Button[$a][0])
            GUICtrlDelete($Button[$a][2])
            GUICtrlDelete($Button[$a][3])
        Next    
        Dim $Button[1][4]
        Local $WGP = WinGetPos($Gui)
        WinMove($Gui, "", $WGP[0], $WGP[1], 44)
    EndIf   
EndFunc

Func DeleteButton($iD)
    For $d = $iD To $Button[0][0]
        If $d < $Button[0][0] Then $Button[$d][1] = $Button[$d + 1][1]
        GUICtrlSetImage($Button[$d][0], $Button[$d][1], 0)
        GUICtrlSetTip($Button[$d][0], $Button[$d][1])
    Next
    GUICtrlDelete($Button[$Button[0][0]][0])
    For $r = 0 To 3
        $Button[$Button[0][0]][$r] = ""
    Next
    $Button[0][0] -= 1
    $bX -= 40
    Local $WGP = WinGetPos($Gui)
    If $WGP[0] + ($bX + 5) > @DesktopWidth Then
        WinMove($Gui, "", @DesktopWidth - ($bX + 5), $WGP[1], $WGP[2] - 40)
    Else
        WinMove($Gui, "", $WGP[0], $WGP[1], $WGP[2] - 40)
    EndIf
EndFunc

Func SaveSettings()
    If FileExists($IniFile) Then IniDelete($IniFile, "PATHS")
    IniWrite($IniFile, "BUTONS", "Total", $Button[0][0])
    For $i = 1 To $Button[0][0]
        IniWrite($IniFile, "PATHS", "App" & $i, $Button[$i][1])
    Next
EndFunc

Func LoadSettings()
    If FileExists($IniFile) And IniRead($IniFile, "BUTONS", "Total", "") > 0 Then
        $Button[0][0] = IniRead($IniFile, "BUTONS", "Total", "")
        ReDim $Button[$Button[0][0] + 1][4]
        For $i = 1 To $Button[0][0]
            $Button[$i][1] = IniRead($IniFile, "PATHS", "App" & $i, "")
            $Button[$i][0] = GUICtrlCreateButton("", $bX, 1, 40, 40, $BS_ICON)
            GUICtrlSetOnEvent(-1, "Clicked")
            GUICtrlSetImage(-1, $Button[$i][1], 0)
            GUICtrlSetTip(-1, $Button[$i][1])
            GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKSIZE)
            $Button[$i][2] = GUICtrlCreateContextMenu($Button[$i][0])
            $Button[$i][3] = GUICtrlCreateMenuitem("Delete Button", $Button[$i][2])
            GUICtrlSetOnEvent(-1, "Clicked")
            $bX += 40
            Local $WGP = WinGetPos($Gui)
            If $WGP[0] + ($bX + 5) > @DesktopWidth Then
                WinMove($Gui, "", @DesktopWidth - ($bX + 5), $WGP[1], $WGP[2] + 40)
            Else
                WinMove($Gui, "", $WGP[0], $WGP[1], $WGP[2] + 40)
            EndIf
        Next
    EndIf
EndFunc

Func Close()
    SaveSettings()
    Exit
EndFunc

Have fun 'N' cheers

Edit: I was using Autoit v3.2.4.9 and XP SP2 when I wrote this...

Edited by smashly
Link to comment
Share on other sites

was wondering how difficlut it would be to have on the (open folder icon) a [add new row.?

so i could add another folder to the line below, then have like top row for game shortcuts and second row for app, and 3rd row for ect...

Link to comment
Share on other sites

Hi, glad you liked it..

An easy way of doing something similar ,

Maybe do profiles or modes..

Right click the add button and select a mode/profile..

eg: Games , Apps , Tools... etc

When one is selected then load a an ini for that mode/profile..

So once your in say the Games mode/profile then anything added/removed is done to that ini..

Select a differnt mode/profile then then load/save a differant ini..

The reason I thought doing the way you said then the toolbar would become quite big with to many buttons covering the work space.. Not to mention it''ll take a bit of work to do it the way you asked.

Doing it the way I was thinking would be quite easy, and you could load a mode/profiles quickly to have the games/apps/tools or whatever in the toolbar without using all the desktop space yet still having the set of items needed to suit your needs.

But each his own preference I think it boils down to..

Cheers

Link to comment
Share on other sites

Hi,

Here's what I meant about the profiles part that I mentioned about before...

Added right click context menu options to the Add button for Load, Create,Delete and Rename profiles.

Create as many profiles as you like. eg: Apps , Favorite Games, Utils

Added Duplicate filtering so profile names won't be added/renamed if the profile name already exists.

Added Check to make sure profile name starts with an alphabetical character when Creating or Renaming a profile.

Added prompt when deleting a profile , saves accidently deleting a profile.

Tooltip when pointing at the Add button shows the current profile that's loaded.

Profile limitations:

Profile names may only start with an alphabetical character (this applies to Create & Rename profile)

Other added tidbits:

Added Multi-Select files when browsing for files (make's it quicker to add buttons)

Added Drag N Drop single or mutiple files onto the Add button, uses filtering to make sure only exe's are added (make's it quicker to add buttons)

Added Duplicate filtering so buttons that are already in the loaded profile won't be added again when a user is adding buttons.

Added a right click context menu option to the title bar offering to send to tray.

Left click tray icon to show GoLauncher , Right click tray for option to Exit GoLauncher.

The ini format has changed from the last script so make sure you delete the old ini if your running this script from the same directory.

I was using AutoIt 3.4.9 and Windows XP SP2 when I wrote this.

I was going to post it in example scripts section, but I think there's enough of these type of launchers already there...lol

File attached if your intrested.

Do as you please with it :)

Off Topic Trivia:

I've made a similar thing for myself a while ago, but it uses alot more AI

(eg: scale buttons when there's to many on screen, snap bar to screen edge top/ bottom/left/ right, flip bar vertical / horizontal, cutomise icons/ShowFlag/WorkingDirectory/Parameter for each button, use urls/ftp/directories/anyfile as a buttons).

Basically anything that can be ShellExecuted can be added and launched.. But what I haven't added yet is profiles.

Hmm , I might have to look into it now...

Cheers

Link to comment
Share on other sites

Wow, thats really good, cough cough.

with my script after 10 buttons i have made it add to new line, + made a shrink/hide menu.

however when i resize the box, the bottom row of icon snap to the top.?

any ideas

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