$Es_Number

  • Hallo.

    Ich habe eine inputbox mit dem style $ES_NUMBER

    und wenn man buchstaben eingibt kommt ja eine Sprechblase. Ich wollte fragen, wo ich den text aus der Sprechblase ändern kann, in der EditConstants.au3 ist nämlich der text nicht drin...

    Danke schonmal für eure hilfe^^

  • Ich bin mir nicht sicher ob es überhaupt geht... Du kannst dir das ganze aber auch selber schreiben ;).
    Z.B. Tastatureingaben überprüfen wenn der Fokus auf dem Control liegt, oder den Inhalt des Controls regelmäßig überprüfen und ggf. ändern.

  • Am einfachsten wäre wohl die Variante mit GUICtrlRead, GUICtrlSetData und einer Funktion die die ungültigen Zeichen herausfiltert.
    Beispiel mit RegExpReplace:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Test", 400, 400)
    $cInput = GUICtrlCreateInput("", 50, 50, 100, 25)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $sInputText = ""

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If GUICtrlRead($cInput) <> $sInputText Then
    $sInputText = StringRegExpReplace(GUICtrlRead($cInput), '[^0-9]', '')
    GUICtrlSetData($cInput, $sInputText)
    EndIf
    WEnd

    [/autoit]
  • Spoiler anzeigen
    [autoit]


    ;input edit control subclassing and ES_NUMBER style tooltip hijack
    ;convert numbers only tooltip error message of GUICtrlCreateInput() or GUICtrlCreateEdit() controls with $ES_NUMBER style
    ;to title, text and language of your choice.
    ;Author: rover
    #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GUIConstantsEX.au3>
    #include <Constants.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #Include <GuiToolTip.au3>
    #include <GuiEdit.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    #cs ; constants for icon in EditConstants.au3
    ; Edit Balloon Tool Tip Icons
    Global Const $TTI_NONE = 0
    Global Const $TTI_INFO = 1
    Global Const $TTI_WARNING = 2
    Global Const $TTI_ERROR = 3
    ; Vista Edit Balloon Tool Tip Icons
    Global Const $TTI_INFO_LARGE = 4
    Global Const $TTI_WARNING_LARGE = 5
    Global Const $TTI_ERROR_LARGE = 6
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui, $msg, $Input, $hInputUpDn, $wProcNew, $wProcOld

    [/autoit] [autoit][/autoit] [autoit]

    ; set tooltip title, text and icon
    Global $sInputTipTitle = "Unacceptable Character - In the language of your choice"
    Global $sInputTipText = "You can only type a number here."
    Global $iInputTipIcon = $TTI_ERROR

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("numbers")
    $Input = GUICtrlCreateInput("", 10, 10, 100, 20,$ES_NUMBER)
    $hInputUpDn = GUICtrlGetHandle(-1) ; get handle of input control for subclassing

    [/autoit] [autoit][/autoit] [autoit]

    ; subclass Input (Edit) control:
    $wProcNew = DllCallbackRegister("_NewWindowProc", "int", "hwnd;uint;wparam;lparam")
    $wProcOld = _WinAPI_SetWindowLong($hInputUpDn, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then _Exit()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    ;Delete callback function
    _WinAPI_SetWindowLong($hInputUpDn, $GWL_WNDPROC, $wProcOld)
    DllCallbackFree($wProcNew)
    GUIDelete($hGui)
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _NewWindowProc($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Local $tTitle, $tText, $tTT
    ;Local $nNotifyCode = BitShift($wparam, 16)
    ;Local $nID = BitAND($wparam, 0x0000FFFF)

    [/autoit] [autoit][/autoit] [autoit]

    Switch $Msg
    Case $EM_SHOWBALLOONTIP
    ;code taken from GUICtrlEdit_ShowBalloonTip()
    ;MSDN references
    ;EDITBALLOONTIP Structure: http://msdn.microsoft.com/en-us/library/bb775466(VS.85).aspx
    ;EM_SHOWBALLOONTIP Message: http://msdn.microsoft.com/en-us/library/bb761668(VS.85).aspx
    $tTitle = _WinAPI_MultiByteToWideChar($sInputTipTitle)
    $tText = _WinAPI_MultiByteToWideChar($sInputTipText)
    $tTT = DllStructCreate($tagEDITBALLOONTIP)
    DllStructSetData($tTT, "Size", DllStructGetSize($tTT))
    DllStructSetData($tTT, "Title", DllStructGetPtr($tTitle))
    DllStructSetData($tTT, "Text", DllStructGetPtr($tText))
    DllStructSetData($tTT, "Icon", $iInputTipIcon)
    ; pass EM_SHOWBALLOONTIP message to default WindowProc with pointer to a new EDITBALLOONTIP struct
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, DllStructGetPtr($tTT))
    ;Case $EM_HIDEBALLOONTIP ; not needed
    ;_GUICtrlEdit_HideBalloonTip($hWnd) ; not needed
    EndSwitch
    ; pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam)
    EndFunc ;==>_NewWindowProc

    [/autoit]
  • Du hast da viele Möglichkeiten um selbst zu prüfen was im Feld ist. Du kannst z.B. untenstehende Funktion immer aufrufen wenn Eingaben ins Feld gemacht werden, du kannst das Feld aber auch erst prüfen wenn das Formular abgeschickt wird also ein Button betätigt wird. Das ist geschmackssache.

    [autoit]


    Func checkinput()
    $getInput = GUICtrlRead ( $Input )

    [/autoit][autoit][/autoit][autoit]

    if StringIsDigit ( $getInput ) = 0 Then ; wenn der inhalt andere Zeichen als Ziffern enthält...
    ; hier kannste dann tun was du für nötig hälst, z.B. den User mit einer msgbox belästigen, eine Tray Sprechblase einblenden, oder einen spalshtext anzeigen
    ; befehle die du dir anschaun kannst:
    SplashTextOn()
    TrayTip()
    tooltip()
    ; oder du handelst ohne Hinweise in dem du alle Zeichen die keine Zahl sind sofort durch "" esetzt
    ; siehe stringregexpreplace Beispiel von name22

    [/autoit][autoit][/autoit][autoit]

    endif
    endfunc

    [/autoit]

    Einmal editiert, zuletzt von misterspeed (20. November 2010 um 17:33)

  • i2c Cool, das kannte ich noch nicht :). Aber in mein Script ist flexibler :P.
    Ach ja, den Tooltip habe ich ja ganz vergessen ^^...

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WinApi.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("Test", 400, 400)
    $cInput = GUICtrlCreateInput("", 50, 50, 100, 25)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $sInputText = ""

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If GUICtrlRead($cInput) <> $sInputText Then
    $sInputText = StringRegExpReplace(GUICtrlRead($cInput), '[^0-9]', '')
    GUICtrlSetData($cInput, $sInputText)

    [/autoit] [autoit][/autoit] [autoit]

    $aWinPos = WinGetPos($hGUI)
    $tClientRect = _WinAPI_GetClientRect($hGUI)
    ToolTip("Hier könnte ihre Werbung stehen :)", $aWinPos[0] + DllStructGetData($tClientRect, "Left") + 70, $aWinPos[1] + DllStructGetData($tClientRect, "Top") + 105, "Info", 2, 5)
    EndIf
    WEnd

    [/autoit]
  • Mahlzeit,

    wenn man die Frage wörtlich nimmt, ist das Skript von i2c die einzige Lösung. Seit XP gibt es dafür aber auch noch eine Variante:

    Spoiler anzeigen
    [autoit]

    ; input edit control subclassing and ES_NUMBER style tooltip hijack
    ; convert numbers only tooltip error message of GUICtrlCreateInput() or GUICtrlCreateEdit() controls with $ES_NUMBER style
    ; to title, text and language of your choice.
    ; Author: rover
    #include <GUIConstantsEX.au3>
    #include <EditConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui, $Msg, $Input, $hInput, $hSubclassProc, $pSubclassProc
    ; set tooltip title, text and icon
    Global $sInputTipTitle = "Unacceptable Character - In the language of your choice"
    Global $sInputTipText = "You can only type a number here."
    Global $iInputTipIcon = $TTI_ERROR

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("numbers")
    $Input = GUICtrlCreateInput("", 10, 10, 100, 20, $ES_NUMBER)

    [/autoit] [autoit][/autoit] [autoit]

    ; subclass Input (Edit) control: http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    $hSubclassProc = DllCallbackRegister("_InputSubclassProc", "BOOL", "HWND;UINT;WPARAM;LPARAM;UINT_PTR;DWORD_PTR")
    $pSubclassProc = DllCallbackGetPtr($hSubclassProc)
    _SetWindowSubclass($Input, $pSubclassProc)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then _Exit()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    ;Delete callback functions
    _RemoveWindowSubclass($Input, $pSubclassProc)
    DllCallbackFree($hSubclassProc)
    GUIDelete($hGui)
    Exit
    EndFunc ;==>_Exit

    [/autoit] [autoit][/autoit] [autoit]

    Func _InputSubclassProc($hWnd, $uMsg, $wParam, $lParam, $uIdSubclass, $dwRefData)
    #forceref $hWnd, $Msg, $wParam, $lParam, $uIdSubclass, $dwRefData
    ; MSDN references
    ; EDITBALLOONTIP Structure: http://msdn.microsoft.com/en-us/library/bb775466(VS.85).aspx
    ; EM_SHOWBALLOONTIP Message: http://msdn.microsoft.com/en-us/library/bb761668(VS.85).aspx
    Local Const $tagEDITBALLOONTIP = "dword Size;ptr Title;ptr Text;int Icon"
    Local $tTitle, $tText, $tTT
    If $uMsg = $EM_SHOWBALLOONTIP Then
    $tTitle = DllStructCreate("WCHAR [" & (StringLen($sInputTipTitle) + 1) & "]")
    DllStructSetData($tTitle, 1, $sInputTipTitle)
    $tText = DllStructCreate("WCHAR [" & (StringLen($sInputTipText) + 1) & "]")
    DllStructSetData($tText, 1, $sInputTipText)
    $tTT = DllStructCreate($tagEDITBALLOONTIP, $lParam)
    DllStructSetData($tTT, "Title", DllStructGetPtr($tTitle))
    DllStructSetData($tTT, "Text", DllStructGetPtr($tText))
    DllStructSetData($tTT, "Icon", $iInputTipIcon)
    EndIf
    ; pass all messages to the next SUBCLASSPROC or original window procedure
    Return _DefSubclassProc($hWnd, $uMsg, $wParam, $lParam)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_InputSubclassProc

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetWindowSubclass($hWnd, $pfnSubclass, $uIdSubclass = 0, $dwRefData = 0)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $aResult = DllCall("Comctl32.dll", "BOOL", "SetWindowSubclass", _
    "HWND", $hWnd, "PTR", $pfnSubclass, "UINT_PTR", $uIdSubclass, "DWORD_PTR", $dwRefData)
    If @error Then Return SetError(2, @error, False)
    Return $aResult[0]
    EndFunc ;==>_SetWindowSubclass

    [/autoit] [autoit][/autoit] [autoit]

    Func _RemoveWindowSubclass($hWnd, $pfnSubclass, $uIdSubclass = 0)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $aResult = DllCall("Comctl32.dll", "BOOL", "RemoveWindowSubclass", _
    "HWND", $hWnd, "PTR", $pfnSubclass, "UINT_PTR", $uIdSubclass)
    If @error Then Return SetError(2, @error, False)
    Return $aResult[0]
    EndFunc ;==>_RemoveWindowSubclass

    [/autoit] [autoit][/autoit] [autoit]

    Func _DefSubclassProc($hWnd, $uMsg, $wParam, $lParam)
    Local $aResult = DllCall("Comctl32.dll", "BOOL", "DefSubclassProc", _
    "HWND", $hWnd, "UINT", $uMsg, "WPARAM", $wParam, "LPARAM", $lParam)
    If @error Then Return SetError(2, @error, False)
    Return $aResult[0]
    EndFunc ;==>_DefSubclassProc

    [/autoit]


    Wenn man es trotzdem anders lösen will, sollte man das Skript nicht mit GuiCtrlRead() in der Mainloop quälen:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEX.au3>
    #include <EditConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $hGui, $Msg, $Input, $hInput, $hSubclassProc, $pSubclassProc

    [/autoit] [autoit][/autoit] [autoit]

    ; set tooltip title, text and icon
    Global $sInputTipTitle = "Unacceptable Character - In the language of your choice"
    Global $sInputTipText = "You can only type a number here."

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("numbers")
    $Input = GUICtrlCreateInput("", 10, 10, 100, 20) ; , $ES_NUMBER)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then _Exit()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    GUIDelete($hGui)
    Exit
    EndFunc ;==>_Exit

    [/autoit] [autoit][/autoit] [autoit]

    Func _WM_COMMAND($hWnd, $uMsg, $wParam, $lParam)
    Local $aCaret, $aPos, $Char, $Text, $Sel, $OCM
    If (_LoWord($wParam) = $Input) And (_HiWord($wParam) = $EN_UPDATE) Then
    $Text = GUICtrlRead($Input)
    If $Text And StringRegExp($Text, "\D") Then
    $OCM = Opt('CaretCoordMode', 0)
    $Sel = GUICtrlSendMsg($Input, $EM_GETSEL, 0, 0)
    $aCaret = WinGetCaretPos()
    $aPos = WinGetPos(GUICtrlGetHandle($Input))
    $Char = StringRegExpReplace($Text, "\d", "")
    ToolTip($sInputTipText, $aPos[0] + $aCaret[0], $aPos[1] + $aPos[3], $sInputTipTitle, 3, 1)
    $Text = StringRegExpReplace($Text, "\D", "")
    GUICtrlSetData($Input, $Text)
    GUICtrlSendMsg($Input, $EM_SETSEL, _LoWord($Sel) - 1, _HiWord($Sel) - 1)
    Opt('CaretCoordMode', $OCM)
    AdlibRegister("_KillToolTip", 1000)
    EndIf
    EndIf
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _LoWord($DWORD)
    Return BitAND($DWORD, 0xFFFF)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _HiWord($DWORD)
    Return BitShift($DWORD, 16)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _KillToolTip()
    AdlibUnRegister("_KillToolTip")
    ToolTip("")
    EndFunc

    [/autoit]
  • Ähhhm nicht nett :thumbdown:
    Hab ich aus dem Bot Forum....

    Zitat von raydok

    boah ich hatte schon angst. blödes autoit forum. da musst ich meine ganzen variabeln umschreiben damit keiner merkt das ich nen bot code :D gut das ihr wieder da seid^^

    Unfreundliche Grüsse....