Jump to content
stephenf

Custom Gui box with a button

Recommended Posts

I know how to trigger a message box. but Instead of the message box, I'd like to create a custom GUI which is read-only with a pre-defined chunk of text as a code snippet and has a button that has the functionality of copying that text to the clipboard. I am totally new to Autoit, please guide me to go further. a sample code would really make it easier for me to understand.

Share this post


Link to post
Share on other sites

stephenf,

instead of firing the existing MsgBox function - just roll one of your own to take its place.

Start by creating a GUI (GUICreate) then add a read-only editbox (GUICtrlCreateEdit) or a simple label (GUCtrlCreateLabel) and fill it with your required text (GUICtrlSetData). Add a button to the GUI as well (GUICtrlCreateButton) and then use ClipPut as an event when the button is pressed.

Give that a go and see how you get on - you know where we are if you run into problems.

M23

P.S. Welcome to the AutoIt forums.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
let StoredBooks = [{
        title: "bookOneTitle",
        author: "bookOneAuthor",
        isbn: "bookOneISBN"
    },

    {
        title: "bookTwoTitle",
        author: "bookTwoAuthor",
        isbn: "bookTwoISBN"
    }
];

this is the text data and I want to set using GUICtrlSetData). I also want the formatting to remain preserved.

GUICtrlSetData($idMyedit, "paste my data here", 1)

when i try this,

GUICtrlSetData($idMyedit, "
  
  
  let StoredBooks = [{
        title: "bookOneTitle",
        author: "bookOneAuthor",
        isbn: "bookOneISBN"
    },

    {
        title: "bookTwoTitle",
        author: "bookTwoAuthor",
        isbn: "bookTwoISBN"
    }
];
  
  
  
  ", 1)

It has problems, how should I proceed?

Share this post


Link to post
Share on other sites

I follow @Melba23 's advice and therefore do not give you the complete solution ;).

54 minutes ago, stephenf said:

this is the text data and I want to set using GUICtrlSetData). I also want the formatting to remain preserved.

Try :

Global $sString = 'let StoredBooks = [{' & @CRLF & _
                  '        title: "bookOneTitle",' & @CRLF & _
                  '        author: "bookOneAuthor",' & @CRLF & _
                  '        isbn: "bookOneISBN"' & @CRLF & _
                  '    },' & @CRLF & _
                  '      ' & @CRLF & _
                  '    {' & @CRLF & _
                  '        title: "bookTwoTitle",' & @CRLF & _
                  '        author: "bookTwoAuthor",' & @CRLF & _
                  '        isbn: "bookTwoISBN"' & @CRLF & _
                  '    },' & @CRLF & _
                  '];'

MsgBox(0, 'Code : ', $sString)

EDIT :

Quote

It has problems, how should I proceed?

Maybe one step more :

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_sString = 'let StoredBooks = [{' & @CRLF & _
                    '        title: "bookOneTitle",' & @CRLF & _
                    '        author: "bookOneAuthor",' & @CRLF & _
                    '        isbn: "bookOneISBN"' & @CRLF & _
                    '    },' & @CRLF & _
                    '      ' & @CRLF & _
                    '    {' & @CRLF & _
                    '        title: "bookTwoTitle",' & @CRLF & _
                    '        author: "bookTwoAuthor",' & @CRLF & _
                    '        isbn: "bookTwoISBN"' & @CRLF & _
                    '    },' & @CRLF & _
                    '];'

Example()

Func Example()
    GUICreate("My GUI edit", 800, 800)
    Local $idMyedit = GUICtrlCreateEdit("" & @CRLF, 30, 30, 740, 540, $ES_AUTOVSCROLL + $WS_VSCROLL)
    GUISetState(@SW_SHOW)
    GUICtrlSetData($idMyedit, $g_sString)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example
Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

 

5 minutes ago, Nine said:

Depends, how much data we are talking about ?

I posted a snippet above must be hundreds of snippets like that

Share this post


Link to post
Share on other sites

I will use this snippet app to cheat in a phone interview by saving my favourite code snippets and quickly navigating while answering questions. basically I have a poor memory. Google searches during the interview are usually not reliable and keyboard makes the sound so I would make tree-like navigation to quickly access code snippets without typing anything

Share this post


Link to post
Share on other sites
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>



Global $nTreeViewSelected = -1

