littlebigman Posted April 2, 2023 Posted April 2, 2023 Hello, I'm experimenting with the Edit control, and am stuck with two issues: 1. How to get the widget to display the text within the box, so the user doesn't need to scroll horizontally to read the whole line? 2. Is there a way to provide a search function, ie. CTRL+F? Thank you. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 689, 540, 286, 121) $Edit1 = GUICtrlCreateEdit("", 0, 0, 688, 539, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY,$ES_MULTILINE)) GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $hFileOpen = FileOpen("LoremIpsum.txt", $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Exit EndIf Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) GUICtrlSetData($Edit1, $sFileRead) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
Solution Dan_555 Posted April 2, 2023 Solution Posted April 2, 2023 It is called "WordWrapping" and here is an example of how to do both requests: expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <GuiEdit.au3> #include <Array.au3> Global $SearchTerm = "", $searchGuiOpen = 0, $searchInEditStartingPos=1 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 689, 540, 286, 121) Global $Edit1 = GUICtrlCreateEdit("", 0, 25, 688, 514, BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $btnSearch = GUICtrlCreateButton("Search", 2, 2, 50, 22) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $hFileOpen = FileOpen("LoremIpsum.txt", $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Exit EndIf Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) _GUICtrlEdit_SetText($Edit1, $sFileRead) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnSearch If SearchGui() = 1 Then SearchInEdit ($Edit1,$SearchTerm,$searchInEditStartingPos) EndIf EndSwitch WEnd Func SearchInEdit($hEdit,$txt,$startingPos) ConsoleWrite( $txt & @CRLF) Local $tmp=GUICtrlRead ($hEdit) Local $SearchinEditFoundStart=StringInStr($tmp,$txt,0,1,$startingPos)-1 IF @error=0 and $SearchinEditFoundStart>0 Then $SearchinEditFoundEnd=$SearchinEditFoundStart+StringLen($txt) ControlFocus ($Form1,"",$edit1) _GUICtrlEdit_SetSel($Edit1,$SearchinEditFoundStart,$SearchinEditFoundEnd) $searchInEditStartingPos=$SearchinEditFoundEnd ConsoleWrite( $SearchinEditFoundStart & " / " & $SearchinEditFoundEnd & @CRLF) Else $searchInEditStartingPos=1 EndIf EndFunc Func SearchGui() Local $TMP = 0 #Region ### START Koda GUI section ### Form= $SearchForm1 = GUICreate("Form1", 217, 81, 192, 124, BitOR($WS_POPUP, $ws_caption, $WS_DLGFRAME)) $Input1 = GUICtrlCreateInput($SearchTerm, 7, 22, 206, 21) $Label1 = GUICtrlCreateLabel("Search for", 7, 2, 53, 17) $Button1 = GUICtrlCreateButton("Search", 7, 53, 53, 23) $Button2 = GUICtrlCreateButton("Cancel", 161, 52, 51, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 $SearchTerm = GUICtrlRead($Input1) If StringLen($SearchTerm) > 0 Then $TMP = 1 ExitLoop EndIf Case $Button2 ExitLoop EndSwitch WEnd GUIDelete($SearchForm1) Return $TMP EndFunc ;==>SearchGui Some of my script sourcecode
littlebigman Posted April 2, 2023 Author Posted April 2, 2023 (edited) Thanks much. As a way to catch CTRL+F to display the search window and do away with a pushbutton in the main window, should I use HotKeySet() ? -- Edit : GUISetAccelerators() looks like a better alternative to add in the GUI event loop. The MsgBox isn't displayed: #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 689, 540, 286, 121) $Edit1 = GUICtrlCreateEdit("", 0, 0, 688, 539,BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_READONLY)) $IdSearch = GUICtrlCreateDummy() Local $aAccelKeys[2][2] = [["^f", $IdSearch]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $hFileOpen = FileOpen("LoremIpsum.txt", $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Exit EndIf Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) GUICtrlSetData($Edit1, $sFileRead) While True $nMsg = GUIGetMsg() Switch $nMsg Case $IdSearch MsgBox($MB_OK, "Search", "In search") ;~ If SearchGui() = 1 Then ;~ SearchInEdit ($Edit1,$SearchTerm,$searchInEditStartingPos) ;~ EndIf Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd --- Done :-) Thanks for the help. #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 689, 540, 286, 121) $Edit1 = GUICtrlCreateEdit("", 0, 0, 688, 539,BitOR($ES_WANTRETURN, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_READONLY)) Local $aAccelKeys[1][2] = [["^f", $Edit1]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $hFileOpen = FileOpen("LoremIpsum.txt", $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Exit EndIf Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) GUICtrlSetData($Edit1, $sFileRead) While True $nMsg = GUIGetMsg() Switch $nMsg Case $Edit1 MsgBox($MB_OK, "Search", "In search") Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited April 2, 2023 by littlebigman
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now