Jump to content
Sign in to follow this  
oMBRa

input with focus

Recommended Posts

oMBRa

how to get the input control with keyboard focus?

Share this post


Link to post
Share on other sites
Valuater

GUICtrlSetState ( controlID, state )

See help

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
oMBRa

yes I know that, but getting the state of a input control with keyboard focus, and one with no focus returns the same...

quick example:

#include <GUIConstantsEx.au3>
$GUI = GUICreate('', 500, 500, -1, -1)
$edit1 = GUICtrlCreateInput('', 100, 100, 100, 30)
$edit2 = GUICtrlCreateInput('', 100, 150, 100, 30)
GUISetState()

Do
$StateEdit1 = GUICtrlGetState($edit1)
$StateEdit2 = GUICtrlGetState($edit2)
    ToolTip($StateEdit1 & @CRLF & $StateEdit2)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites
Jos

you mean ?

ControlGetFocus

--------------------------------------------------------------------------------

Returns the ControlRef# of the control that has keyboard focus within a specified window.

ControlGetFocus ( "title" [, "text"] )


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
oMBRa

yes Thx

Share this post


Link to post
Share on other sites
charvi

you mean ?

ControlGetFocus ( "title" [, "text"] )

Yes, I have a problem here too. I have an application that uses ControlGetFocus to display a comment line when the focus is on a particular keyboard input field.

The problem is that it returns "Edit1", "Edit2" etc, instead of the Handle itself. This means that, if later I would like to insert a new input field, I need to update the "Edit#" too.

So, my question is: can I retrieve the Control Handle number when the user is on an input field?

Func _SubTitle_($h_Win, $ah_SubTitle, ByRef $h_CgfCurrent);, $ai_Msg, $ah_Input)
    Local $h_Cgf
    $h_Cgf = ControlGetFocus($h_Win)
    If $h_Cgf = $h_CgfCurrent Then Return; otherwise the SubTitle will flash
    Switch $h_Cgf
        Case "Edit1"
            GUICtrlSetData($ah_SubTitle[1], "Enter Customer Number, or press [+] to get a free number")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit2"
            GUICtrlSetData($ah_SubTitle[1], "Enter Company Name")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit3"
            GUICtrlSetData($ah_SubTitle[1], "Enter Contact Person")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit4"
            GUICtrlSetData($ah_SubTitle[1], "Enter Address Line 1")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit5"
            GUICtrlSetData($ah_SubTitle[1], "Enter Address Line 2")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit6"
            GUICtrlSetData($ah_SubTitle[1], "Enter Country Code")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit7"
            GUICtrlSetData($ah_SubTitle[1], "Enter Postal Code")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit8"
            GUICtrlSetData($ah_SubTitle[1], "Enter Location")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit9"
            GUICtrlSetData($ah_SubTitle[1], "Enter GSM or Phone Number 1")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit10"
            GUICtrlSetData($ah_SubTitle[1], "Enter GSM or Phone Number 2")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit11"
            GUICtrlSetData($ah_SubTitle[1], "Enter GSM or Phone Number 3")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit12"
            GUICtrlSetData($ah_SubTitle[1], "Enter Fax Number")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit13"
            GUICtrlSetData($ah_SubTitle[1], "Enter E-Mail Address 1")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit14"
            GUICtrlSetData($ah_SubTitle[1], "Enter E-Mail Address 2")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case "Edit15"
            GUICtrlSetData($ah_SubTitle[1], "Enter WebSite HomePage")
            GUICtrlSetData($ah_SubTitle[2], "")
        Case Else
            GUICtrlSetData($ah_SubTitle[1], "")
            GUICtrlSetData($ah_SubTitle[2], "")
    ;EndCase
    EndSwitch
    $h_CgfCurrent = $h_Cgf
EndFunc

Share this post


Link to post
Share on other sites
oMBRa

ofc:

ControlGetHandle($GUIHANDLE, '', ControlGetFocus($GUIHANDLE))

Share this post


Link to post
Share on other sites
Jos

Yes, I have a problem here too. I have an application that uses ControlGetFocus to display a comment line when the focus is on a particular keyboard input field.

The problem is that it returns "Edit1", "Edit2" etc, instead of the Handle itself. This means that, if later I would like to insert a new input field, I need to update the "Edit#" too.

