automotizator Posted February 28, 2013 Share Posted February 28, 2013 i want to create an edit (hEdit=GUICtrlCreateEdit() ) to which the user can only append text. i made it read-only and tried to fetch an event by $msg = GUIGetMsg() and then using a Select and case $msg=$hEdit. but that doesn't seem to work. ultimately i want to create an edit which serves as a terminal, the user can't delete the text that already exists in the edit, he can append text and delete his own text (as long it wasn't sent). thank you Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 1, 2013 Share Posted March 1, 2013 Example#include <GuiEdit.au3> #include <GuiConstantsEx.au3> Opt('MustDeclareVars', 1) $Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work _Main() Func _Main() Local $hEdit ; Create GUI GUICreate("Edit Append Text", 400, 300) $hEdit = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 2, 2, 394, 268) GUISetState() _GUICtrlEdit_AppendText($hEdit, @CRLF & "Append to the end?") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main You can even disable the control but setting the Edit to read-only has more better results Regards My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
automotizator Posted March 1, 2013 Author Share Posted March 1, 2013 but i want that the user will be able to append the text, and if he press backspace i'll ignore it. Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 1, 2013 Share Posted March 1, 2013 (edited) This should helpexpandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <WindowsConstants.au3> Global $s_Edit_Data = '' Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate('Example') GUICtrlCreateEdit('', 10, 20) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Register the WM_COMMAND to intercept when the value in the first input's value is changed. GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $iHiWord = _WinAPI_HiWord($wParam) ; Control identification code. Switch $iHiWord Case $EN_CHANGE ; When a change event is intercepted. Local $iLoWord = _WinAPI_LoWord($wParam) ; Control identifier. Local $iEdit_Len = StringLen(GUICtrlRead($iLoWord)) ;Lets check if deletion of characters was intercepted If $iEdit_Len >= StringLen($s_Edit_Data) Then $s_Edit_Data = GUICtrlRead($iLoWord) Else ;Get the data which has been replaced and substitute it in the insertion point GUICtrlSetData($iLoWord, StringMid( $s_Edit_Data, _GetCaretOffset($iLoWord) + 1, 1 ), 1) EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND ;Taken from the PredictText Library Func _GetCaretOffset($Edit_ID) Local $Edit_Handle = GUICtrlGetHandle($Edit_ID) Local $_LineIndex = _GUICtrlEdit_GetSel($Edit_Handle) If Not IsArray($_LineIndex) Then Return SetError(1, 0, -1) Switch $_LineIndex[0] Case $_LineIndex[1] Return SetExtended(0, $_LineIndex[1]) Case Else Local $_CoordMode = Opt('CaretCoordMode', 2) Local $_Caret = WinGetCaretPos() Local $_TextPos = _GUICtrlEdit_PosFromChar($Edit_Handle, $_LineIndex[0]) Opt('CaretCoordMode', $_CoordMode) Return SetExtended(1, $_TextPos[0] = $_Caret[0] And $_Caret[1] = $_TextPos[1]) EndSwitch EndFunc ;==>_GetCaretOffset Edited March 1, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 1, 2013 Share Posted March 1, 2013 (edited) This is a more better implementationexpandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Constants.au3> Global $wProcNew, $wProcOld, $VK_BACK = 0x8 Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate('Example') GUICtrlCreateEdit('', 10, 20) Local $hEdit = GUICtrlGetHandle(-1) _Edit_Block_BackSpace($hEdit) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) While GUIGetMsg() <> $GUI_EVENT_CLOSE Sleep(10) WEnd ;callback-deregister DllCallbackFree($wProcNew) ;Unsubclass _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, DllCallbackGetPtr($wProcOld)) ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _Edit_Block_BackSpace($hEdit) ;Ge the handle of the dll callback $wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr") ;subclass the edit control $wProcOld = _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) ;return the old procedure Return $wProcOld EndFunc ;==>_Edit_Block_BackSpace Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam) Switch $uiMsg Case $WM_CHAR Switch $wParam Case $VK_BACK Return 0 EndSwitch EndSwitch ;pass the unhandled messages to default WindowProc Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam) EndFunc ;==>_MyWindowProc Ask if you have any questions Edit : added the cleanup part as suggested by M23 Regards Edited March 2, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 1, 2013 Moderators Share Posted March 1, 2013 PhoenixXL,Nothing wrong with the concept at all - no need to have reported it. But in my opinion you should really delete the subclassed control and free the new WndProc with DllCallbackFree in the code before exiting the script - rather than leaving it up to AutoIt to do the cleanup work for you as at present. M23 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...
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