mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: Solve lost focus for application after displaying the waiting dialog
This commit is contained in:
@@ -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)
|
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg)
|
||||||
{
|
{
|
||||||
HWND hParent = (hwnd && bUseHwndAsParent)? hwnd : GetDesktopWindow();
|
HWND hParent = (hwnd && bUseHwndAsParent)? hwnd : GetDesktopWindow();
|
||||||
@@ -6605,24 +6642,23 @@ void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, v
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
BOOL bIsForeground = FALSE;
|
||||||
WaitDialogDisplaying = TRUE;
|
WaitDialogDisplaying = TRUE;
|
||||||
if (hwnd)
|
if (hwnd)
|
||||||
|
{
|
||||||
|
if (GetForegroundWindow () == hwnd)
|
||||||
|
bIsForeground = TRUE;
|
||||||
EnableWindow (hwnd, FALSE);
|
EnableWindow (hwnd, FALSE);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
EnableWindow (MainDlg, FALSE);
|
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,
|
DialogBoxParamW (hInst,
|
||||||
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent,
|
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent,
|
||||||
(DLGPROC) WaitDlgProc, (LPARAM) &threadParam);
|
(DLGPROC) WaitDlgProc, (LPARAM) &threadParam);
|
||||||
|
|
||||||
WaitDialogDisplaying = FALSE;
|
WaitDialogDisplaying = FALSE;
|
||||||
|
|
||||||
if (hwnd && IsWindowVisible(hwnd) && !bUseHwndAsParent)
|
|
||||||
{
|
|
||||||
SetForegroundWindow(hwnd);
|
|
||||||
BringWindowToTop(hwnd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Display a wait dialog while calling the provided callback with the given parameter
|
||||||
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
|
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
|
||||||
|
void BringToForeground(HWND hWnd);
|
||||||
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg);
|
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg);
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|||||||
@@ -4598,9 +4598,10 @@ static BOOL Dismount (HWND hwndDlg, int nDosDriveNo)
|
|||||||
void __cdecl mountThreadFunction (void *hwndDlgArg)
|
void __cdecl mountThreadFunction (void *hwndDlgArg)
|
||||||
{
|
{
|
||||||
HWND hwndDlg =(HWND) hwndDlgArg;
|
HWND hwndDlg =(HWND) hwndDlgArg;
|
||||||
|
BOOL bIsForeground = (GetForegroundWindow () == hwndDlg)? TRUE : FALSE;
|
||||||
// Disable parent dialog during processing to avoid user interaction
|
// Disable parent dialog during processing to avoid user interaction
|
||||||
EnableWindow(hwndDlg, FALSE);
|
EnableWindow(hwndDlg, FALSE);
|
||||||
finally_do_arg (HWND, hwndDlg, { EnableWindow(finally_arg, TRUE); bPrebootPasswordDlgMode = FALSE;});
|
finally_do_arg2 (HWND, hwndDlg, BOOL, bIsForeground, { EnableWindow(finally_arg, TRUE); if (finally_arg2) BringToForeground (finally_arg); bPrebootPasswordDlgMode = FALSE;});
|
||||||
|
|
||||||
Mount (hwndDlg, 0, 0, -1);
|
Mount (hwndDlg, 0, 0, -1);
|
||||||
}
|
}
|
||||||
@@ -9102,7 +9103,7 @@ void CALLBACK mountFavoriteVolumeCallbackFunction (void *pArg, HWND hwnd)
|
|||||||
|
|
||||||
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg)
|
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg)
|
||||||
{
|
{
|
||||||
ShowWaitDialog (NULL, FALSE, mountFavoriteVolumeCallbackFunction, pArg);
|
ShowWaitDialog (MainDlg, FALSE, mountFavoriteVolumeCallbackFunction, pArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveDefaultKeyFilesParam (HWND hwnd)
|
static void SaveDefaultKeyFilesParam (HWND hwnd)
|
||||||
|
|||||||
Reference in New Issue
Block a user