Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted (edited)

This should help

#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 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.

Posted (edited)

This is a more better implementation

#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 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.

  • Moderators
Posted

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

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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...