Jump to content

Icon bar in Autoit


Go to solution Solved by Subz,

Recommended Posts

  • Solution

Create an image list and apply against the toolbar, see _GUICtrlToolbar_SetImageList in the help file for an example

$hToolbar = _GUICtrlToolbar_Create($hGUI)
    $hImages = _GUIImageList_Create(32, 24)
    _GUIImageList_AddIcon($hImages, @SystemDir & "\shell32.dll", 5)
    _GUICtrlToolbar_SetImageList($hToolbar, $hImages)

 

Link to comment
Share on other sites

After testing it out i can't figure out why my script doesn't work. I tried what you said but i keep getting blank images on the buttons

#NoTrayIcon

#include <Misc.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <String.au3>
#include <GuiRichEdit.au3>
#include <GuiToolbar.au3>
#include <GuiImageList.au3>

$WIDTH = 500
$HEIGHT = 380
$EXT1 = "|Rich Text File (*.rtf)"
$EXT2 = "|ODF Text (*.odt)"
$EXT3 = "|All Files(*.*)"
$EXT = $EXT1 & $EXT2
$SETTINGS = "Settings.ini"

Global $FILESAVE, $FILEOPEN = "", $SAVES, $SAVE, $FILEOPENED = 0
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp


$MAINGUI = GUICreate("Text Editor", $WIDTH, $HEIGHT, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE)

 $TOOLBAR = _GUICtrlToolbar_Create($MAINGUI)
 _GUIImageList_AddIcon($TOOLBAR, @SystemDir & "\shell.dll", -1)
 $IMAGES = _GUIImageList_Create(24,24)
 _GUICtrlToolbar_SetImageList($TOOLBAR, $IMAGES)



 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -1)
 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, -2)
 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 3)
 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 4)
 _GUICtrlToolbar_AddButtonSep($TOOLBAR)
 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 5)
 _GUICtrlToolbar_AddButton($TOOLBAR, $e_idNew, 6)


 $EDITBOX = _GUICtrlRichEdit_Create($MAINGUI, "This is a test.", 10, 35, $WIDTH - 20, $HEIGHT - 70, _
                  BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

$FILE = GUICtrlCreateMenu("File")

$NEW = GUICtrlCreateMenuItem("New", $FILE)
$OPEN = GUICtrlCreateMenuItem("Open...", $FILE)
$SAVE = GUICtrlCreateMenuItem("Save", $FILE)
$SAVEAS = GUICtrlCreateMenuItem("Save As...", $FILE)
$PRINT = GUICtrlCreateMenuItem("Print...", $FILE)

GUICtrlCreateMenuItem("", $FILE)

$EXIT = GUICtrlCreateMenuItem("Exit", $FILE)

$EDIT = GUICtrlCreateMenu("Edit")
$UNDO = GUICtrlCreateMenuItem("Undo", $EDIT)
$REDO = GUICtrlCreateMenuItem("Redo", $EDIT)
$SEPARATOR = GUICtrlCreateMenuItem("", $EDIT)
$FONT = GUICtrlCreateMenuItem("Font test", $EDIT)
$SEPARATOR1 = GUICtrlCreateMenuItem("", $EDIT)
$CUT = GUICtrlCreateMenuItem("Cut", $EDIT)
$COPY = GUICtrlCreateMenuItem("Copy", $EDIT)
$PASTE = GUICtrlCreateMenuItem("Paste", $EDIT)





GUISetState(@SW_SHOW & $GUI_ACCEPTFILES)

While 1
    $Msg = GUIGetMsg()
    Select

        Case $Msg = $GUI_EVENT_CLOSE
            If _GUICtrlEdit_CanUndo($EDITBOX) Then
                $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?")
                If $SAVECHANGES = 6 And $FILEOPENED = 0 Then
                    SaveAs()
                    _GUICtrlRichEdit_Destroy($hRichEdit)
                    Exit
                EndIf
                If $SAVECHANGES = 6 And $FILEOPENED = 1 Then
                    FileDelete($FILEOPEN)
                    FileWrite($FILEOPEN, GUICtrlRead($EDITBOX))
                    Exit
                EndIf
                If $SAVECHANGES = 7 Then
                    ExitLoop
                    Exit
                EndIf
            EndIf
            If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit

        Case $Msg = $OPEN
            $FILEOPEN = FileOpenDialog("Open", $FILEOPEN, $EXT)
            $TEXT = _GUICtrlRichEdit_StreamFromFile($EDITBOX, $FILEOPEN)
            _GUICtrlRichEdit_ReplaceText($EDITBOX, $TEXT)
            $FILEOPENED = 1

        Case $Msg = $NEW
            If _GUICtrlEdit_CanUndo($EDITBOX) Then
                $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?")
                If $SAVECHANGES = 6 And $FILEOPENED = 0 Then
                    SaveAs()
                EndIf
                If $SAVECHANGES = 6 And $FILEOPENED = 1 Then
                    FileDelete($FILEOPEN)
                    FileWrite($FILEOPEN, GUICtrlRead($EDITBOX))
                EndIf
                If $SAVECHANGES = 7 Then GUICtrlSetData($EDITBOX, "")
                If $SAVECHANGES = 2 Then Sleep(1)
            EndIf
            If Not _GUICtrlEdit_CanUndo($EDITBOX) Then GUICtrlSetData($EDITBOX, "")
            $FILEOPENED = 0

        Case $Msg = $EXIT
            If _GUICtrlEdit_CanUndo($EDITBOX) Then
                $SAVECHANGES = MsgBox(35, "Text Editor", "Your original file has been modified." & @CRLF & "Would you like to save changes to it?")
                If $SAVECHANGES = 6 And $FILEOPENED = 0 Then
                    SaveAs()
                    _GUICtrlRichEdit_Destroy($hRichEdit)
                    Exit
                EndIf
                If $SAVECHANGES = 6 And $FILEOPENED = 1 Then
                    FileDelete($FILEOPEN)
                    FileWrite($FILEOPEN, GUICtrlRead($EDITBOX))
                    Exit
                EndIf
                If $SAVECHANGES = 7 Then ExitLoop
                If $SAVECHANGES = 2 Then
                    Sleep(1)
                EndIf
            EndIf
            If Not _GUICtrlEdit_CanUndo($EDITBOX) Then Exit

        Case $Msg = $SAVEAS
            GUICtrlSetState($EDITBOX, $GUI_DISABLE)
            SaveAs()
            $FILEOPENED = 1
            GUICtrlSetState($EDITBOX, $GUI_ENABLE)

        Case $Msg = $SAVE And $FILEOPENED = 1
            FileDelete($FILEOPEN)
            FileWrite($FILEOPEN, GUICtrlRead($EDITBOX))
            _GUICtrlEdit_EmptyUndoBuffer($EDITBOX)

        Case $Msg = $SAVE And $FILEOPENED = 0
            GUICtrlSetState($EDITBOX, $GUI_DISABLE)
            SaveAs()
            $FILEOPENED = 1
            GUICtrlSetState($EDITBOX, $GUI_ENABLE)

        Case $Msg = $SAVE And $FILEOPENED = 0
            GUICtrlSetState($EDITBOX, $GUI_DISABLE)
            SaveAs()
            $FILEOPENED = 1
            GUICtrlSetState($EDITBOX, $GUI_ENABLE)

        Case $Msg = $PRINT
            $PRINTMSGBOX = MsgBox(35, "Text Editor", "Are you sure you want to print this page?")
            Select

                Case $PRINTMSGBOX = 6
                    If FileExists("Print.txt") Then
                        FileDelete("Print.txt")
                    EndIf
                    FileWrite("Print.txt", GUICtrlRead($EDITBOX))
                    $PRINTFILE = "Print.txt"
                    _FilePrint($PRINTFILE)
                    FileDelete($PRINTFILE)
            EndSelect

        Case $Msg = $UNDO
            _GUICtrlRichEdit_Undo($EDITBOX)

        Case $Msg = $REDO
            _GUICtrlRichEdit_Redo($EDITBOX)

        Case _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 1
            GUICtrlSetState($SAVE, $GUI_ENABLE)

        Case $Msg = $CUT
            _GUICtrlRichEdit_Cut ($EDITBOX)

        Case $Msg = $COPY
            _GUICtrlRichEdit_Copy ($EDITBOX)

        Case $Msg = $PASTE
            _GUICtrlRichEdit_Paste ($EDITBOX)

        Case Not _GUICtrlEdit_CanUndo($EDITBOX) And $SAVES = 0
            GUICtrlSetState($SAVE, $GUI_DISABLE)
            $SAVES = 1
         Case $Msg = $FONT
            _GUICtrlRichEdit_SetFont($EDITBOX, 15, "Times New Roman")

    EndSelect
WEnd
Exit

Func SaveAs()
    $FILESAVEAS = FileSaveDialog("Save As", "", "Text Document (*.txt)|All Files (*.*)")
    If Not @error Then
        $STRING = StringSplit($FILESAVEAS, ".")
        If $STRING[0] = 1 Then
            FileDelete($FILESAVEAS)
            _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf")
        Else
;~             FileWrite($FILESAVEAS, _GUICtrlRichEdit_GetText($EDITBOX))
            _GUICtrlRichEdit_StreamToFile($EDITBOX, $FILESAVEAS &".rtf")
        EndIf
    EndIf
EndFunc

I reuploaded my script and here is the custom dll file with icons:

I used the included autoit fileenum example to get the dll icon and anolis to make the icon file

ico.dll

Edited by AFrenchCroissant
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...