Func Example($g_sString)
    Local $idEdit

    ; Create GUI
    GUICreate("Edit Set Text", 400, 300)
    $idEdit = GUICtrlCreateEdit("", 2, 2, 394, 268, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
    GUISetState(@SW_SHOW)


    ; Set Text
    _GUICtrlEdit_SetText($idEdit, $g_sString)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; JS - Define Array of Objects
Global $g_sString1 = 'let StoredBooks = [{' & @CRLF & _
        '        title: "bookOneTitle",' & @CRLF & _
        '        author: "bookOneAuthor",' & @CRLF & _
        '        isbn: "bookOneISBN"' & @CRLF & _
        '    },' & @CRLF & _
        '      ' & @CRLF & _
        '    {' & @CRLF & _
        '        title: "bookTwoTitle",' & @CRLF & _
        '        author: "bookTwoAuthor",' & @CRLF & _
        '        isbn: "bookTwoISBN"' & @CRLF & _
        '    },' & @CRLF & _
        '];'


; JS - Define class
Global $g_sString2 = 'class Book {' & @CRLF & _
        '    constructor(title, author, isbn) {' & @CRLF & _
        '        this.title = title;' & @CRLF & _
        '        this.author = author;' & @CRLF & _
        '        this.isbn = isbn;' & @CRLF & _
        '    }' & @CRLF & _
        '}'

; JS - forEach Loop
Global $g_sString3 = 'books.forEach(book => {' & @CRLF & _
'    UI.addBookToList(book);' & @CRLF & _
'})'

; JS - Define Object
Global $g_sString4 = 'myBookObject = new Book(bookinput, authorinput, isbninput);'

; JS - Template Literal
Global $g_sString5 = 'newTr.innerHTML = `' & @CRLF & _
'<td>${book.title}</td>' & @CRLF & _
'<td>${book.author}</td>' & @CRLF & _
'<td>${book.isbn}</td>' & @CRLF & _
'<td>X</td>' & @CRLF & _
'`;'

; HTML - Add Bootstrap
Global $g_sString6 = '<link rel="stylesheet" href="https://bootswatch.com/4/pulse/bootstrap.min.css">'

; HTML - Add Button
Global $g_sString7 = '<button class="add-book mt-5 btn btn-primary btn-block">Add Book</button>'

; HTML - Add Container Div
Global $g_sString8 = '<div class="container mt-4"></div>'

; HTML - Add Fontawesome
Global $g_sString9 = '<script src="https://kit.fontawesome.com/8e7a83d261.js" crossorigin="anonymous"></script>'

; HTML - Add a Form
Global $g_sString10 = '<form id="book-form">' & @CRLF & _
'' & @CRLF & _
'</form>'

; HTML - Add h1 heading
Global $g_sString11 = '<h1 class="display-4 text-center"><i class="fas fa-book-open text-primary"></i> My<span class="text-primary">Book</span>List' & @CRLF & _
'</h1>'

; HTML - Add InputBox
Global $g_sString12 = '<div class="form-group">' & @CRLF & _
'    <label for="title">Title</label>' & @CRLF & _
'    <input type="text" id="title" class="form-control">' & @CRLF & _
'</div>'

; HTML - Add a table
Global $g_sString13 = '<table class="table table-striped mt-5">' & @CRLF & _
'    <thead>' & @CRLF & _
'        <tr>' & @CRLF & _
'            <th>Title</th>' & @CRLF & _
'            <th>Author</th>' & @CRLF & _
'            <th>ISBN#</th>' & @CRLF & _
'            <th></th>' & @CRLF & _
'' & @CRLF & _
'        </tr>' & @CRLF & _
'    </thead>' & @CRLF & _
'    <tbody id="book-list"></tbody>' & @CRLF & _
'</table>'



#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\desktop\sumit\aform1.kxf
$Form1 = GUICreate("MyBookList Snippets", 350, 247, 303, 219)
$TreeView1 = GUICtrlCreateTreeView(24, 16, 305, 201)
$TreeView1_0 = GUICtrlCreateTreeViewItem("JS", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("HTML", $TreeView1)

$TreeView1_2 = GUICtrlCreateTreeViewItem("Define Array of Objects", $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Define class", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("forEach Loop", $TreeView1_0)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Define Object", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Template Literal", $TreeView1_0)

$TreeView1_7 = GUICtrlCreateTreeViewItem("Add Bootstrap", $TreeView1_1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Add Button", $TreeView1_1)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Add Container Div", $TreeView1_1)
$TreeView1_10 = GUICtrlCreateTreeViewItem("Add Fontawesome", $TreeView1_1)
$TreeView1_11 = GUICtrlCreateTreeViewItem("Add a Form", $TreeView1_1)
$TreeView1_12 = GUICtrlCreateTreeViewItem("Add h1 heading", $TreeView1_1)
$TreeView1_13 = GUICtrlCreateTreeViewItem("Add InputBox", $TreeView1_1)
$TreeView1_14 = GUICtrlCreateTreeViewItem("Add a table", $TreeView1_1)
$Button1 = GUICtrlCreateButton("OK", 256, 224, 75, 17, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $TreeView1_0
            $nTreeViewSelected = 0
        Case $TreeView1_2
            $nTreeViewSelected = $g_sString1
        Case $TreeView1_3
            $nTreeViewSelected = $g_sString2
        Case $TreeView1_4
            $nTreeViewSelected = $g_sString3
        Case $TreeView1_5
            $nTreeViewSelected = $g_sString4
        Case $TreeView1_6
            $nTreeViewSelected = $g_sString5
        Case $TreeView1_7
            $nTreeViewSelected = $g_sString6
        Case $TreeView1_8
            $nTreeViewSelected = $g_sString7
        Case $TreeView1_9
            $nTreeViewSelected = $g_sString8
        Case $TreeView1_10
            $nTreeViewSelected = $g_sString9
        Case $TreeView1_11
            $nTreeViewSelected = $g_sString10
        Case $TreeView1_12
            $nTreeViewSelected = $g_sString11
        Case $TreeView1_13
            $nTreeViewSelected = $g_sString12
        Case $TreeView1_14
            $nTreeViewSelected = $g_sString13



        Case $Button1
            If $nTreeViewSelected > -1 Then _
                    Example($nTreeViewSelected)
            ;MsgBox(64, "Info", "You Clicked TreeView: " & $nTreeViewSelected & @CRLF & "Which equals: " & $aTreeViewText[$nTreeViewSelected])
            $nTreeViewSelected = -1
    EndSwitch
WEnd

Here is how I wanted it to look... Any improvement suggestions ?

Share this post


Link to post
Share on other sites

1) Store your snippets to TXT file(s) and load them from there instead of hardcoded in EXE

2) Use only one GUI containing treeview on the left and Edit (for showing snippets) on the right sight of the GUI -> on click in treeview automatically show clicked snippet (no OK button needed)

Share this post


Link to post
Share on other sites

2) Use only one GUI containing treeview on the left and Edit (for showing snippets) on the right sight of the GUI -> on click in treeview automatically show clicked snippet (no OK button needed):

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

; JS - Define Array of Objects
Global $g_sString1 = 'let StoredBooks = [{' & @CRLF & _
        '        title: "bookOneTitle",' & @CRLF & _
        '        author: "bookOneAuthor",' & @CRLF & _
        '        isbn: "bookOneISBN"' & @CRLF & _
        '    },' & @CRLF & _
        '      ' & @CRLF & _
        '    {' & @CRLF & _
        '        title: "bookTwoTitle",' & @CRLF & _
        '        author: "bookTwoAuthor",' & @CRLF & _
        '        isbn: "bookTwoISBN"' & @CRLF & _
        '    },' & @CRLF & _
        '];'


; JS - Define class
Global $g_sString2 = 'class Book {' & @CRLF & _
        '    constructor(title, author, isbn) {' & @CRLF & _
        '        this.title = title;' & @CRLF & _
        '        this.author = author;' & @CRLF & _
        '        this.isbn = isbn;' & @CRLF & _
        '    }' & @CRLF & _
        '}'

; JS - forEach Loop
Global $g_sString3 = 'books.forEach(book => {' & @CRLF & _
'    UI.addBookToList(book);' & @CRLF & _
'})'

; JS - Define Object
Global $g_sString4 = 'myBookObject = new Book(bookinput, authorinput, isbninput);'

; JS - Template Literal
Global $g_sString5 = 'newTr.innerHTML = `' & @CRLF & _
'<td>${book.title}</td>' & @CRLF & _
'<td>${book.author}</td>' & @CRLF & _
'<td>${book.isbn}</td>' & @CRLF & _
'<td>X</td>' & @CRLF & _
'`;'

; HTML - Add Bootstrap
Global $g_sString6 = '<link rel="stylesheet" href="https://bootswatch.com/4/pulse/bootstrap.min.css">'

; HTML - Add Button
Global $g_sString7 = '<button class="add-book mt-5 btn btn-primary btn-block">Add Book</button>'

; HTML - Add Container Div
Global $g_sString8 = '<div class="container mt-4"></div>'

; HTML - Add Fontawesome
Global $g_sString9 = '<script src="https://kit.fontawesome.com/8e7a83d261.js" crossorigin="anonymous"></script>'

; HTML - Add a Form
Global $g_sString10 = '<form id="book-form">' & @CRLF & _
'' & @CRLF & _
'</form>'

; HTML - Add h1 heading
Global $g_sString11 = '<h1 class="display-4 text-center"><i class="fas fa-book-open text-primary"></i> My<span class="text-primary">Book</span>List' & @CRLF & _
'</h1>'

; HTML - Add InputBox
Global $g_sString12 = '<div class="form-group">' & @CRLF & _
'    <label for="title">Title</label>' & @CRLF & _
'    <input type="text" id="title" class="form-control">' & @CRLF & _
'</div>'

; HTML - Add a table
Global $g_sString13 = '<table class="table table-striped mt-5">' & @CRLF & _
'    <thead>' & @CRLF & _
'        <tr>' & @CRLF & _
'            <th>Title</th>' & @CRLF & _
'            <th>Author</th>' & @CRLF & _
'            <th>ISBN#</th>' & @CRLF & _
'            <th></th>' & @CRLF & _
'' & @CRLF & _
'        </tr>' & @CRLF & _
'    </thead>' & @CRLF & _
'    <tbody id="book-list"></tbody>' & @CRLF & _
'</table>'


#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\desktop\sumit\aform1.kxf
$Form1 = GUICreate("MyBookList Snippets", 800, 300)
$TreeView1 = GUICtrlCreateTreeView(24, 16, 305, 201)
$TreeView1_0 = GUICtrlCreateTreeViewItem("JS", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("HTML", $TreeView1)

$TreeView1_2 = GUICtrlCreateTreeViewItem("Define Array of Objects", $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Define class", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("forEach Loop", $TreeView1_0)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Define Object", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Template Literal", $TreeView1_0)

$TreeView1_7 = GUICtrlCreateTreeViewItem("Add Bootstrap", $TreeView1_1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Add Button", $TreeView1_1)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Add Container Div", $TreeView1_1)
$TreeView1_10 = GUICtrlCreateTreeViewItem("Add Fontawesome", $TreeView1_1)
$TreeView1_11 = GUICtrlCreateTreeViewItem("Add a Form", $TreeView1_1)
$TreeView1_12 = GUICtrlCreateTreeViewItem("Add h1 heading", $TreeView1_1)
$TreeView1_13 = GUICtrlCreateTreeViewItem("Add InputBox", $TreeView1_1)
$TreeView1_14 = GUICtrlCreateTreeViewItem("Add a table", $TreeView1_1)

$idEdit = GUICtrlCreateEdit("", 350, 2, 394, 268, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
$Button_Copy = GUICtrlCreateButton("Copy to Clipboard", 450, 275, 175, 17, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $TreeView1_0,$TreeView1_1
            ShowSnippet('')
        Case $TreeView1_2
            ShowSnippet($g_sString1)
        Case $TreeView1_3
            ShowSnippet($g_sString2)
        Case $TreeView1_4
            ShowSnippet($g_sString3)
        Case $TreeView1_5
            ShowSnippet($g_sString4)
        Case $TreeView1_6
            ShowSnippet($g_sString5)
        Case $TreeView1_7
            ShowSnippet($g_sString6)
        Case $TreeView1_8
            ShowSnippet($g_sString7)
        Case $TreeView1_9
            ShowSnippet($g_sString8)
        Case $TreeView1_10
            ShowSnippet($g_sString9)
        Case $TreeView1_11
            ShowSnippet($g_sString10)
        Case $TreeView1_12
            ShowSnippet($g_sString11)
        Case $TreeView1_13
            ShowSnippet($g_sString12)
        Case $TreeView1_14
            ShowSnippet($g_sString13)
        Case $Button_Copy
            ClipPut(_GUICtrlEdit_GetText($idEdit))
    EndSwitch
WEnd

Func ShowSnippet($g_sString)
    _GUICtrlEdit_SetText($idEdit, $g_sString)
EndFunc

 

Edited by Zedna

Share this post


Link to post
Share on other sites
2 hours ago, stephenf said:

I will use this snippet app to cheat in a phone interview...

Google searches during the interview are usually not reliable and keyboard makes the sound...

I don't think this is anything we want to support.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...