14 #pragma comment(lib,"imm32.lib")
53 CEditAscii(
void) : _super(), m_boCanCutPaste(true), m_boCanCallUpdate(true), m_boIsPasting(false)
54 , m_strValidChars( _T(
"!\x22#$%&'()=~|")
58 _T(
"abcdefghijklmnopqrstuvwxyz")
59 _T(
"ABCDEFGHIJKMNLOPQRSTUVWXYZ")
68 CEditAscii(LPCTSTR lpszValidChars) : _super(), m_boCanCutPaste(true), m_boCanCallUpdate(true), m_boIsPasting(false)
69 , m_strValidChars(lpszValidChars)
85 _super::GetWindowText(s);
95 void SetText(LPCTSTR lpszText,
bool boIsNomoveSel =
false)
97 if ( ! boIsNomoveSel )
99 _super::SetWindowText(lpszText);
103 int iCurSel = LOWORD(_super::GetSel());
104 _super::SetWindowText(lpszText);
105 _super::SetSel(iCurSel, iCurSel);
115 m_strValidChars = chars;
124 return m_strValidChars;
148 ::ImmAssociateContext(_super::m_hWnd, NULL);
149 _super::PreSubclassWindow();
161 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
163 if ( message == WM_SETTEXT )
165 LRESULT l = _super::WindowProc(message, wParam, lParam);
170 else if ( message == WM_KEYDOWN )
172 if ( wParam == VK_TAB && ::GetAsyncKeyState(VK_CONTROL) < 0 )
177 else if ( message == WM_CHAR )
179 if ( wParam == VK_TAB )
183 UINT wp = down_cast<UINT>(wParam);
184 LONG lp = down_cast<LONG>(lParam);
191 else if ( message == WM_PASTE )
193 if ( ! m_boCanCutPaste )
197 m_boIsPasting =
true;
198 _super::SetRedraw(FALSE);
199 LRESULT l = _super::WindowProc(message, wParam, lParam);
200 m_boIsPasting =
false;
201 _super::SetRedraw(TRUE);
202 _super::Invalidate();
205 else if ( message == WM_CONTEXTMENU )
207 if ( ! m_boCanCutPaste )
212 else if ( message == WM_LBUTTONDOWN )
215 return _super::DefWindowProc(message, wParam, lParam);
218 return _super::WindowProc(message, wParam, lParam);
234 virtual BOOL
OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* _pResult)
236 if ( message == WM_COMMAND && lParam ==
reinterpret_cast<LPARAM
>(m_hWnd) )
238 if ( m_boCanCallUpdate )
240 m_boCanCallUpdate =
false;
241 int ctrlID = _super::GetDlgCtrlID();
242 if ( wParam == MAKEWPARAM(ctrlID, EN_UPDATE) )
250 else if ( wParam == MAKEWPARAM(ctrlID, EN_SETFOCUS) )
254 else if ( wParam == MAKEWPARAM(ctrlID, EN_KILLFOCUS) )
258 m_boCanCallUpdate =
true;
261 return _super::OnChildNotify(message, wParam, lParam, _pResult);
274 bool boHasInvalidChar =
false;
275 while ( i < s.GetLength() )
278 _super::SetSel(i, i);
282 boHasInvalidChar =
true;
286 s.SetAt(i,
static_cast<TCHAR
>(nChar));
290 if ( boHasInvalidChar )
295 _super::SetSel(i, i);
306 virtual bool IsValidChar(UINT& _nChar, LONG& _lFlags,
const CString& strNowText)
308 bool r = (_lFlags & 1) != 0;
309 if ( r && _nChar == 0x03 )
313 if ( m_boCanCutPaste )
315 if ( r && _nChar == 0x18 )
319 if ( r && _nChar == 0x16 )
324 if ( _nChar ==
'\b' || _nChar == VK_RETURN )
328 if ( m_strValidChars.Find(
static_cast<TCHAR
>(_nChar)) >= 0 )
340 ::MessageBeep(MB_OK);
371 bool m_boCanCutPaste;
372 CString m_strValidChars;
373 bool m_boCanCallUpdate;
397 _super::SetValidChars(_T(
"1234567890") _T(
"abcdef") _T(
"ABCDEF"));
409 virtual bool IsValidChar(UINT& _nChar, LONG& _lFlags,
const CString& strNowText)
411 if ( _nChar >=
'a' && _nChar <=
'f' )
413 _nChar -= (
'a' -
'A');
415 return _super::IsValidChar(_nChar, _lFlags, strNowText);
440 _super::SetValidChars(
445 _T(
"abcdefghijklmnopqrstuvwxyz")
446 _T(
"ABCDEFGHIJKMNLOPQRSTUVWXYZ")
void SetText(LPCTSTR lpszText, bool boIsNomoveSel=false)
[設定] 文字列設定
virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *_pResult)
[通知] for notifications from parent
void SetValidChars(LPCTSTR chars)
[設定] 入力可能文字設定.
virtual void OnInputInvalidChar(void)
[通知] 禁止文字入力発生時に通知.
virtual void OnEditStart(void)
[通知] フォーカスを得た時に通知
virtual void OnPasteChar(void)
[通知] ペーストされた時
virtual bool IsValidChar(UINT &_nChar, LONG &_lFlags, const CString &strNowText)
[確認] 入力許可チェック
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
virtual ~CEditAscii()
デストラクタ
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
CEditAscii(LPCTSTR lpszValidChars)
コンストラクタ
virtual void OnEditEnd(void)
[通知] フォーカスを失った時に通知
virtual void OnUpdateChar(void)
[通知] 入力時に通知
CString GetValidChars(void) const
[取得] 入力可能文字取得.
void SetCutPasteMode(bool r)
[設定] カットペーストモード.
CString GetText(void) const
[取得] 入力文字取得
CEditFileName(void)
コンストラクタ
virtual bool IsValidChar(UINT &_nChar, LONG &_lFlags, const CString &strNowText)
[確認] 入力許可チェック
LRESULT SendCommandMessage(CWnd *pCtrl, UINT cmd)
[処理] WM_COMMAND送信.