VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-10-15 01:18:25 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-10-15 01:36:15 +0200
commit41819270bbb7129a5568125a6b0cbfdf719680bd (patch)
treee47c9b527b2b0e89fbfe4f38045f8d67aff3e038 /src/Common
parent8342d0d616a8340bc358b19146f1b2d8cdf41af8 (diff)
downloadVeraCrypt-41819270bbb7129a5568125a6b0cbfdf719680bd.tar.gz
VeraCrypt-41819270bbb7129a5568125a6b0cbfdf719680bd.zip
Windows: Solve lost focus for application after displaying the waiting dialog
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c50
-rw-r--r--src/Common/Dlgcode.h1
2 files changed, 44 insertions, 7 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index a295d5b5..65801bea 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -6592,6 +6592,43 @@ BOOL CALLBACK WaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
}
}
+
+void BringToForeground(HWND hWnd)
+{
+ if(!::IsWindow(hWnd)) return;
+
+ DWORD lockTimeOut = 0;
+ HWND hCurrWnd = ::GetForegroundWindow();
+ DWORD dwThisTID = ::GetCurrentThreadId(),
+ dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0);
+
+ if(dwThisTID != dwCurrTID)
+ {
+ ::AttachThreadInput(dwThisTID, dwCurrTID, TRUE);
+
+ ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&lockTimeOut,0);
+ ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
+
+ ::AllowSetForegroundWindow(ASFW_ANY);
+ }
+
+ ::SetForegroundWindow(hWnd);
+
+ if(dwThisTID != dwCurrTID)
+ {
+ ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)lockTimeOut,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
+ ::AttachThreadInput(dwThisTID, dwCurrTID, FALSE);
+ }
+
+#ifdef TCMOUNT
+ if (hWnd == MainDlg)
+ {
+ SetFocus (hWnd);
+ ::SendMessage(hWnd, WM_NEXTDLGCTL, (WPARAM) GetDlgItem (hWnd, IDC_DRIVELIST), 1L);
+ }
+#endif
+}
+
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg)
{
HWND hParent = (hwnd && bUseHwndAsParent)? hwnd : GetDesktopWindow();
@@ -6605,24 +6642,23 @@ void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, v
}
else
{
+ BOOL bIsForeground = FALSE;
WaitDialogDisplaying = TRUE;
if (hwnd)
+ {
+ if (GetForegroundWindow () == hwnd)
+ bIsForeground = TRUE;
EnableWindow (hwnd, FALSE);
+ }
else
EnableWindow (MainDlg, FALSE);
- finally_do_arg (HWND, hwnd, { if (finally_arg) EnableWindow(finally_arg, TRUE); else EnableWindow (MainDlg, TRUE);});
+ finally_do_arg2 (HWND, hwnd, BOOL, bIsForeground, { if (finally_arg) {EnableWindow(finally_arg, TRUE); if (finally_arg2) BringToForeground (finally_arg);} else EnableWindow (MainDlg, TRUE);});
DialogBoxParamW (hInst,
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent,
(DLGPROC) WaitDlgProc, (LPARAM) &threadParam);
WaitDialogDisplaying = FALSE;
-
- if (hwnd && IsWindowVisible(hwnd) && !bUseHwndAsParent)
- {
- SetForegroundWindow(hwnd);
- BringWindowToTop(hwnd);
- }
}
}
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index 5d8d7e29..a7f4affd 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -568,6 +568,7 @@ inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos)
// Display a wait dialog while calling the provided callback with the given parameter
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
+void BringToForeground(HWND hWnd);
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg);
#endif // __cplusplus