Jump to content

"Trigger something" whenever an EditBox content is updated


Faalamva
 Share

Recommended Posts

Hello, :bye:

I have an EditBox that I'm using as input for a search function :

$MySearch = GUICtrlCreateEdit(...)

Next to it, I have a button that I click once the occurrence to be searched has been entered in the editbox.

When clicking this button, a listbox displays the result of the search.

It works, but now I would like to improve this a bit. I want to avoid clicking on a button to launch the search (lazy me >_<).

I would like that whenever I type a new character (or delete a character) in the editbox, the search is triggered and the listbox is updated with the corresponding search result.

How could I do that ?

Thank you !

Link to comment
Share on other sites

Faalamva,

You can use this technique

#Include <GUIConstants.au3>
#Include <EditConstants.au3>
#Include <WindowsConstants.au3>
#Include <winapi.au3>

GUICreate('MyGUI', 300, 200)
$Input = GUICtrlCreateInput('', 10, 10, 280, 19)
$edit  = guictrlcreateedit("",10,40,100,20)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch BitAND($wParam, 0xFFFF)
        Case $Input
            Switch BitShift($wParam, 16)
                Case $EN_CHANGE
                    ConsoleWrite("from en_change > " & GUICtrlRead($Input) & @CR)
                Case $EN_update
                    ConsoleWrite("from en_update > " & GUICtrlRead($Input) & @CR)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
endfunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

Faalamva,

You might find the GUIRegisterMsg tutorial in the Wiki a good starting point to understand Windows message handling. ;)

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

 

Link to comment
Share on other sites

Thank you both ! :bye:

Melba23, your tutorial was very helpful. Without it, I would never have figured what kylomas cryptic code was doing ! :sorcerer:

I have adapted kylomas code to my own program, and it works like a charm.

However, I still have a few questions :

  • What is the difference between EN_CHANGE and EN_UPDATE ? I have kept only EN_CHANGE because whenever I updated my EditZone, both types or messages were called, which resulted in my handling function to be called twice...

  • I have commented the last line (the Return $GUI_RUNDEFMSG) because according to the tutorial, this can lead to unstable system behaviour. Not that my handling function may take a very long time to execute (less than 1 second), but from what I understand, this return instruction is simply an optimization, but not required, to avoid the whole system applications to check the notification that is supposed to concern only my AutoIt application anyway, am I right ?
Cheers ! Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva

- 1. Welcome the to world of MSDN - read about these messages (and all the others!) here! :D

- 2. You have misunderstood the tutorial. Returning $GUI_RUNDEFMSG just tells AutoIt to pass the message on as usual to Windows itself and any other controls that might require it. Returning 0 tells AutoIt not to do this (and so prevent the focus lines showing as in my UDF ;)). The system will become unstable if you spend too long (I use about 500ms as an absolute max) inside the handler without returning either of the above values. The tutorial shows how to use flags and dummy controls to run long complicated functions outside the handler, but triggered by it.

All clear now ? :)

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...