VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c78
1 files changed, 42 insertions, 36 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 04f35044..42d93224 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -1219,6 +1219,44 @@ void EnableCloseButton (HWND hwndDlg)
EnableMenuItem (GetSystemMenu (hwndDlg, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
}
+void HandlePasswordEditWmChar (HWND hwnd, WPARAM wParam)
+{
+ DWORD dwStartPos = 0, dwEndPos = 0;
+ short vk = VkKeyScanW ((WCHAR) wParam);
+ BYTE vkCode = LOBYTE (vk);
+ BYTE vkState = HIBYTE (vk);
+ bool ctrlPressed = (vkState & 2) && !(vkState & 4);
+ int dwMaxPassLen = (int) SendMessage (hwnd, EM_GETLIMITTEXT, 0, 0);
+
+ // check if there is a selected text
+ SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos);
+
+ if ((dwStartPos == dwEndPos)
+ && (vkCode != VK_DELETE) && (vkCode != VK_BACK)
+ && !ctrlPressed
+ && (GetWindowTextLength (hwnd) == dwMaxPassLen))
+ {
+ EDITBALLOONTIP ebt;
+ DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_MAXLENGTH_REACHED")) + 16;
+ WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR));
+
+ StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_MAXLENGTH_REACHED"), dwMaxPassLen);
+
+ ebt.cbStruct = sizeof( EDITBALLOONTIP );
+ ebt.pszText = szErrorText;
+ ebt.pszTitle = lpszTitle;
+ ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon
+
+ SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);
+
+ MessageBeep (0xFFFFFFFF);
+
+ free (szErrorText);
+ }
+ else
+ SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0);
+}
+
// Protects an input field from having its content updated by a Paste action (call ToBootPwdField() to use this).
static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -1228,6 +1266,9 @@ static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam
{
case WM_PASTE:
return 1;
+ case WM_CHAR:
+ HandlePasswordEditWmChar (hwnd, wParam);
+ break;
}
return CallWindowProcW (wp, hwnd, message, wParam, lParam);
@@ -1338,42 +1379,7 @@ static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wPar
}
break;
case WM_CHAR:
- {
- DWORD dwStartPos = 0, dwEndPos = 0;
- short vk = VkKeyScanW ((WCHAR) wParam);
- BYTE vkCode = LOBYTE (vk);
- BYTE vkState = HIBYTE (vk);
- bool ctrlPressed = (vkState & 2) && !(vkState & 4);
- int dwMaxPassLen = bUseLegacyMaxPasswordLength? MAX_LEGACY_PASSWORD : MAX_PASSWORD;
-
- // check if there is a selected text
- SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos);
-
- if ((dwStartPos == dwEndPos)
- && (vkCode != VK_DELETE) && (vkCode != VK_BACK)
- && !ctrlPressed
- && (GetWindowTextLength (hwnd) == dwMaxPassLen))
- {
- EDITBALLOONTIP ebt;
- DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_MAXLENGTH_REACHED")) + 16;
- WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR));
-
- StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_MAXLENGTH_REACHED"), dwMaxPassLen);
-
- ebt.cbStruct = sizeof( EDITBALLOONTIP );
- ebt.pszText = szErrorText;
- ebt.pszTitle = lpszTitle;
- ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon
-
- SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt);
-
- MessageBeep (0xFFFFFFFF);
-
- free (szErrorText);
- }
- else
- SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0);
- }
+ HandlePasswordEditWmChar (hwnd, wParam);
break;
}