MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / InputBoxTimeout

Function InputBoxTimeout

source/script2.cpp:5329–5359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5327
5328
5329VOID CALLBACK InputBoxTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
5330{
5331 // First check if the window has already been destroyed. There are quite a few ways this can
5332 // happen, and in all of them we want to make sure not to do things such as calling EndDialog()
5333 // again or updating the output variable. Reasons:
5334 // 1) The user has already pressed the OK or Cancel button (the timer isn't killed there because
5335 // it relies on us doing this check here). In this case, EndDialog() has already been called
5336 // (with the proper result value) and the script's output variable has already been set.
5337 // 2) Even if we were to kill the timer when the user presses a button to dismiss the dialog,
5338 // this IsWindow() check would still be needed here because TimerProc()'s are called via
5339 // WM_TIMER messages, some of which might still be in our msg queue even after the timer
5340 // has been killed. In other words, split second timing issues may cause this TimerProc()
5341 // to fire even if the timer were killed when the user dismissed the dialog.
5342 // UPDATE: For performance reasons, the timer is now killed when the user presses a button,
5343 // so case #1 is obsolete (but kept here for background/insight).
5344 if (IsWindow(hWnd))
5345 {
5346 auto &CURR_INPUTBOX = *(InputBoxType *)idEvent;
5347 // Even though the dialog has timed out, we still want to write anything the user
5348 // had a chance to enter into the output var. This is because it's conceivable that
5349 // someone might want a short timeout just to enter something quick and let the
5350 // timeout dismiss the dialog for them (i.e. so that they don't have to press enter
5351 // or a button:
5352 INT_PTR result = FAIL;
5353 HWND hControl = GetDlgItem(hWnd, IDC_INPUTEDIT);
5354 if (hControl && CURR_INPUTBOX.UpdateResult(hControl))
5355 result = AHK_TIMEOUT;
5356 EndDialog(hWnd, result);
5357 }
5358 KillTimer(hWnd, idEvent);
5359}
5360
5361
5362

Callers

nothing calls this directly

Calls 1

UpdateResultMethod · 0.80

Tested by

no test coverage detected