stephenf Posted October 31, 2019 Share Posted October 31, 2019 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 31, 2019 Moderators Share Posted October 31, 2019 (edited) 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 October 31, 2019 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
stephenf Posted October 31, 2019 Author Share Posted October 31, 2019 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? Link to comment Share on other sites More sharing options...
Musashi Posted October 31, 2019 Share Posted October 31, 2019 (edited) 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 October 31, 2019 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
stephenf Posted October 31, 2019 Author Share Posted October 31, 2019 thanks, prefix line with ' and suffix with ' & @CRLF & _ i have a lot of data so is there a tool for it ? Link to comment Share on other sites More sharing options...
Nine Posted October 31, 2019 Share Posted October 31, 2019 10 minutes ago, stephenf said: i have a lot of data so is there a tool for it ? Depends, how much data we are talking about ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
stephenf Posted October 31, 2019 Author Share Posted October 31, 2019 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 Link to comment Share on other sites More sharing options...
Nine Posted October 31, 2019 Share Posted October 31, 2019 Hundreds, OK. And user, what he will do with that display ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
stephenf Posted October 31, 2019 Author Share Posted October 31, 2019 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 Link to comment Share on other sites More sharing options...
stephenf Posted October 31, 2019 Author Share Posted October 31, 2019 expandcollapse popup#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 ? Link to comment Share on other sites More sharing options...
Zedna Posted October 31, 2019 Share Posted October 31, 2019 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) stephenf 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted October 31, 2019 Share Posted October 31, 2019 (edited) 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): expandcollapse popup#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 October 31, 2019 by Zedna stephenf 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 31, 2019 Moderators Share Posted October 31, 2019 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. seadoggie01 and Musashi 2 "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! Link to comment Share on other sites More sharing options...
Recommended Posts