Sign in to follow this  
Followers 0
Sven

auto-overwrite content of input control?

5 posts in this topic

I've set up a control with

GUICtrlCreateInput("", $x, $y, $width, $height)
GUICtrlSetLimit(-1, 1)
 
Is there a way to erase the current content automatically when new data is entered? I know of GUICtrlSendMsg() and $EM_SETSEL, but this causes flickering in the input control when placed in a while loop.
 
Enter "1" in the input control, "1" stays. Try entering "2", and "1" is replaced by it.

Share this post


Link to post
Share on other sites



Logically only set the value when it's NOT what you are changing it to.  No flashing that way.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

; Johnmcloud - 2014
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Johnmcloud Test Code", 200, 70, -1, -1)
$sInput = GUICtrlCreateInput("", 10, 20, 180, 20)
GuiSetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $iIDFrom = $sInput And $iCode = $EN_CHANGE Then
       GUICtrlSetData($sInput, StringRight(GUICtrlRead($sInput),1))
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Edited by johnmcloud
1 person likes this

Share this post


Link to post
Share on other sites

Sven,

Fun little problem that one! :D

How about this as a solution: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>

; Create a flag
Global $iFocused = 0

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)
GUICtrlSetLimit($cInput, 1)

$cButton = GUICtrlCreateButton("Test", 10, 100, 80, 30)
GUICtrlSetState($cButton, $GUI_FOCUS)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $iFocused = 1 Then
        _GUICtrlEdit_SetSel($cInput, 0, -1)
        ; Set flag for focused and selected
        $iFocused = 2
    EndIf

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Switch _WinAPI_HiWord($wParam) ; Code
        Case $EN_SETFOCUS
            If Not $iFocused Then
                ; Set flag for initial focus
                $iFocused = 1
            EndIf
        Case $EN_KILLFOCUS
            ; Clear flag
            $iFocused = 0
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_COMMAND
Now you only select the content when you initially focus on the input. Any use? :huh:

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0