ahha Posted March 1, 2023 Share Posted March 1, 2023 I'm trying to get Word Wrap under (Format) to work in the program below and feel like the blind squirrel not finding the nut. The program has a built in string for testing and will accept drag and drop. I've tried combinations of GUICtrlSetStyle that I thought would work and searched the forum and nada. This blind squirrel needs some help. expandcollapse popup#AutoIt3Wrapper_run_debug_mode=Y ;use this to debug in console window <--- LOOK Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration ;Hack for Word Wrap v3c.au3 #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <WindowsConstants.au3> Global $data = "", $file = "", $hGUI, $cEdit $hGUI = GUICreate("GUI Window", 920, 570, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX), BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ;handle $cEdit = GUICtrlCreateEdit("", 10, 10, 800, 455, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_NOHIDESEL)) ;control ID ;normally I have the $cEdit occupying the full size of the client region of $hGUI - border here to make sure we can see what's happening GUICtrlSetState($cEdit, $GUI_DROPACCEPTED) ;allow drag and drop GUICtrlSetFont($cEdit, 10, 400, 0, "Courier New") ;change default font GUISetState(@SW_SHOW, $hGUI) ;Format Menu Local $idFormatMenu = GUICtrlCreateMenu("F&ormat") ;Create the Format menu. Underline o when Alt is pressed. ;sub-menus Local $idFormatMenu_WordWrap = GUICtrlCreateMenuItem("&Word Wrap" &@TAB& "", $idFormatMenu) ;Create the "Word Wrap" menu item. Underline W when Alt is pressed. $data = "8e4t9qn0rgup3qrelm0b9emp9061abjm9n9tyv44m2edpbfj1svwulpe02dcwjdqcyyajru4dfyfk8w0anlk86t335qcoeekm2baxv40nzqs9ka65lo09su8omqaw7" ;for testing _GUICtrlEdit_SetText($cEdit, $data) GUISetState(@SW_SHOW) ;display the GUI Local $nMsg While 1 $nMsg = GUIGetMsg() If $nMsg <> 0 Then Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idFormatMenu_WordWrap _WordWrap() Case $GUI_EVENT_DROPPED _GUICtrlEdit_SetText($cEdit, FileRead(@GUI_DragFile)) ;read and set the data to be displayed EndSwitch EndIf WEnd Func _WordWrap() If BitAND(GUICtrlRead($idFormatMenu_WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then ;turn off Word Wrap GUICtrlSetState($idFormatMenu_WordWrap, $GUI_UNCHECKED) ;uncheck Word Wrap GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_NOHIDESEL)) ;<- original style Else GUICtrlSetState($idFormatMenu_WordWrap, $GUI_CHECKED) ;turn on Word Wrap and show checked ;I can't seem to find the correct combination to get the text to Word Wrap. Check the forum and tried these. ;GUICtrlSetStyle($cEdit, $GUI_SS_DEFAULT_EDIT) ;does not work ;GUICtrlSetStyle($cEdit, $ES_AUTOVSCROLL) ;does not work ;GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) ;does not work but gets rid of hscroll till resize GUI Window then hscroll reappears ;GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) ;does not work and gets rid of vscroll and hscroll ;GUICtrlSetStyle($cEdit, $ES_AUTOVSCROLL) ;does not work ;GUICtrlSetStyle($cEdit, -1) ;does not work ;GUICtrlSetStyle($cEdit, BitOR($ES_WANTRETURN, $WS_VSCROLL)) ;does not work ;GUICtrlSetStyle($cEdit, $GUI_SS_DEFAULT_EDIT) ;does not work ;GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_NOHIDESEL)) ;does not work ;GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_NOHIDESEL)) ;does not work and as soon as resize GUI the hscroll reappears GUICtrlSetStyle($cEdit, BitOR($GUI_SS_DEFAULT_EDIT, $WS_VSCROLL)) ;does not work ;This blind squirrel needs help EndIf EndFunc Link to comment Share on other sites More sharing options...
ioa747 Posted March 1, 2023 Share Posted March 1, 2023 take a look maybe help I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted March 1, 2023 Share Posted March 1, 2023 (edited) ... or try to remove the $WS_HSCROLL Edited March 1, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ahha Posted March 1, 2023 Author Share Posted March 1, 2023 @ioa747I tried a bunch of combinations that had $WS_HSCROLL removed (see the ones I tried). It did not result in Word Wrap working. I'll look at @LarsJbut I doubt it will work as it appears to get into Dll stuctures and very complicatdd. Link to comment Share on other sites More sharing options...
ioa747 Posted March 1, 2023 Share Posted March 1, 2023 (edited) here work #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <WindowsConstants.au3> Global $data = "", $file = "", $hGUI, $cEdit $hGUI = GUICreate("GUI Window", 920, 570, -1, -1, $WS_OVERLAPPEDWINDOW, BitOR($WS_EX_CLIENTEDGE, $WS_EX_ACCEPTFILES)) ;handle $cEdit = GUICtrlCreateEdit("", 10, 10, 800, 455, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_NOHIDESEL)) ;control ID GUICtrlSetState($cEdit, $GUI_DROPACCEPTED) ;allow drag and drop GUICtrlSetFont($cEdit, 10, 400, 0, "Courier New") ;change default font GUISetState(@SW_SHOW, $hGUI) $data = "8e4t9qn0rgup3qrelm0b9emp9061abjm9n9tyv44m2edpbfj1svwulpe02dcwjdqcyyajru4dfyfk8w0anlk86t335qcoeekm2baxv40nzqs9ka65lo09su8omqaw7" ;for testing GUICtrlSetData($cEdit, $data) GUISetState(@SW_SHOW) ;display the GUI Local $nMsg While 1 $nMsg = GUIGetMsg() If $nMsg <> 0 Then Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED EndSwitch EndIf WEnd Edited March 1, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ahha Posted March 1, 2023 Author Share Posted March 1, 2023 (edited) @ioa747 Thanks for your input. However it's not working in the program. Look at line 59 and uncomment it. ;GUICtrlSetStyle($cEdit, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_NOHIDESEL)) It's the same as your line and it does not work in the program. BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_NOHIDESEL)) This is my frustration, why does it not work? As you can see I've tried a lot of combinations and not found the correct one yet. Yours was used in a GUICtrlCreateEdit not in a GUICtrlSetStyle. Any other suggestions are most welcome. Edited March 1, 2023 by ahha Link to comment Share on other sites More sharing options...
Solution pixelsearch Posted March 1, 2023 Solution Share Posted March 1, 2023 (edited) Hi everybody It seems tricky. Have you already seen any AutoIt script where OP's need is solved with a simple control style (added or removed) after the Edit control has been created ? Even MS write this on its msdn page, topic Edit Control Styles After the control has been created, these styles cannot be modified, except as noted (...) It seems frustrating because when we open NotePad, menu Format, option Word Wrap, then we can easily check/unchech the Word wrap option and the Edit control in NotePad reacts immediately & correctly. But did you notice the following ? If you use "AutoIt Window Info Tool" to check the handle of NotePad's Edit control, before and after you checked the Word Wrap option... the handle CHANGES each time ! (we're talking here of NotePad Edit control handle, not of NotePad window handle) It means that even MS deletes the Edit Control and recreates it immediately, with the new appropriate style, when the user checks/unchecks Word Wrap in NotePad @ahha I tried the same way to solve it in the script below, it seems to work fine : expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <String.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration Global $g_hGUI, $g_idEdit $g_hGUI = GUICreate("GUI Window", 920, 570, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_ACCEPTFILES) ;handle _EditRecreate(False) ;False = no word wrap (keep it False here, to match with the unchecked Menu item "Word Wrap") ;Format Menu Local $idFormatMenu = GUICtrlCreateMenu("F&ormat") ;Create the Format menu. Underline o when Alt is pressed. ;sub-menus Local $idFormatMenu_WordWrap = GUICtrlCreateMenuItem("&Word Wrap" &@TAB& "", $idFormatMenu) ;Create the "Word Wrap" menu item. Underline W when Alt is pressed. GUISetState(@SW_SHOW, $g_hGUI) ;display the GUI _GUICtrlEdit_SetSel($g_idEdit, -1, 0) ;deselects only when placed AFTER GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idFormatMenu_WordWrap _WordWrap() Case $GUI_EVENT_DROPPED _GUICtrlEdit_SetText($g_idEdit, FileRead(@GUI_DragFile)) ;read and set the data to be displayed EndSwitch WEnd ;============================= Func _WordWrap() If BitAND(GUICtrlRead($idFormatMenu_WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then ;turn off Word Wrap _EditRecreate(False) ; False = no word wrap GUICtrlSetState($idFormatMenu_WordWrap, $GUI_UNCHECKED) ;uncheck Word Wrap Else ;turn on Word Wrap _EditRecreate(True) ; True = word wrap GUICtrlSetState($idFormatMenu_WordWrap, $GUI_CHECKED) ;turn on Word Wrap and show checked EndIf EndFunc ;============================= Func _EditRecreate($bWordWrap) Local $idEdit_Old = $g_idEdit ;0 at first passage If $idEdit_Old Then Local $aPos = ControlGetPos($g_hGUI, "", $idEdit_Old) Else ;1st passage Local $aPos[4] = [10, 10, 800, 455] EndIf $g_idEdit = GUICtrlCreateEdit("", $aPos[0], $aPos[1], $aPos[2], $aPos[3], ($bWordWrap _ ? BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL) _ : -1)) ;control ID GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;allow drag and drop GUICtrlSetFont(-1, 10, 400, 0, "Courier New") ;change default font If $idEdit_Old Then _GUICtrlEdit_SetText($g_idEdit, GUICtrlRead($idEdit_Old)) Local $aSel = _GUICtrlEdit_GetSel($idEdit_Old) GUICtrlDelete($idEdit_Old) _GUICtrlEdit_SetSel($g_idEdit, $aSel[0], $aSel[1]) Else ;1st passage _GUICtrlEdit_SetText($g_idEdit, _StringRepeat("1234567890", 20)) EndIf EndFunc Hope it helps Edited March 1, 2023 by pixelsearch As the GUI is resizable, the coords of the Edit Control need to be checked just before recreating it . Also, take care of an eventual selection ahha, t0nZ, Dan_555 and 1 other 3 1 Link to comment Share on other sites More sharing options...
Dan_555 Posted March 1, 2023 Share Posted March 1, 2023 Yes, in my notememopad script i have had to delete and recreate it as well. here is a snippet, (reacting from the tray menu item ): Case $idWW $WordWrap = Mod($WordWrap + 1, 2) _TrayCheckUncheck($idWW, $WordWrap) If $WordWrap = 0 Then $ww = -1 Else $ww = BitOR($WS_VSCROLL, $ES_AUTOVSCROLL) EndIf IniWrite($inifile, "OPTIONS", "Wordwrap", $WordWrap) $tmp = GUICtrlRead($Edit1) GUICtrlDelete($Edit1) $Edit1 = GUICtrlCreateEdit("", 2, 2, 500, 444, $ww) _GUICtrlEdit_SetLimitText($Edit1, 20000000) GetIniFont($Edit1) GUICtrlSetData($Edit1, $tmp) $tmp = "" pixelsearch and ahha 2 Some of my script sourcecode Link to comment Share on other sites More sharing options...
ahha Posted March 1, 2023 Author Share Posted March 1, 2023 @pixelsearchThank you so much! That explains it all and why my futile attempts failed to work. I did not previously see the Notepad handle change, now I do. It all makes sense now (and I guess I can halt one of my computers that is trying every style from 0 to about 4 billion to brute force search for a style that word wraps 🙂 I do note that even Notepad does not keep a current selection when it changes Word Wrap on/off. This blind squirrel would never have found the nut without your help. Perhaps a mention of this issue in the GUICtrlSetStyle help page would help others. Thanks again. pixelsearch 1 Link to comment Share on other sites More sharing options...
ahha Posted March 1, 2023 Author Share Posted March 1, 2023 @Dan_555Thanks for also noting this issue and how to get around it. Link to comment Share on other sites More sharing options...
pixelsearch Posted March 1, 2023 Share Posted March 1, 2023 (edited) 45 minutes ago, ahha said: That explains it all and why my futile attempts failed to work. It's not futile at all, you did your best to achieve your goal, trying it in many ways. I like this approach and tend to do same, trying and retrying, then asking for help on the Forum when you feel that you'll never find the answer by yourself. 45 minutes ago, ahha said: I do note that even Notepad does not keep a current selection when it changes Word Wrap on/off. Keeping the current selection seems doable at any stage, we started to discuss it in this post. I just amended my script above to take care of an eventual selection, no matter the word wrap is active or not. Good luck Edited March 1, 2023 by pixelsearch typo ahha 1 Link to comment Share on other sites More sharing options...
ahha Posted March 1, 2023 Author Share Posted March 1, 2023 @pixelsearchNicely done on the selection 😉 Link to comment Share on other sites More sharing options...
pixelsearch Posted March 1, 2023 Share Posted March 1, 2023 (edited) Thx ahha. Using the preceding script, just a test on word wrap, space and non-break space, for fun Edited March 1, 2023 by pixelsearch ahha 1 Link to comment Share on other sites More sharing options...
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