Jump to content

Custom_InputBox()!


MrCreatoR
 Share

Recommended Posts

Hi to all!

Custom (GUI-Based) version of the Build-in function InputBox():

;===============================================================================
;
; Function Name:    _InputBox()
; Description:      Custom InputBox Function (GUI based).
; Parameter(s):     $Title - The title of the Input Box.
;                   $Prmt - A message to the user indicating what kind of input is expected.
;                   $sDef - [Optional] The value that the input box starts with.
;                   $hWnd - [Optional] Window handle of the parent.
;                   $IsPass - [optional] If <> 0 Then typed characters will be replaced with password characters (*).
;                   $IsDig - [optional] If <> 0 Then only numbers can by typed to the input.
;                   $Limit - [optional] Limit the input for accept N characters.
;                   $W - [optional] The width of the window. Use -1 for default width (200).
;                   $H - [optional] The height of the window. Use -1 for default height (150).
;                   $Left - [optional] The left side of the input box. By default (-1), the box is centered.
;                   $Top - [optional] The top of the input box. By default (-1), the box is centered.
;                   $Style - [optional] Defines the style of the GUI window (forced style(s): $WS_SIZEBOX).
;                   $exStyle - [optional] Defines the extended style of the GUI window. -1 is the default.
;                   $iTOut - [optional] How many seconds to wait before automatically cancelling the InputBox.
;
; Requirement(s):   #include <GuiConstants.au3>.
; Return Value(s):  String that was typed to the Input.
; Author(s):        G.Sandler (a.k.a CreatoR).
; Note(s):          None.
;
;===============================================================================

Example + UDF:

_InputBox.au3

[NEW]

_InputBox.au3

========================================

EDIT 1:

Added $Timeout param :whistle: - It allows to set timeout (in seconds), just like in the original function InputBox().

EDIT 2:

Added focus of input when window is shown.

EDIT 3:

Added $IsDigits param - it allows to set the behaviour of typing in the input - if this parametr set to 1, then only digits can be typed in the InputBox.

EDIT 4:

Change the way that parent window is disabled (now its by WinSetState() - so its' work not just for Gui).

EDIT 5:

Change te example, now there is no parent gui, the inputbox is &#8220;attached&#8221; to currently active window.

EDIT 6:

Change the function completly - * Now it is possible to set limit for entered string, * the promt text is displayed more correct now, * and the input text are scrollable now ($ES_AUTOHSCROLL).

EDIT 7:

The Example + UDF attached to the post.

+ Little "cosmetic corrections" in the functions.

EDIT 8: (19.11.2007)

+ Added full description/comments to the main function.

* Changed example a little.

* Now the function and the example required #include <GuiConstants.au3> (see bellow why).

* The function now is stripped from &#8220;Magic Numbers&#8221; :)

Edited by MrCreatoR

 

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

You version has a lot of issues. Ie. The Ok and Cancel buttons don't work. You set styles, which cause some styles to be predefined. I'd leave it up to the user to define which styles they'd like.

I used a lot of smokes as a building block. My code works well.

Func _InputBox($Title, $Text = "", $Width = 200, $Height = 75, $Left = -1, $Top = -1, $OnTop = 1, $nInStyle = -1, $nInStyleEx = -1, $IsPassword=0, $IsDigits=0, $Timeout = 0)
    $hWnd = WinGetHandle(WinGetTitle(""))
    Local $aCID[5], $Y = 0, $sRead
    If $Left = -1 Or $Left = Default Then $Left = @DesktopWidth / 2.5
    If $Top = -1 Or $Top = Default Then $Right = @DesktopHeight / 2.5
    If $Width < 175 Then $Width = 175
    If $Height < 75 Then $Height = 75
    If $Text <> '' Then $Y = 20
    Local $hGUI = GUICreate($Title, $Width, $Height + $Y, $Left, $Top)
    If $Text <> '' Then $aCID[1] = GUICtrlCreateLabel($Text, 10, 10, $Width - 20, 20, $ES_CENTER)
    If $IsPassword <> 0 Then $IsPassword = 32
    If $IsDigits <> 0 Then $IsDigits = 8192
    $aCID[2] = GUICtrlCreateInput('', 10, 10 + $Y, $Width - 20, 20, $nInStyle & $IsPassword+$IsDigits, $nInStyleEx)
    $aCID[3] = GUICtrlCreateButton('OK', (($Width - 150) / 2), 40 + $Y, 75, 25, $BS_DEFPUSHBUTTON)
    $aCID[4] = GUICtrlCreateButton('Cancel', (($Width - 150) / 2) + 80, 40 + $Y, 75, 25)
    WinSetOnTop($hGUI, '', $OnTop)
    GUISetState()
    
    If $Timeout > 0 Then $TimerStart = TimerInit()
    While 1
        Switch GUIGetMsg()
            Case - 3, $aCID[4]
                Exit
            Case $aCID[3]
                $sRead = GUICtrlRead($aCID[2])
                Return $sRead
        EndSwitch
    If $Timeout > 0 And Round(TimerDiff($TimerStart)/1000) = $Timeout Then
            $RetValue = GUICtrlRead($aCID[2])
            WinSetState($hWnd, "", @SW_ENABLE)
            GUIDelete($aCID[2])
            SetError(2)
            Return $RetValue
        EndIf
    WEnd
EndFunc

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

You version has a lot of issues

And your's even more :) - You say:

I'd leave it up to the user to define which styles they'd like

But what about $ES_CENTER and $BS_DEFPUSHBUTTON - i have no #Include <GuiConstants.au3> at the begining of script, and what i get? right, an error (Variable used without being declared).

And also, you set in the function the title of the window (Win handle), its not ok, it should be like an option that user can set. And what for do you need it (in your changed func), if there is no disabling of that window (to allow “attaching” of input to that window).

In my function, there is default forced styles (just like in many original funnctions), this is for the resizing - 0x00040000, and for the input there is the style that make it look better :lol: (0x00000001), and some styles for set the resizing behaviour. And if user want to add more styles, he can do it easily, just like with other functions that have a styles.

The Ok and Cancel buttons don't work

If you use the example that i provided in my first post, you will see that everything work fine! :whistle: Edited by MsCreatoR

 

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

  • 4 months later...

Edit first post, the function now more reliable now :">

EDIT 6:

Change the function completly - * Now it is possible to set limit for entered string, * the promt text is displayed more correct now, * and the input text are scrollable now ($ES_AUTOHSCROLL).

 

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

I post it there, i don't know what wrong with the forum, and this is not the first time that topics are moved without any warning/message....

To Moderators:

Please, put it back to Example forum, it should be there i think (it is not "help asking" topic or something :whistle: ).

Thanks :lmao:.

Edited by MsCreatoR

 

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

  • 4 months later...

First post updated! The function rewrited again :P (i hope that is the last time).

 

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

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