| 1979 | |
| 1980 | |
| 1981 | VOID CALLBACK MsgBoxTimeout(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) |
| 1982 | { |
| 1983 | // Unfortunately, it appears that MessageBox() will return zero rather |
| 1984 | // than AHK_TIMEOUT, specified below -- at least under WinXP. This |
| 1985 | // makes it impossible to distinguish between a MessageBox() that's been |
| 1986 | // timed out (destroyed) by this function and one that couldn't be |
| 1987 | // created in the first place due to some other error. But since |
| 1988 | // MessageBox() errors are rare, we assume that they timed out if |
| 1989 | // the MessageBox() returns 0. UPDATE: Due to the fact that TimerProc()'s |
| 1990 | // are called via WM_TIMER messages in our msg queue, make sure that the |
| 1991 | // window really exists before calling EndDialog(), because if it doesn't, |
| 1992 | // chances are that EndDialog() was already called with another value. |
| 1993 | // UPDATE #2: Actually that isn't strictly needed because MessageBox() |
| 1994 | // ignores the AHK_TIMEOUT value we send here. But it feels safer: |
| 1995 | if (IsWindow(hWnd)) |
| 1996 | EndDialog(hWnd, AHK_TIMEOUT); |
| 1997 | KillTimer(hWnd, idEvent); |
| 1998 | // v1.0.33: The following was added to fix the fact that a MsgBox with only an OK button |
| 1999 | // does not actually send back the code sent by EndDialog() above. The HWND is checked |
| 2000 | // in case "g" is no longer the original thread due to another thread having interrupted it. |
| 2001 | // v1.1.30.01: The loop was added so that the timeout can be detected even if the thread |
| 2002 | // which owns the dialog was interrupted. |
| 2003 | for (auto *dialog_g = g; dialog_g >= g_array; --dialog_g) |
| 2004 | if (dialog_g->DialogHWND == hWnd) // Regardless of whether IsWindow() is true. |
| 2005 | { |
| 2006 | dialog_g->MsgBoxTimedOut = true; |
| 2007 | break; |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 |
nothing calls this directly
no outgoing calls
no test coverage detected