Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Personally I did this only once: I've extended CEdit class and ovverided the PretranslateMessage. Here's the code:</p> <p>// .h</p> <pre><code>#pragma once // CHexEdit #define WM_RETURN_PRESSED WM_USER + 5 #define WM_NUMBER_INSERTED WM_USER + 6 class CHexEdit : public CEdit { DECLARE_DYNAMIC( CHexEdit ) public: CHexEdit(); virtual ~CHexEdit(); protected: DECLARE_MESSAGE_MAP() public: afx_msg void OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags ); virtual BOOL PreTranslateMessage( MSG* pMsg ); }; // .cpp #include "stdafx.h" #include "HexEdit.h" #include "Utils.h" // CHexEdit IMPLEMENT_DYNAMIC( CHexEdit, CEdit ) CHexEdit::CHexEdit() { } CHexEdit::~CHexEdit() { } BEGIN_MESSAGE_MAP( CHexEdit, CEdit ) ON_WM_KEYUP() END_MESSAGE_MAP() // CHexEdit message handlers BOOL CHexEdit::PreTranslateMessage( MSG* pMsg ) { bool bAFChars; bool b09Chars; bool bValidInput; bool bControlChars; BOOL bOK; if ( pMsg-&gt;message == WM_KEYDOWN ) { bAFChars = pMsg-&gt;wParam &gt;= 'A' &amp;&amp; pMsg-&gt;wParam &lt;= 'F'; bAFChars |= pMsg-&gt;wParam &gt;= 'a' &amp;&amp; pMsg-&gt;wParam &lt;= 'f'; b09Chars = pMsg-&gt;wParam &gt;= '0' &amp;&amp; pMsg-&gt;wParam &lt;= '9'; bValidInput = bAFChars || b09Chars; bControlChars = pMsg-&gt;wParam &gt;= 0x08 &amp;&amp; pMsg-&gt;wParam &lt;= 0x2F; bControlChars = bControlChars || ( pMsg-&gt;wParam &gt;= 0x5B &amp;&amp; pMsg-&gt;wParam &lt;= 0x5F ); bControlChars = bControlChars || ( pMsg-&gt;wParam &gt;= VK_NUMPAD0 &amp;&amp; pMsg-&gt;wParam &lt;= VK_NUMPAD9 ); if ( bValidInput || bControlChars ) { bOK = TRUE; } else { bOK = FALSE; } if ( !bOK ) return TRUE; // Non fare la pre-translate. } return CEdit::PreTranslateMessage(pMsg); } void CHexEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CString strValue; switch( nChar ) { case VK_RETURN: /*GetParent()-&gt;PostMessage( WM_RETURN_PRESSED, 0, ( LPARAM )byNewValue );*/ break; default: GetParent()-&gt;PostMessage( WM_NUMBER_INSERTED, 16 ); break; } CEdit::OnKeyUp(nChar, nRepCnt, nFlags); } </code></pre> <p>Obviously you have to catch the message on your container class, but this should not be a problem. Hope this will help to solve your problem. Lemme know.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload