1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: make the wait dialog mechanism more generic in order to reuse it more widely across VeraCrypt.

This commit is contained in:
Mounir IDRASSI
2014-12-27 00:08:13 +01:00
parent 258ba629a2
commit c92d51e040
2 changed files with 65 additions and 29 deletions

View File

@@ -6135,29 +6135,29 @@ void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap)
} }
/************************************************************/ /************************************************************/
// implementation of the generic wait dialog mechanism
static UINT g_wmWaitDlg = ::RegisterWindowMessage("VeraCryptWaitDlgMessage");
typedef struct typedef struct
{ {
HWND hwnd; HWND hwnd;
MOUNT_STRUCT* pmount; void* pArg;
BOOL* pbResult; WaitThreadProc callback;
DWORD* pdwResult; } WaitThreadParam;
} MountThreadParam;
static UINT g_wmMountWaitDlg = ::RegisterWindowMessage("VeraCryptMountWaitDlgMessage"); static void _cdecl WaitThread (void* pParam)
static DWORD WINAPI DeviceIoControlThread (void* pParam)
{ {
MountThreadParam* pThreadParam = (MountThreadParam*) pParam; WaitThreadParam* pThreadParam = (WaitThreadParam*) pParam;
*(pThreadParam->pbResult) = DeviceIoControl (hDriver, TC_IOCTL_MOUNT_VOLUME, pThreadParam->pmount, pThreadParam->callback(pThreadParam->pArg, pThreadParam->hwnd);
sizeof (MOUNT_STRUCT),pThreadParam->pmount, sizeof (MOUNT_STRUCT), pThreadParam->pdwResult, NULL);
/* close the wait dialog */ /* close the wait dialog */
PostMessage (pThreadParam->hwnd, g_wmMountWaitDlg, 0, 0); PostMessage (pThreadParam->hwnd, g_wmWaitDlg, 0, 0);
return 0;
} }
static BOOL CALLBACK MountWaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) BOOL CALLBACK WaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
WORD lw = LOWORD (wParam); WORD lw = LOWORD (wParam);
@@ -6165,8 +6165,7 @@ static BOOL CALLBACK MountWaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
MountThreadParam* thParam = (MountThreadParam*) lParam; WaitThreadParam* thParam = (WaitThreadParam*) lParam;
HANDLE hThread = NULL;
// set the progress bar type to MARQUEE (indefinite progress) // set the progress bar type to MARQUEE (indefinite progress)
HWND hProgress = GetDlgItem (hwndDlg, IDC_WAIT_PROGRESS_BAR); HWND hProgress = GetDlgItem (hwndDlg, IDC_WAIT_PROGRESS_BAR);
@@ -6194,8 +6193,7 @@ static BOOL CALLBACK MountWaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
} }
LocalizeDialog (hwndDlg, NULL); LocalizeDialog (hwndDlg, NULL);
hThread = CreateThread(NULL, 0, DeviceIoControlThread, (void*) thParam, 0, NULL); _beginthread(WaitThread, 0, thParam);
SetWindowLongPtr(hwndDlg, GWL_USERDATA, (LONG_PTR) hThread);
return 0; return 0;
} }
@@ -6205,10 +6203,8 @@ static BOOL CALLBACK MountWaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
return 1; return 1;
default: default:
if (msg == g_wmMountWaitDlg) if (msg == g_wmWaitDlg)
{ {
HANDLE hThread = (HANDLE) GetWindowLongPtrA(hwndDlg, GWL_USERDATA);
CloseHandle(hThread);
EndDialog (hwndDlg, IDOK); EndDialog (hwndDlg, IDOK);
return 1; return 1;
} }
@@ -6216,6 +6212,45 @@ static BOOL CALLBACK MountWaitDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
} }
} }
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg)
{
HWND hParent = (hwnd && bUseHwndAsParent)? hwnd : GetDesktopWindow();
WaitThreadParam threadParam;
threadParam.callback = callback;
threadParam.pArg = pArg;
DialogBoxParamW (hInst,
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), hParent,
(DLGPROC) WaitDlgProc, (LPARAM) &threadParam);
if (hwnd && IsWindowVisible(hwnd) && !bUseHwndAsParent)
{
SetForegroundWindow(hwnd);
BringWindowToTop(hwnd);
}
}
/************************************************************************/
// specific definitions and implementation for support of mount operation
// in wait dialog mechanism
typedef struct
{
MOUNT_STRUCT* pmount;
BOOL* pbResult;
DWORD* pdwResult;
} MountThreadParam;
void CALLBACK MountWaitThreadProc(void* pArg, HWND )
{
MountThreadParam* pThreadParam = (MountThreadParam*) pArg;
*(pThreadParam->pbResult) = DeviceIoControl (hDriver, TC_IOCTL_MOUNT_VOLUME, pThreadParam->pmount,
sizeof (MOUNT_STRUCT),pThreadParam->pmount, sizeof (MOUNT_STRUCT), pThreadParam->pdwResult, NULL);
}
/************************************************************************/
// Use only cached passwords if password = NULL // Use only cached passwords if password = NULL
// //
@@ -6364,15 +6399,12 @@ retry:
if (!quiet) if (!quiet)
{ {
MountThreadParam threadParam; MountThreadParam mountThreadParam;
threadParam.hwnd = hwndDlg; mountThreadParam.pmount = &mount;
threadParam.pmount = &mount; mountThreadParam.pbResult = &bResult;
threadParam.pbResult = &bResult; mountThreadParam.pdwResult = &dwResult;
threadParam.pdwResult = &dwResult;
DialogBoxParamW (hInst, ShowWaitDialog (hwndDlg, FALSE, MountWaitThreadProc, &mountThreadParam);
MAKEINTRESOURCEW (IDD_STATIC_MODAL_WAIT_DLG), GetDesktopWindow(),
(DLGPROC) MountWaitDlgProc, (LPARAM) &threadParam);
} }
else else
{ {

View File

@@ -528,6 +528,10 @@ std::string HarddiskVolumePathToPartitionPath (const std::string &harddiskVolume
std::string FindLatestFileOrDirectory (const std::string &directory, const char *namePattern, bool findDirectory, bool findFile); std::string FindLatestFileOrDirectory (const std::string &directory, const char *namePattern, bool findDirectory, bool findFile);
std::string GetUserFriendlyVersionString (int version); std::string GetUserFriendlyVersionString (int version);
// Display a wait dialog while calling the provided callback with the given parameter
typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg);
void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg);
#endif // __cplusplus #endif // __cplusplus
#endif // TC_HEADER_DLGCODE #endif // TC_HEADER_DLGCODE