QA: How can I disable SIP word completion?

Vassili Philippov (vasja@spbteam.com), November 07, 2001.

Question

My application prompts for a password in an edit box. Although the 'password' style is set so that only asterisks are displayed when characters are entered, if a password has previously been entered then the 'Word Completion' feature causes the previous password to be suggested. How can I disable word completion for the password field?

Answer

You should add SIPF_DISABLECOMPLETION flag to the fdwFlags member of of SIPINFO structure. Then set this SIPINFO using SHSipInfo function. Here is code for that:

SIPINFO info; SHSipInfo(SPI_GETSIPINFO, 0, &info, 0); info.fdwFlags |= SIPF_DISABLECOMPLETION; SHSipInfo(SPI_SETSIPINFO, 0, &info, 0);

But if SIP is already opened then it will not work. You have to close and open SIP again. The following two lines do what is needed:

SHSipPreference(m_hWnd, SIP_FORCEDOWN); SHSipPreference(m_hWnd, SIP_UP);

Restore word completion

We do not need to disable word completion for all input fields, only for password fields. For that we will disable word completion when the password field receives focus and will restore it when the password field loses the focus.

We should handle EN_SETFOCUS and EN_KILLFOCUS messages. The handles can be like in the following example:

void CCompletionTestDlg::OnSetfocusPassword() { SIPINFO info; SHSipInfo(SPI_GETSIPINFO, 0, &info, 0); m_dwSipFlasg = info.fdwFlags; info.fdwFlags |= SIPF_DISABLECOMPLETION; SHSipInfo(SPI_SETSIPINFO, 0, &info, 0); SHSipPreference(m_hWnd, SIP_FORCEDOWN); SHSipPreference(m_hWnd, SIP_UP); } void CCompletionTestDlg::OnKillfocusPassword() { SIPINFO info; SHSipInfo(SPI_GETSIPINFO, 0, &info, 0); info.fdwFlags = m_dwSipFlasg; SHSipInfo(SPI_SETSIPINFO, 0, &info, 0); SHSipPreference(m_hWnd, SIP_FORCEDOWN); SHSipPreference(m_hWnd, SIP_UP); }

Related resources: