0

I have a login dialog for my MFC application in Visual Studio. By pressing an 'eye' button, the password attribute of the edit control gets enabled/disabled.

This works as expected; however, after pressing the button, the displayed text inside the edit control stays as it was until I move the cursor over the edit control.

Is there any way to 'tell' the edit control to update itself, so that I don't have to move the cursor over it?

This is my code, which is executed after pressing the 'eye' button:

if (((CEdit*)GetDlgItem(IDC_EDIT1))->GetPasswordChar() == 9679)
    ((CEdit*)GetDlgItem(IDC_EDIT1))->SetPasswordChar(0);
else
    ((CEdit*)GetDlgItem(IDC_EDIT1))->SetPasswordChar(9679);

I tried to send an EN_UPDATE message after setting the attribute of my edit control, but without any success.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 2
    `EN_UPDATE` is a *notification* message, sent to the control's parent to notify it about events. If you need to update a window, call [`CWnd::UpdateWindow`](https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class#updatewindow). – IInspectable Mar 01 '23 at 20:21
  • 1
    According to the documentation calling `SetPasswordChar` should be enough to also trigger a refresh of the display, however if that is not working for you. You can try calling `((CEdit*)GetDlgItem(IDC_EDIT1))->Invalidate();` this will mark the window region as out of date and requires repainting. – user20716902 Mar 01 '23 at 22:43
  • 1
    ((CEdit*)GetDlgItem(IDC_EDIT1))->Invalidate(); works perfect, thank you very much!:) – Medic 84 Mar 03 '23 at 16:18

0 Answers0