| 5313 | ////////////// |
| 5314 | |
| 5315 | ResultType InputBox(Var *aOutputVar, char *aTitle, char *aText, bool aHideInput, int aWidth, int aHeight |
| 5316 | , int aX, int aY, double aTimeout, char *aDefault) |
| 5317 | { |
| 5318 | // Note: for maximum compatibility with existing AutoIt2 scripts, do not |
| 5319 | // set ErrorLevel to ERRORLEVEL_ERROR when the user presses cancel. Instead, |
| 5320 | // just set the output var to be blank. |
| 5321 | if (g_nInputBoxes >= MAX_INPUTBOXES) |
| 5322 | { |
| 5323 | // Have a maximum to help prevent runaway hotkeys due to key-repeat feature, etc. |
| 5324 | MsgBox("The maximum number of InputBoxes has been reached." ERR_ABORT); |
| 5325 | return FAIL; |
| 5326 | } |
| 5327 | if (!aOutputVar) return FAIL; |
| 5328 | if (!*aTitle) |
| 5329 | // If available, the script's filename seems a much better title in case the user has |
| 5330 | // more than one script running: |
| 5331 | aTitle = (g_script.mFileName && *g_script.mFileName) ? g_script.mFileName : NAME_PV; |
| 5332 | // Limit the size of what we were given to prevent unreasonably huge strings from |
| 5333 | // possibly causing a failure in CreateDialog(). This copying method is always done because: |
| 5334 | // Make a copy of all string parameters, using the stack, because they may reside in the deref buffer |
| 5335 | // and other commands (such as those in timed/hotkey subroutines) maybe overwrite the deref buffer. |
| 5336 | // This is not strictly necessary since InputBoxProc() is called immediately and makes instantaneous |
| 5337 | // and one-time use of these strings (not needing them after that), but it feels safer: |
| 5338 | char title[DIALOG_TITLE_SIZE]; |
| 5339 | char text[4096]; // Size was increased in light of the fact that dialog can be made larger now. |
| 5340 | char default_string[4096]; |
| 5341 | strlcpy(title, aTitle, sizeof(title)); |
| 5342 | strlcpy(text, aText, sizeof(text)); |
| 5343 | strlcpy(default_string, aDefault, sizeof(default_string)); |
| 5344 | g_InputBox[g_nInputBoxes].title = title; |
| 5345 | g_InputBox[g_nInputBoxes].text = text; |
| 5346 | g_InputBox[g_nInputBoxes].default_string = default_string; |
| 5347 | |
| 5348 | if (aTimeout > 2147483) // This is approximately the max number of seconds that SetTimer can handle. |
| 5349 | aTimeout = 2147483; |
| 5350 | if (aTimeout < 0) // But it can be equal to zero to indicate no timeout at all. |
| 5351 | aTimeout = 0.1; // A value that might cue the user that something is wrong. |
| 5352 | g_InputBox[g_nInputBoxes].timeout = (DWORD)(aTimeout * 1000); // Convert to ms |
| 5353 | |
| 5354 | // Allow 0 width or height (hides the window): |
| 5355 | g_InputBox[g_nInputBoxes].width = aWidth != INPUTBOX_DEFAULT && aWidth < 0 ? 0 : aWidth; |
| 5356 | g_InputBox[g_nInputBoxes].height = aHeight != INPUTBOX_DEFAULT && aHeight < 0 ? 0 : aHeight; |
| 5357 | g_InputBox[g_nInputBoxes].xpos = aX; // But seems okay to allow these to be negative, even if absolute coords. |
| 5358 | g_InputBox[g_nInputBoxes].ypos = aY; |
| 5359 | g_InputBox[g_nInputBoxes].output_var = aOutputVar; |
| 5360 | g_InputBox[g_nInputBoxes].password_char = aHideInput ? '*' : '\0'; |
| 5361 | |
| 5362 | // At this point, we know a dialog will be displayed. See macro's comments for details: |
| 5363 | DIALOG_PREP |
| 5364 | |
| 5365 | // Specify NULL as the owner window since we want to be able to have the main window in the foreground |
| 5366 | // even if there are InputBox windows: |
| 5367 | ++g_nInputBoxes; |
| 5368 | int result = (int)DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_INPUTBOX), NULL, InputBoxProc); |
| 5369 | --g_nInputBoxes; |
| 5370 | |
| 5371 | // See the comments in InputBoxProc() for why ErrorLevel is set here rather than there. |
| 5372 | switch(result) |
no test coverage detected