The NM_SFTBOX_CHAR structure is sent to the parent window with a WM_NOTIFY message (notification code NM_SFTBOX_CHAR_CODE) when a character is typed while the combo box control has the input focus.
#define NM_SFTBOX_CHAR_CODE 102
typedef struct {
NMHDR hdr;
BOOL fEdit;
TCHAR ch;
int cRepeat;
BOOL fHandled; // modifiable
} NM_SFTBOX_CHAR;The standard WM_NOTIFY notification header. hwndFrom contains the window handle of the combo box control, idFrom contains the control ID of the combo box control and code is set to NM_SFTBOX_CHAR_CODE.
TRUE if the combo box control has an edit control portion (simple combo box and dropdown combo box), in which case the character is about to be entered into the edit control portion. FALSE for a dropdown list combo box, where the character is about to be used to search for an item.
The character code (the wParam value of the WM_CHAR message). Control characters, such as Backspace, are also reported.
The repeat count (the low-order word of the lParam value of the WM_CHAR message).
Modifiable. The combo box control sets this member to FALSE before sending the notification. An application can set fHandled to TRUE to indicate that it has handled the character. In this case, the combo box control discards the character. It is not entered into the edit control portion and, in a dropdown list combo box, it is not used to search for an item. If fHandled remains FALSE, the character is processed normally. h1 Comments
The combo box control sends the WM_NOTIFY message with the NM_SFTBOX_CHAR structure to its parent window for each WM_CHAR message it receives, before the character is processed. The wParam value of the WM_NOTIFY message contains the control ID of the combo box control, the lParam value contains a pointer to the NM_SFTBOX_CHAR structure.
This notification can be used to filter character input, for example to restrict the characters that can be entered into the edit control portion.
Key down and key up events are reported using the NM_SFTBOX_KEYDOWN and NM_SFTBOX_KEYUP structures.
case WM_NOTIFY: {
LPNMHDR lpnmh = (LPNMHDR) lParam;
if (lpnmh->idFrom == IDC_COMBO && lpnmh->code == NM_SFTBOX_CHAR_CODE) {
NM_SFTBOX_CHAR * lpChar = (NM_SFTBOX_CHAR *) lParam;
if (lpChar->fEdit && lpChar->ch >= TEXT('0') && lpChar->ch <= TEXT('9'))
lpChar->fHandled = TRUE; // digits cannot be entered
}
break;
}See Also C/C++ API | Categories | Notifications