Jump to content

QUESTION ABOUT $ES_NUMBER


kmetski
 Share

Recommended Posts

IS there a way to change the message that appears under input when i use the $ES_NUMBER exStyle

i mean this one Posted Image

Unacceptable Character ...... i wish i can translate it to my home language.

You could do something like this.

#include <editconstants.au3>
#include <guiconstantsEx.au3>
#include <windowsconstants.au3>
Global $lastOK = ''

Global $setTip = False
$hwnd = GUICreate("numbers")
$ip = GUICtrlCreateInput("", 10, 10, 100, 20);,$ES_NUMBER)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "My_WM_COMMAND")
Global $wp = WinGetPos($hwnd)
While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    
    If $setTip Then
        ToolTip("That's not a digit!", $wp[0] + 20, $wp[1] + 60, "ERROR", 3, 3);your own text here
        Sleep(2000)
        GUICtrlSetData($ip, $lastOK)
        ToolTip("")
        $setTip = False
    EndIf
WEnd

Func My_WM_COMMAND($hwnd, $imsg, $iwParam, $ilParam)

    Local $nNotifyCode = BitShift($iwParam, 16)
    Local $nID = BitAND($iwParam, 0x0000FFFF)
    Local $hCtrl = $ilParam
    
    If $nNotifyCode = $EN_CHANGE Then
        If GUICtrlGetHandle($ip) = $ilParam Then
            ToolTip("");in case another character typed before last tooltip removed
            Local $str = GUICtrlRead($ip)
            For $n = 1 To StringLen($str)
                Local $ch = StringMid($str, $n, 1)
                ;might want to include '.' here with numnbers, and +-?
                If Asc($ch) < Asc('0') Or Asc($ch) > Asc('9') Then
                    $setTip = True
                    ExitLoop
                EndIf
            Next
            If Not $setTip Then $lastOK = GUICtrlRead($ip)
        EndIf
        

        Return $GUI_RUNDEFMSG
    EndIf
    

EndFunc  ;==>My_WM_COMMAND

EDIT:Changed to allow for characters being inserted mid string.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

IS there a way to change the message that appears under input when i use the $ES_NUMBER exStyle

i mean this one Posted Image

Unacceptable Character ...... i wish i can translate it to my home language.

Greetings kmetski and Martin

I had a look at the tooltip function _GUICtrlEdit_ShowBalloonTip() in GuiEdit.au3

and came up with this demo.

just need someone to verify it will work with other languages as is

or if it needs some character conversion added.

Edit1: Minimum OS for EDITBALLOONTIP struct is WinXP.

you can also remove the code below 'Case $EM_SHOWBALLOONTIP' and add 'Return 0' to prevent a tooltip

or add a Beep(1000,5) or sound effect or use GUICtrlSendToDummy() to send a message to run a function.

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

Opt('MustDeclareVars', 1)

#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

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

; 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


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

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

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

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

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)
    
    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
Edited by rover

I see fascists...

Link to comment
Share on other sites

rover

Very nice example! Thank you for sharing! :P

Thanks Rasim :(

I forgot to mention that the minimum OS for EDITBALLOONTIP struct usage is WinXP.

I don't know about getting the handle to the tooltip to change its colour etc.

Winspector Spy shows creation and deletion messages for the tooltip.

unlike say a listview where the tooltip is created and only deleted when the control is.

Edit: the usual typos

Edited by rover

I see fascists...

Link to comment
Share on other sites

Wow, it's possible! Posted Image

Thanks rover!

Btw, i did an UDF to set only numbers for input control (_GUIInputSetOnlyNumbers() UDF), that's because $ES_NUMBER not fully preventing the insertion of non numbers characters (via pasting text for example)... and there you can set the tooltip text (and other params) as well.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Wow, it's possible! Posted Image

Thanks rover!

Btw, i did an UDF to set only numbers for input control (_GUIInputSetOnlyNumbers() UDF), that's because $ES_NUMBER not fully preventing the insertion of non numbers characters (via pasting text for example)... and there you can set the tooltip text (and other params) as well.

@MrCreatoR

just occurred to me, I posted a RegEx for negative numbers for your numbers only UDF

in a thread a while ago where I suggested to the OP in that thread to use your UDF.

I forgot about that.

here's the link: Input style with ES_NUMBER, negative number with ES_NUMBER?

@kmetski

have a look at MrCreatoR's UDF as well as my solution.

Cheers

I see fascists...

Link to comment
Share on other sites

Greetings kmetski and Martin

I had a look at the tooltip function _GUICtrlEdit_ShowBalloonTip() in GuiEdit.au3

and came up with this demo.

just need someone to verify it will work with other languages as is

or if it needs some character conversion added.

Edit1: Minimum OS for EDITBALLOONTIP struct is WinXP.

you can also remove the code below 'Case $EM_SHOWBALLOONTIP' and add 'Return 0' to prevent a tooltip

or add a Beep(1000,5) or sound effect or use GUICtrlSendToDummy() to send a message to run a function.

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

Opt('MustDeclareVars', 1)

#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

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

; 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


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

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

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

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

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)
    
    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
Thanks for the help all of you.

It works in PERFEKT IN BULGARIAN :P

Cheers

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