[Func] InputBox étendue

Partagez des fonctions et des UDF AutoIt.
Règles du forum
.
Répondre
perfaram
Niveau 4
Niveau 4
Messages : 68
Enregistré le : jeu. 28 avr. 2011 11:40
Status : Hors ligne

[Func] InputBox étendue

#1

Message par perfaram »

Hello !
Il y a quelque temps j'avais écrit une fonction pour améliorer l'InputBox classique :

Code : Tout sélectionner

#include <WinAPI.au3>
#include <string.au3>

Opt("WinWaitDelay", 0)
$i=0

$shit=_InputBoxEx("Numéro de balise", "Entrez le numéro de téléphone de la balise :", True, False, Default, "Fermer", False)

Func _InputBoxEx($title, $text, $numbers=False, $pass=False, $pwdchar=Default, $cancel="Cancel", $allowcanceling=True, $parent="")
    Local Const $SC_CLOSE  = 0xF060
    Local Const $MF_GRAYED = 0x00000001
    Local Const $EM_SETPASSWORDCHAR=0xCC
    If $numbers=True Then
        $number=2 ;2 to lock to numbers, 0 to all
    Else
        $number=0
    EndIf
    $cancela=0
    If $allowcanceling=False Then
        $cancela=8 ;8 to grey, 0 to activate
    EndIf
    $pass=8 ;a for pass, 8 for normal
    If $pass=True Then
        $pass='a'
    EndIf
    If mod(StringLen($title), 2) = 0 Then
        $title=$title&" "
    EndIf
    $titlehex=StringTrimRight(StringReplace(StringRegExpReplace(StringTrimLeft(StringToBinary($title), 2),"(..)","\1 "), " ", "00"), 2)
    If not mod(StringLen($text), 2) = 0 Then
        $text=$text&" "
    EndIf
    $texthex=StringTrimRight(StringReplace(StringRegExpReplace(StringTrimLeft(StringToBinary($text), 2),"(..)","\1 "), " ", "00"), 2)
    If not mod(StringLen($text), 2) = 0 Then
        $cancel=$cancel&" "
    EndIf
    $cancelhex=StringTrimRight(StringReplace(StringRegExpReplace(StringTrimLeft(StringToBinary($cancel), 2),"(..)","\1 "), " ", "00"), 2)
    Global $bDialog="0x0100ffff0000000000000400480acc80040000000000a2005f0000000000"&$titlehex&"0000000800000000004d00530020005300680065006c006c00200044006c006700000000000000000000000000000002500700070093002c00ea030000ffff8200"&$texthex&"00000000000000000000000000"&$pass&"0"&$number&"081500700380093000c00e9030000ffff8100000000000000000000000000010001501000490032000e0001000000ffff80004f004b000000000000000000000000000000015"&$cancela&"5e00490032000e0002000000ffff8000"&$cancelhex&"0000000000"

    Global $tDialog = DllStructCreate("byte[" & BinaryLen($bDialog) & "]")
    DllStructSetData($tDialog, 1, $bDialog)

    Global $hDialogProc = DllCallbackRegister("_DialogProc", "int_ptr", "hwnd;dword;wparam;lparam")
    If StringLen($parent)<>0 Then
        Global $aCall = DllCall("user32.dll", "hwnd", "CreateDialogIndirectParamW", _
                "handle", 0, _
                "ptr", DllStructGetPtr($tDialog), _
                "hwnd", $parent, _
                "ptr", DllCallbackGetPtr($hDialogProc), _
                "lparam", 0)
    Else
        Global $aCall = DllCall("user32.dll", "hwnd", "CreateDialogIndirectParamW", _
                "handle", 0, _
                "ptr", DllStructGetPtr($tDialog), _
                "hwnd", 0, _
                "ptr", DllCallbackGetPtr($hDialogProc), _
                "lparam", 0)
    EndIf
    Global $hDialog = $aCall[0]

    If $allowcanceling=False Then
        Local $hMenu = DllCall('user32.dll', 'int', 'GetSystemMenu', 'hwnd', $hDialog, 'int', 0)
        DllCall('user32.dll', 'int', 'EnableMenuItem', 'hwnd', $hMenu[0], 'int', $SC_CLOSE, 'int', $MF_GRAYED)
    EndIf
    Global $hInput = ControlGetHandle($title, "", "[CLASS:Edit]")
    If Not $pwdchar=Default Then
        _SendMessage($hInput, $EM_SETPASSWORDCHAR, Asc($pwdchar))
    Else

    EndIf
    WinSetState($hDialog, 0, @SW_SHOW)
EndFunc

While 1
WEnd



Func _DialogProc($hWnd, $iMsg, $wParam, $lParam)
    Local Const $WM_COMMAND = 0x0111
    Local Const $WM_CLOSE = 0x0010
    Switch $iMsg
        Case $WM_CLOSE
            SetError(-1)
            DllCall("user32.dll", "int", "DestroyWindow", "hwnd", $hDialog)
        Case $WM_COMMAND
            Switch BitAND($wParam, 65535)
                Case 1
                    ConsoleWrite("'OK' clicked" & @CRLF)
                    $IBX_DATA=ControlGetText("Numéro de balise", "", _WinAPI_GetDlgCtrlID($hInput))
                    DllCall("user32.dll", "int", "DestroyWindow", "hwnd", $hDialog)
                    Global $IBX_DATA
                Case 2
                    SetError(-1)
                    DllCall("user32.dll", "int", "DestroyWindow", "hwnd", $hDialog)
            EndSwitch
    EndSwitch
EndFunc   ;==>_DialogProc
Ce n'est pas vraiment un UDF, car il faut l'adapter à chaque utilisation, mais c'est efficace et rapide.
Vous pouvez bloquer l'Input à des chiffres, ou bien la passer en mode password, et choisir le caractère à utiliser.
Pour récupérer les données, il suffit d'utiliser la fonction $IBX_DATA
C'est tout... :oops:
Répondre