Jump to content
Sign in to follow this  
eskeptic

Am I Entering or Leaving Inputs?

Recommended Posts

eskeptic

Hello!

Ideally using GUIGetMsg(), I'd really like to distinguish between a user entering and leaving my input box (as it needs to be formatted when they tab or click away, but not when they enter it - otherwise the cursor is left at the wrong side of the text and they need to press shift+home before typing.)

Does anyone know of a way to get more information about the event that GUIGetMsg is saying occurred at the input box?

Thank you very much for the consideration!

- Gordon

Teach Critical Thought

Share this post


Link to post
Share on other sites
Melba23

eskeptic,

Welcome to the AutoIt forum. :mellow:

There are no doubt sexier ways to do this by looking for the various messages that Windows would pass around, but this "hobbyist" version sems to work quite well: :party:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

$fInput_Flag = False

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

$hInput = GUICtrlCreateInput("", 10, 10, 480, 20)
$hInput_Handle = GUICtrlGetHandle($hInput)

$hButton = GUICtrlCreateButton("Dummy", 10, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If _WinAPI_GetFocus() = $hInput_Handle Then
        If $fInput_Flag = False Then $fInput_Flag = True
    Else
        If $fInput_Flag = True Then
            $fInput_Flag = False

            MsgBox(0, "Alert", "The user has left the input" & @CRLF & "You can now format the content")

        EndIf
    EndIf
    
WEnd

What sort of formatting do you need to do to the input content? There might well be ways to do it on the fly. :P

M23


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
Mat

Ah Melba...

#include<WindowsConstants.au3> ; For $WM_COMMAND
#include<WinApi.au3> ; For _WinApi_HiWord and LoWord
#include<EditConstants.au3> ; for $EN_KILLFOCUS

; The variables are needed in functions too...
Global $hEdit1, $hEdit2

GUICreate("This is a test", 400, 200)

$hEdit1 = GUICtrlCreateInput("", 2, 2, 396, 20)
$hEdit2 = GUICtrlCreateInput("", 2, 24, 396, 20)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Register the message

While GUIGetMsg() <> -3 ; Wait for close
    Sleep(10)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    If _WinAPI_HiWord($iwParam) = $EN_KILLFOCUS Then ; An edit ctrl has lost focus
        Switch _WinAPI_LoWord($iwParam)
            Case $hEdit1
                ConsoleWrite("Edit 1 has lost focus" & @CRLF)
            Case $hEdit2
                ConsoleWrite("Edit 2 has lost focus" & @CRLF)
        EndSwitch
    EndIf

EndFunc   ;==>WM_COMMAND

Share this post


Link to post
Share on other sites
Melba23

Mat,

I did say there were sexier ways. :mellow:

M23


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
Mat

Mat,

I did say there were sexier ways. :P

M23

I'm not sure messages are sexy... Or at least - sexy isn't the right word to describe them :mellow:

Share this post


Link to post
Share on other sites
Melba23

Mat,

sexy isn't the right word to describe them

Must be a generational thing... :P

eskeptic,

If you do go with Mat's code, please read the warning in the Help file on the GUIRegisterMsg page about returning quickly from the message handler. If your formatting takes any time at all, you may need to think of using a flag in the While...WEnd loop and doing it there. ;)

But we are getting ahead of ourselves a bit - as I mentioned earlier, what is this formatting? :blink:

M23


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
eskeptic

Dear Melba & Mat.

I sincerely apologise for taking so long to get back to you, I didn't get any notifications that my thread had been replied to!

This project was put on hold until about a week ago and I'm still working out where I was up to with it. One of my comments was the URL to this thread.

The formatting was to standardise the input of construction site addresses, which uses a large, slow validation routine, so thank you very much for the headsup about this.

I might actually hold off on address standardisation until the user has dismissed the dialog after all.

Thank you both very much for all of your hard work! Matt's beautiful solution won't go unused though, it will be useful to be able to trap these events to recalculate some values in another part of this project.

- Gordon

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  

×