home » knowledge base » Disable word completion in edit control on Pocket PC (2006-01-28)
By default, every Pocket PC edit control has text completion enabled. In that mode, when Pocket PC OS sees that there is a potential completion for a text in the edit control, it shows a window with the suggestions. It can be selected either by tapping on it or using 5-way navigation up and center press.
This behaviour is not always desirable since it prevents from handling 5-way up event inside edit control.
Also, sometimes edit control is in suggestion mode but suggestion window is not displayed. I haven't figured out why, but this can cause a lot of head-scratching if suddently edit control swallows up events with no apparent reason.
It's possible to control auto-completion by changing sip (soft input panel) flags using SHSipInfo. Unfortunately this is a global setting.
In order to turn completion off only for a given edit control, we need to subclass
edit control, write our own windows proc and enable/disable completion on
WM_KILLFOCUS/WM_SETFOCUS messages, as the snippet below shows.
A better implementation would remember what was the completion state was on
WM_SETFOCUS and restore it on WM_KILLFOCUS.
This jumping through hoop should not be necessary - Pocket PC should provide a flag to disable auto completion that could be set on edit control during its creation.
#include <aygshell.h>
// see http://pocketpcdn.com/articles/wordcompletion.html for details
// edit boxes on pocket pc by default have spelling suggestion/completion.
// Sometimes we want/need to disable that and those functions do it.
void sip_completion_disable(void)
{
SIPINFO info;
SHSipInfo(SPI_GETSIPINFO, 0, &info, 0);
info.fdwFlags |= SIPF_DISABLECOMPLETION;
SHSipInfo(SPI_SETSIPINFO, 0, &info, 0);
}
void sip_completion_enable(void)
{
SIPINFO info;
SHSipInfo(SPI_GETSIPINFO, 0, &info, 0);
info.fdwFlags &= ~SIPF_DISABLECOMPLETION;
SHSipInfo(SPI_SETSIPINFO, 0, &info, 0);
}
LRESULT EditWinProc(HWND hwnd, UINT msg, UINT wparam, LONG lparam)
{
switch (msg) {
case WM_KILLFOCUS:
sip_completion_enable();
break;
case WM_SETFOCUS:
sip_completion_disable();
break;
}
}