So, my question is: can I retrieve the Control Handle number when the user is on an input field?

Does the Edit?? change when you add the new field at the end of the list of GUICtrlCreate(s) ?

You would have to do this anyways or else in internal handle would also change.

ofc:

ControlGetHandle($GUIHANDLE, '', ControlGetFocus($GUIHANDLE))
Don't think this returns the internal GUI Handle which is really a sequence number returned with GuiCtrlCreateEdit().

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
rover

@charvi

oMBRa posted the first item of my reply so here's the second half

instead of polling for edit control with focus use registered messages

a reworked example from my post in this thread

Identify Control that contains cursor BEFORE button is pressed

Edit: changed consolewrite "0x" & Hex(GUICtrlRead($Dummy) to HWnd(GUICtrlRead($Dummy)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Global $cLastInputFocus = 0; last Edit control ID buffer
Global $iBuffer, $Dummy
_EditFocus()

Func _EditFocus()

    $frmGlobalDefaults = GUICreate("Edit Focus", 400, 300)
    $btnBrowse = GUICtrlCreateButton("&Browse", 240, 24, 60, 248, 0)
    $inptbxRegFileName = GUICtrlCreateInput("inptbxRegFileName " & $btnBrowse+1, 20, 24, 200, 21)
    $inptbxDirBase = GUICtrlCreateInput("inptbxDirBase " & $btnBrowse+2, 20, 80, 200, 21)
    $inptbxDirAlbum = GUICtrlCreateInput("inptbxDirAlbum " & $btnBrowse+3, 20, 136, 200, 21)
    $inptbxDirSettings = GUICtrlCreateInput("inptbxDirSettings " & $btnBrowse+4, 20, 192, 200, 21)
    $inptbxDirHP = GUICtrlCreateInput("inptbxDirHP " & $btnBrowse+5, 20, 248, 200, 21)

    $Dummy = GUICtrlCreateDummy()

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUISetState()

    While 1
;~      If $iBuffer <> $cLastInputFocus Then
;~          ConsoleWrite("-Edit control ID with focus: " & $cLastInputFocus & @CRLF & @CRLF)
;~          $iBuffer = $cLastInputFocus
;~      EndIf
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnBrowse
                ;If $cLastInputFocus Then
                    ;ConsoleWrite("-cursor no longer in Input control: " & $cLastInputFocus & @CRLF)
                ;EndIf
            Case $Dummy
                ConsoleWrite('!Previous edit control hWnd    = ' &  HWnd(GUICtrlRead($Dummy)) & @crlf)
        EndSwitch
    WEnd

EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)

    Switch $nNotifyCode; Edit control event messages only
        Case $EN_SETFOCUS; Edit (Input) control has focus
            ;If $cLastInputFocus Then ConsoleWrite("-You previously had the cursor in Input control ID: " & $cLastInputFocus & @crlf)
            ConsoleWrite(@CRLF & '+Control ID      = ' & $nID & @crlf); control ID of Input edit control with focus
            ConsoleWrite('+Control hWnd    = ' & $lParam & @crlf); handle of Input edit control with focus
            ConsoleWrite('+ControlGetFocus = ' & ControlGetFocus($hWnd) & @crlf); the ClassNameNN of control 'Edit#'
            ;GUICtrlSendToDummy($Dummy, $lParam)
;~          If $nID <> $cLastInputFocus Then
;~              $cLastInputFocus = $nID
;~          EndIf
        Case $EN_KILLFOCUS; Edit (Input) control lost focus
           ; $cLastInputFocus = -1
            If StringInStr(ControlGetFocus($hWnd), "Edit") = 0 Then
                GUICtrlSendToDummy($Dummy, -1)
            Else
                GUICtrlSendToDummy($Dummy, $lParam)
            EndIf
            ;use to reset comment once edit controls no longer have focus
            ;ConsoleWrite('+$nID = ' & $nID & @crlf); control ID of previous Input edit control with focus
            ;ConsoleWrite('+ControlGetFocus = ' & ControlGetFocus($hWnd) & @crlf); the ClassNameNN of control 'Edit#'
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
charvi

oMBRa, Jos and Rover, thank you all for your reply.

Using the WM_COMMAND example from Rover will solve my issue.

Cheers, charvi

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  

×