Jump to content

Recommended Posts

Posted (edited)

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

 

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

Click "inside" a inputbox and if the inputbox has some text delete it

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

 

  • Moderators
Posted (edited)

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:

  Reveal hidden contents

 

Posted

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

 

  • Moderators
  • Solution
Posted

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:

  Reveal hidden contents

 

Posted (edited)

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.

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
  • Recently Browsing   0 members

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