ciderpress/util/MyEdit.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Support for MyEdit class.
*/
#include "StdAfx.h"
#include "MyEdit.h"
//BEGIN_MESSAGE_MAP(MyBitmapButton, CButton)
// ON_WM_SYSCOLORCHANGE()
2007-03-27 17:47:10 +00:00
//END_MESSAGE_MAP()
/*
* Replace an edit control in a dialog with ourselves.
*
* Returns TRUE on success, FALSE on failure.
*/
BOOL MyEdit::ReplaceDlgCtrl(CDialog* pDialog, int editID)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd = pDialog->GetDlgItem(editID);
2014-11-18 05:13:13 +00:00
if (pWnd == NULL)
return FALSE;
2007-03-27 17:47:10 +00:00
/* latch on to their window handle */
Attach(pWnd->m_hWnd);
2007-03-27 17:47:10 +00:00
return TRUE;
2007-03-27 17:47:10 +00:00
}
/*
* Set the properties that make us special.
*/
void MyEdit::SetProperties(int props)
2007-03-27 17:47:10 +00:00
{
fCapsOnly = (props & kCapsOnly) != 0;
fHexOnly = (props & kHexOnly) != 0;
fNoWhiteSpace = (props & kNoWhiteSpace) != 0;
2007-03-27 17:47:10 +00:00
}
/*
* Special keypress handling.
*/
BOOL MyEdit::PreTranslateMessage(MSG* pMsg)
2007-03-27 17:47:10 +00:00
{
if (pMsg->message == WM_CHAR) {
if (fCapsOnly)
pMsg->wParam = toupper(pMsg->wParam);
if (fNoWhiteSpace) {
if (pMsg->wParam == ' ' || pMsg->wParam == '\t')
return TRUE; // we handled it
}
if (fHexOnly) {
if ((pMsg->wParam >= '0' && pMsg->wParam <= '9') ||
(pMsg->wParam >= 'a' && pMsg->wParam <= 'f') ||
(pMsg->wParam >= 'A' && pMsg->wParam <= 'F'))
{
/* good, keep going */
} else if ((pMsg->wParam >= 0x20 && pMsg->wParam < 0x7f) ||
(pMsg->wParam >= 0xa0 && pMsg->wParam <= 0xff))
{
/* ignore this character */
return TRUE; // we handled it
}
/* else it's a backspace or DEL or something */
}
}
2007-03-27 17:47:10 +00:00
return CEdit::PreTranslateMessage(pMsg);
2007-03-27 17:47:10 +00:00
}