|
2 | 2 | ; Name ..........: _MultiInput |
3 | 3 | ; Description ...: InputBox with multiple inputs |
4 | 4 | ; AutoIt Version : V3.3.0.0 |
5 | | -; Syntax ........: _MultiInput(ByRef $aText[, $sTitle = ""[, $vInputStyle = -1[, $iInputWidth = 200[, $sButtonR = "OK"[, $sButtonL = "Cancel"[, $iReturnMode = 0]]]]]]) |
| 5 | +; Syntax ........: _MultiInput(ByRef $aText[, $aDefaultText=""[, $sTitle = ""[, $vInputStyle = -1[, $iInputWidth = 200[, $sButtonL = "OK"[, $sButtonR = "Cancel"[, $iReturnMode = 0[, $parent]]]]]]]) |
6 | 6 | ; Parameter(s): .: $aText - Array with the text for the input-controls. |
7 | 7 | ; * Text-style: |
8 | 8 | ; | **Text** = bold |
9 | 9 | ; | ""Text"" = italic |
10 | 10 | ; | __Text__ = underline |
11 | 11 | ; | --Text-- = strike |
| 12 | +; $aDefaultText - Optional: (Default = "") : Array with the default text for the input-controls. The controls will be prefilled. |
12 | 13 | ; $sTitle - Optional: (Default = "") : Window-title |
13 | 14 | ; $vInputStyle - Optional: (Default = -1) : Style for the input-controls. |
14 | 15 | ; | single var for a global style, or |
15 | 16 | ; | array for different styles |
16 | | -; * look at the "GUI Control Styles" |
| 17 | +; * lool at the "GUI Control Styles" |
17 | 18 | ; $iInputWidth - Optional: (Default = 200) : Width of the inputs |
18 | | -; $sButtonR - Optional: (Default = "OK") : Text of the right button |
19 | | -; $sButtonL - Optional: (Default = "Cancel") : Text of the left button |
| 19 | +; $sButtonL - Optional: (Default = "OK") : Text of the left button |
| 20 | +; $sButtonR - Optional: (Default = "Cancel") : Text of the right button |
20 | 21 | ; $iReturnMode - Optional: (Default = 0) : |
21 | 22 | ; | 0 Returns a single string, values seperated with the GUIDataSeparatorChar |
22 | 23 | ; | 1 Returns an array with all values |
| 24 | +; $parent - Optional: (Default = -1) : The window handle to use as the parent for this dialog. |
23 | 25 | ; Return Value ..: Success - string or array, depending on $iReturnMode |
24 | 26 | ; Failure - empty string |
25 | 27 | ; @ERROR - 1 if cancel is pressed |
26 | 28 | ; | 2 UBound($aT) <> UBound($aInputFormat) |
27 | 29 | ; | 3 $aText not an array |
28 | | -; Author(s) .....: Thorsten Willert |
29 | | -; Date ..........: Sun Nov 08 12:25:22 CET 2009 |
30 | | -; Version .......: 3.0 |
| 30 | + ; | 4 $aDefaultText not an array |
| 31 | + ; | 5 UBound($aText) <> UBound($aDefaultText) |
| 32 | +; Author(s) .....: Thorsten Willert and M3d1c5 |
| 33 | +; Date ..........: Sun Jul 08 20:24:00 CET 2012 |
| 34 | +; Version .......: 4.0 |
31 | 35 | ; Example .......: |
32 | 36 | ; |
33 | 37 | ;Global $aTexts[5] = ["**Verzeichnis**", "Benutzer", "Passwort", "", "__Information__"] |
34 | 38 | ;Global $aInputSt[5] = [-1, -1, 32] ; $ES_PASSWORD = 32 |
35 | 39 |
|
36 | 40 |
|
37 | | -; Global $sValues = _MultiInput($aTexts, "Test", $aInputSt) |
| 41 | +; Global $sValues = _MultiInput($aTexts, "", "Test", $aInputSt) |
38 | 42 | ; If Not @error Then MsgBox(0, "", $sValues) |
39 | 43 | ; ============================================================================== |
40 | | -Func _MultiInput(ByRef $aText, $sTitle = "", $vInputStyle = -1, $iInputWidth = 200, $sButtonR = "OK", $sButtonL = "Cancel", $iReturnMode = 0) |
41 | | - Local $oldOpt = Opt('GUIOnEventMode', 0) |
| 44 | +Func _MultiInput(ByRef $atext, $adefaulttext = "", $stitle = "", $vinputstyle = -1, $iinputwidth = 200, $sbuttonl = "OK", $sbuttonr = "Cancel", $ireturnmode = 0, $parent = -1) |
| 45 | + Local $oldopt = Opt('GUIOnEventMode') |
42 | 46 |
|
43 | 47 |
|
44 | | - ; Default parameters |
45 | | - If $iInputWidth < 100 Then $iInputWidth = 100 |
46 | | - If $iInputWidth = Default Then $iInputWidth = 200 |
47 | | - If $vInputStyle = Default Then $vInputStyle = -1 |
48 | | - If $sButtonR = Default Then $sButtonR = "OK" |
49 | | - If $sButtonL = Default Then $sButtonL = "Cancel" |
| 48 | + ; Default parameters |
| 49 | + If $iinputwidth < 100 Then $iinputwidth = 100 |
| 50 | + If $iinputwidth = Default Then $iinputwidth = 200 |
| 51 | + If $vinputstyle = Default Then $vinputstyle = -1 |
| 52 | + If $sbuttonl = Default Then $sbuttonl = "OK" |
| 53 | + If $sbuttonr = Default Then $sbuttonr = "Cancel" |
50 | 54 |
|
51 | 55 |
|
52 | | - ; Parameter check (arrays only) |
53 | | - If Not IsArray($aText) Then |
54 | | - SetError(3) |
55 | | - Return "" |
56 | | - EndIf |
57 | | - If IsArray($vInputStyle) And UBound($vInputStyle) <> UBound($aText) Then |
58 | | - SetError(2) |
59 | | - Return "" |
60 | | - EndIf |
| 56 | + ; Parameter check (arrays only) |
| 57 | + If Not IsArray($atext) Then |
| 58 | + SetError(3) |
| 59 | + Return "" |
| 60 | + EndIf |
| 61 | + If Not IsArray($adefaulttext) And $adefaulttext <> "" Then |
| 62 | + SetError(4) |
| 63 | + Return "" |
| 64 | + EndIf |
| 65 | + If IsArray($vinputstyle) And UBound($vinputstyle) <> UBound($atext) Then |
| 66 | + SetError(2) |
| 67 | + Return "" |
| 68 | + EndIf |
| 69 | + If IsArray($adefaulttext) And UBound($atext) <> UBound($adefaulttext) Then |
| 70 | + SetError(5) |
| 71 | + Return "" |
| 72 | + EndIf |
61 | 73 |
|
62 | 74 |
|
63 | | - Local $iS = 6 ; char width |
64 | | - Local $iT = UBound($aText) |
65 | | - Local $input[$iT], $aTextStyle[$iT], $aTextWidth[$iT] |
66 | | - Local $iOfs = 0, $iLen = 0 |
67 | | - Local $sSC = Opt("GUIDataSeparatorChar") |
68 | | - Local $sRet = "" |
69 | | - Local $InputStyle |
70 | | - If Not IsArray($vInputStyle) Then $InputStyle = $vInputStyle |
| 75 | + Local $is = 6 ; char width |
| 76 | + Local $it = UBound($atext) |
| 77 | + Local $input[$it], $atextstyle[$it], $atextwidth[$it] |
| 78 | + Local $iofs = 0, $ilen = 0 |
| 79 | + Local $ssc = Opt("GUIDataSeparatorChar") |
| 80 | + Local $sret = "" |
| 81 | + Local $inputstyle |
| 82 | + If Not IsArray($vinputstyle) Then $inputstyle = $vinputstyle |
71 | 83 |
|
72 | 84 |
|
73 | | - ; text width and styles |
74 | | - For $i = 0 To $iT - 1 |
75 | | - $iLen = StringLen($aText[$i]) |
76 | | - If $iLen > $iOfs Then $iOfs = $iLen ; max text width |
77 | | - If $iOfs < 10 Then $iOfs = 10 |
78 | | - $aTextWidth[$i] = 400 |
79 | | - $aTextStyle[$i] = 0 |
80 | | - Select |
81 | | - ; bold |
82 | | - Case StringRegExp($aText[$i], '^\*\*.*?\*\*$') |
83 | | - $aTextWidth[$i] = 600 |
84 | | - $aText[$i] = StringMid($aText[$i], 3, $iLen - 4) |
85 | | - ; italic |
86 | | - Case StringRegExp($aText[$i], '^"".*?""$') |
87 | | - $aTextStyle[$i] = 2 |
88 | | - $aText[$i] = StringMid($aText[$i], 3, $iLen - 4) |
89 | | - ; underline |
90 | | - Case StringRegExp($aText[$i], '^__.*?__$') |
91 | | - $aTextStyle[$i] = 4 |
92 | | - $aText[$i] = StringMid($aText[$i], 3, $iLen - 4) |
93 | | - ; strike |
94 | | - Case StringRegExp($aText[$i], '^--.*?--$') |
95 | | - $aTextStyle[$i] = 8 |
96 | | - $aText[$i] = StringMid($aText[$i], 3, $iLen - 4) |
97 | | - EndSelect |
98 | | - Next |
| 85 | + ; text width and styles |
| 86 | + For $i = 0 To $it - 1 |
| 87 | + $ilen = StringLen($atext[$i]) |
| 88 | + If $ilen > $iofs Then $iofs = $ilen ; max text width |
| 89 | + If $iofs < 10 Then $iofs = 10 |
| 90 | + $atextwidth[$i] = 400 |
| 91 | + $atextstyle[$i] = 0 |
| 92 | + Select |
| 93 | + ; bold |
| 94 | + Case StringRegExp($atext[$i], '^\*\*.*?\*\*$') |
| 95 | + $atextwidth[$i] = 600 |
| 96 | + $atext[$i] = StringMid($atext[$i], 3, $ilen - 4) |
| 97 | + ; italic |
| 98 | + Case StringRegExp($atext[$i], '^"".*?""$') |
| 99 | + $atextstyle[$i] = 2 |
| 100 | + $atext[$i] = StringMid($atext[$i], 3, $ilen - 4) |
| 101 | + ; underline |
| 102 | + Case StringRegExp($atext[$i], '^__.*?__$') |
| 103 | + $atextstyle[$i] = 4 |
| 104 | + $atext[$i] = StringMid($atext[$i], 3, $ilen - 4) |
| 105 | + ; strike |
| 106 | + Case StringRegExp($atext[$i], '^--.*?--$') |
| 107 | + $atextstyle[$i] = 8 |
| 108 | + $atext[$i] = StringMid($atext[$i], 3, $ilen - 4) |
| 109 | + EndSelect |
| 110 | + Next |
99 | 111 |
|
100 | 112 |
|
101 | | - ; GUI |
102 | | - Local $hWin = GUICreate($sTitle, $iOfs * $iS + $iInputWidth + 40, $iT * 25 + 55) |
103 | | - For $i = 0 To $iT - 1 |
104 | | - If IsArray($vInputStyle) Then $InputStyle = $vInputStyle[$i] |
105 | | - Select |
106 | | - Case $aText[$i] <> "" |
107 | | - GUICtrlCreateLabel($aText[$i] & ":", 16, $i * 25 + 15, $iOfs * $iS) |
108 | | - GUICtrlSetFont(-1, 8.5, $aTextWidth[$i], $aTextStyle[$i]) |
109 | | - $input[$i] = GUICtrlCreateInput("", $iOfs * $iS + 20, $i * 25 + 10, $iInputWidth, -1, $InputStyle) |
110 | | - Case Else |
111 | | - GUICtrlCreateLabel("", 16, 1) |
112 | | - EndSelect |
113 | | - Next |
114 | | - Local $ok = GUICtrlCreateButton($sButtonR, 16, $i * 25 + 20, 75) |
115 | | - GUICtrlSetState(-1, 512) ; $GUI_DEFBUTTON = 512 |
116 | | - Local $cancel = GUICtrlCreateButton($sButtonL, $iOfs * $iS + $iInputWidth - 55, $i * 25 + 20, 75) |
117 | | - GUISetState(@SW_SHOW) |
118 | | - ; /GUI |
| 113 | + ; GUI |
| 114 | + If $parent <> -1 Then GUISetState(@SW_DISABLE, $parent) |
| 115 | + Local $hwin = GUICreate($stitle, $iofs * $is + $iinputwidth + 40, $it * 25 + 55, -1, -1, -1, -1, $parent) |
| 116 | + For $i = 0 To $it - 1 |
| 117 | + If IsArray($vinputstyle) Then $inputstyle = $vinputstyle[$i] |
| 118 | + Select |
| 119 | + Case $atext[$i] <> "" |
| 120 | + GUICtrlCreateLabel($atext[$i] & ":", 16, $i * 25 + 15, $iofs * $is) |
| 121 | + GUICtrlSetFont(-1, 8.5, $atextwidth[$i], $atextstyle[$i]) |
| 122 | + $input[$i] = GUICtrlCreateInput("", $iofs * $is + 20, $i * 25 + 10, $iinputwidth, -1, $inputstyle) |
| 123 | + If IsArray($adefaulttext) Then |
| 124 | + GUICtrlSetData($input[$i], $adefaulttext[$i]) |
| 125 | + EndIf |
| 126 | + Case Else |
| 127 | + GUICtrlCreateLabel("", 16, 1) |
| 128 | + EndSelect |
| 129 | + Next |
| 130 | + Local $ok = GUICtrlCreateButton($sbuttonl, 16, $i * 25 + 20, 75) |
| 131 | + GUICtrlSetState(-1, 512) ; $GUI_DEFBUTTON = 512 |
| 132 | + Local $cancel = GUICtrlCreateButton($sbuttonr, $iofs * $is + $iinputwidth - 55, $i * 25 + 20, 75) |
| 133 | + GUISetState(@SW_SHOW) |
| 134 | + ; /GUI |
119 | 135 |
|
120 | 136 |
|
121 | | - While True |
122 | | - Switch GUIGetMsg() |
123 | | - Case -3, $cancel ; $GUI_EVENT_CLOSE = -3 |
124 | | - GUIDelete($hWin) |
125 | | - Opt('GUIOnEventMode', $oldOpt) |
126 | | - SetError(1) |
127 | | - Return "" |
128 | | - Case $ok |
129 | | - For $i = 0 To $iT - 2 |
130 | | - $sRet &= GUICtrlRead($input[$i]) & $sSC |
131 | | - Next |
132 | | - $sRet &= GUICtrlRead($input[$i]) |
133 | | - GUIDelete($hWin) |
134 | | - Opt('GUIOnEventMode', $oldOpt) |
135 | | - If $iReturnMode = 0 Then |
136 | | - Return $sRet |
137 | | - Else |
138 | | - Return StringSplit($sRet, $sSC, 2) |
139 | | - EndIf |
140 | | - EndSwitch |
141 | | - WEnd |
| 137 | + While True |
| 138 | + Switch GUIGetMsg() |
| 139 | + Case -3, $cancel ; $GUI_EVENT_CLOSE = -3 |
| 140 | + If $parent <> -1 Then GUISetState(@SW_ENABLE, $parent) |
| 141 | + GUIDelete($hwin) |
| 142 | + Opt('GUIOnEventMode', $oldopt) |
| 143 | + SetError(1) |
| 144 | + Return "" |
| 145 | + Case $ok |
| 146 | + For $i = 0 To $it - 2 |
| 147 | + $sret &= GUICtrlRead($input[$i]) & $ssc |
| 148 | + Next |
| 149 | + $sret &= GUICtrlRead($input[$i]) |
| 150 | + If $parent <> -1 Then GUISetState(@SW_ENABLE, $parent) |
| 151 | + GUIDelete($hwin) |
| 152 | + Opt('GUIOnEventMode', $oldopt) |
| 153 | + If $ireturnmode = 0 Then |
| 154 | + Return $sret |
| 155 | + Else |
| 156 | + Return StringSplit($sret, $ssc, 2) |
| 157 | + EndIf |
| 158 | + EndSwitch |
| 159 | + WEnd |
142 | 160 | EndFunc ;==>_MultiInput |
0 commit comments