[MSGINA] Fix default focus to dialog controls (#8337)

Fix some erroneous `SetFocus()` invocations in dialog procedures:

- In `WM_INITDIALOG`, don't return `TRUE` if focus is changed to a
  control, otherwise any focus set by the caller would be ignored;

- In other handlers, `SetFocus()` would generate an inconsistent
  behaviour with the dialog push-buttons, as mentioned in:
  https://devblogs.microsoft.com/oldnewthing/20040802-00/?p=38283
This commit is contained in:
Hermès Bélusca-Maïto
2025-08-14 20:58:12 +02:00
parent d537052196
commit 20b3673aab
2 changed files with 11 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#define IDC_STATIC (-1)
/* Icons */
#define IDI_WINLOGON 4

View File

@@ -780,7 +780,7 @@ ChangePasswordDialogProc(
SendDlgItemMessageW(hwndDlg, IDC_CHANGEPWD_DOMAIN, CB_ADDSTRING, 0, (LPARAM)pgContext->DomainName);
SendDlgItemMessageW(hwndDlg, IDC_CHANGEPWD_DOMAIN, CB_SETCURSEL, 0, 0);
SetFocus(GetDlgItem(hwndDlg, IDC_CHANGEPWD_OLDPWD));
return TRUE;
return FALSE; // Default focus is changed.
}
case WM_COMMAND:
@@ -795,7 +795,7 @@ ChangePasswordDialogProc(
{
SetDlgItemTextW(hwndDlg, IDC_CHANGEPWD_NEWPWD1, NULL);
SetDlgItemTextW(hwndDlg, IDC_CHANGEPWD_NEWPWD2, NULL);
SetFocus(GetDlgItem(hwndDlg, IDC_CHANGEPWD_OLDPWD));
SendMessageW(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_CHANGEPWD_OLDPWD), TRUE);
}
return TRUE;
@@ -1320,7 +1320,9 @@ LogonDialogProc(
if (pDlgData->pgContext->bAutoAdminLogon ||
!pDlgData->pgContext->bDontDisplayLastUserName)
{
SetDlgItemTextW(hwndDlg, IDC_LOGON_USERNAME, pDlgData->pgContext->UserName);
}
if (pDlgData->pgContext->bAutoAdminLogon)
SetDlgItemTextW(hwndDlg, IDC_LOGON_PASSWORD, pDlgData->pgContext->Password);
@@ -1338,7 +1340,7 @@ LogonDialogProc(
if (pDlgData->pgContext->bAutoAdminLogon)
PostMessage(GetDlgItem(hwndDlg, IDOK), BM_CLICK, 0, 0);
return TRUE;
return FALSE; // Default focus is changed.
}
case WM_PAINT:
@@ -1589,18 +1591,18 @@ UnlockDialogProc(
if (pDlgData == NULL)
return FALSE;
DlgData_LoadBitmaps(pDlgData);
SetWelcomeText(hwndDlg);
SetLockMessage(hwndDlg, IDC_UNLOCK_MESSAGE, pDlgData->pgContext);
SetDlgItemTextW(hwndDlg, IDC_UNLOCK_USERNAME, pDlgData->pgContext->UserName);
SetFocus(GetDlgItem(hwndDlg, IDC_UNLOCK_PASSWORD));
if (pDlgData->pgContext->bDisableCAD)
EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), FALSE);
DlgData_LoadBitmaps(pDlgData);
return TRUE;
SetFocus(GetDlgItem(hwndDlg, IDC_UNLOCK_PASSWORD));
return FALSE; // Default focus is changed.
}
case WM_PAINT: