Re: PreTranslateMessage is not called in CMessageFilter and CEdit derived class
"Jim Barry" <[email protected]>
| Newsgroups | gmane.comp.windows.wtl |
|---|---|
| Message-ID | <053BA0665AF74BD88C27E866596F0CA5@jbarry> |
"izm_ka" wrote:
> Maybe this question has been answered somewhere on forums, but I could
> not find. Basically, I want to filter chars in the in-place edit box to
> allow
> entering only digits (for integer).
As already mentioned, there is the ES_NUMBER style, though it doesn't
support signed numbers or hexadecimal.
> I thought that PreTranslateMessage can help, but the method is never
> called.
You don't need a message filter - just handle the WM_CHAR message. Here is
how I restrict input to hexadecimal digits:
class CHexEdit :
public CWindowImpl<CHexEdit, CEdit>
{
BEGIN_MSG_MAP_EX(CMainDlg)
MSG_WM_CHAR(OnChar)
END_MSG_MAP()
void OnChar(TCHAR ch, UINT, UINT)
{
// Allow hex digits and backspace.
if ((VK_BACK == ch) ||
_tcschr(_T("0123456789ABCDEFabcdef"), ch))
{
SetMsgHandled(FALSE);
return;
}
MessageBeep(0);
}
};
Note that invalid characters can still be pasted into the edit control.
You'll have to take additional steps if you want to prevent that.
- Jim
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/wtl/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/wtl/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/