Jump to content

Highlight Inputbox contorl


Necromorph
 Share

Recommended Posts

GUICreate('test', 150, 150)
GUISetState()
$hCombo = GUICtrlCreateCombo("string", 25, 25, 100)
$hInput = GUICtrlCreateInput('<test>', 25, 50, 100)

While 1
     $msg = GUIGetMsg()
     Switch $msg
          Case $gui_event_close
               Exit
          Case $hInput
               GUICtrlSetState($hInput, $GUI_FOCUS)
     EndSwitch
WEnd

when i click in the guictrlcreateinput($hInput) i want it to highlight the the text in the control, above doesnt work, and i tried to replace the 'GUICtrlSetState($hInput, $GUI_FOCUS)' with 'Send(^a)' and that didn't work either. im sure this is easy to do, and im just missing something simple. thanks for any help.

Edited by redLabel
Link to comment
Share on other sites

The geeky way is to register WM_NOTIFY WM_COMMAND messages and select the text in your handler.

Another possibility is simply to watch for mouse clicks and see if the GUI is active and that control is in focus:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate('test', 150, 150)
$idCombo = GUICtrlCreateCombo("string", 25, 25, 100)
$idInput = GUICtrlCreateInput('<test>', 25, 50, 100)
$hInput = GUICtrlGetHandle($idInput)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $GUI_EVENT_PRIMARYUP
            If (WinGetHandle("[ACTIVE]", "") = $hGUI) And (ControlGetHandle($hGUI, "", ControlGetFocus($hGUI, "")) = $hInput) Then
                ConsoleWrite("!!! Focus on input !!!  Do something !!!" & @LF)
            EndIf
    EndSwitch
WEnd

;)

Edit: Corrected WM_COMMAND for WM_NOTIFY.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Actually, I should have said WM_COMMAND because an Input control is actually just a one-line EDIT class control. Watching for a WM_COMMAND message indicating the input has received focus looks like this:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>

$hGUI = GUICreate('test', 150, 150)
$idCombo = GUICtrlCreateCombo("string", 25, 25, 100)
$idInput = GUICtrlCreateInput('<test>', 25, 50, 100)
$hInput = GUICtrlGetHandle($idInput)
ConsoleWrite("$hGUI = " & $hGUI & "; $idInput = " & $idInput & "; $hInput = " & $hInput & @LF)
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
    EndSwitch
WEnd


Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode

    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    ConsoleWrite("$iIDFrom = " & $iIDFrom & "; $iCode = " & $iCode & @LF)
    Switch $iIDFrom
        Case $idInput
            Switch $iCode
                Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
                    ConsoleWrite("!!! Input has focus !!! Do something !!!" & @LF)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

I added some extra ConsoleWrite() lines to illustrate what it's doing.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...