Jump to content

Inputbox focus/not focus


Go to solution Solved by Melba23,

Recommended Posts

Hi,

I want to make a func to clean one or more inputbox on click. My script:

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 242, 99)
$Input1 = GUICtrlCreateInput("Some text", 40, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 40, 50, 121, 21)
$btn1 = GUICtrlCreateButton("Initial focus", 180, 70)
GUICtrlSetState($btn1, $GUI_Focus)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    _Focus($Form1, $Input1, "")
WEnd

Func _Focus($hHandle, $Control, $Data)
    If ControlGetHandle($hHandle, "", ControlGetFocus($hHandle)) = GUICtrlGetHandle($Control) Then
        If GUICtrlRead($Control) <> "" Then
            GUICtrlSetData($Control, $Data)
            Do
            Until ControlGetHandle($hHandle, "", ControlGetFocus($hHandle)) <> GUICtrlGetHandle($Control)
        EndIf
    EndIf
EndFunc   ;==>_Focus

Work fine but has only one big problem, i can't close the GUI if the $Input1 is focused ( by Do Until )

How i can resolve? Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators

Terenz,

What exactly do you want to happen? Saying "clean one or more inputbox on click" is extremely vague - which input and what click where? :huh:

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

  • Moderators

Terenz,

Understood. Is this a "prompt" text to suggest what needs to be entered there or any old text that was already entered? :huh:

M23

Edited by Melba23
Typo

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

Any old text. I'll set an "default" text to the inputbox, if user click on inputbox it will automatically delete, then the user write something and click on another thing, if click again on inputbox the txt will be automaticcally delete etc.

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Moderators
  • Solution

Terenz,

Perhaps like this: ;)

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

Global $aInput[2]

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

$aInput[0] = GUICtrlCreateInput("Some text 1", 10, 10, 200, 20)
$aInput[1] = GUICtrlCreateInput("Some text 2", 10, 40, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            For $i = 0 To UBound($aInput) - 1
                If _WinAPI_GetFocus() = GUICtrlGetHandle($aInput[$i]) Then
                    GUICtrlSetData($aInput[$i], "")
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

Any use? :)

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

Was just doing something like this, when I found this post.
Thought I'd add an alternative.
 

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("GUI", 220, 100)

$iInput1 = GUICtrlCreateInput("Default", 10, 10, 200, 20)
$iInput2 = GUICtrlCreateInput("Default", 10, 40, 200, 20)
$iButton = GUICtrlCreateButton("OK",100,70)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            $aInfo = GUIGetCursorInfo()
            _ClearData($aInfo[4]) ; Pass control ID to function
        Case $iButton
            _ResetData()
    EndSwitch
WEnd

Func _ClearData(Const $Ctrl)
    If Not $Ctrl Or $Ctrl = $iButton Then ; Return if it's a control we do not want cleared
        Return
    EndIf
    GUICtrlSetData($Ctrl, "")
EndFunc

Func _ResetData()
    GUICtrlSetData($iInput1, "Input 1")
    GUICtrlSetData($iInput2, "Input 2")
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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...