Question of CEdit control
edwardlau@hactl.com.hk
Wednesday, October 30, 1996
Environment: MSVC 4.0 / Win95
I am trying to write a derived CEdit class to simlulate the
functionality of masked edit control. After reading from the discussion
for the procedure for developing type over mode, I almost succeed to
develop a mask with literal characters inside. (E.g., date time format,
which is dd/mm/yy, in which the slash is the literal character). It can
skip pass the literal character in the OnChar function, but what I
still cannot succeed is when backspace or delete key is pressed - it
works fine for 'yy', but not 'dd' or 'mm' since the literal character
will move to the left as well. I know this is normal behaviour but
that's not what I want. What I want is when the user press backspace or
insert character, the literal characters still remains in its original
position. How can I achieve this??
Below is part of the code extracted from OnChar of my derived class:
if (b_isTypeOverMode)
{
WORD wPosition = LOWORD(GetSel());
if (bMaskHasLiteralChar)
{
UINT iSpecPos;
BOOL bPosfound = FALSE;
CUIntArray* parint = GetLiteralCharPosArray();
iSpecPos = (m_bIsBackSpaceorDelete) ? (UINT)wPosition - 1 :
(UINT)wPosition;
for (int idx = 0; idx < parint->GetSize(); idx++)
{
if (parint->GetAt(idx) == iSpecPos)
{
bPosfound = TRUE;
break;
}
}
if ((bPosfound) && (!m_bIsBackSpaceorDelete))
wPosition++;
else if ((bPosfound) && (m_bIsBackSpaceorDelete))
wPosition--;
}
if (m_bIsBackSpaceorDelete)
SetSel(wPosition, wPosition--);
else
SetSel(wPosition, wPosition++);
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
David Little -- dlittle@equinoxcorp.com
Thursday, October 31, 1996
[Mini-digest: 2 responses]
I believe that whatever you are doing in the OnChar class is being =
negated by your call to CEdit::OnChar(). Since you are defining your =
own behavior, you don't need the base class, unless it is a case that =
you didn't handle. If you decided to have a CEdit box that only =
accepted a Y or N, you could do this:
void CYorNOnly::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case 'Y':
case 'N':
CEdit::OnChar(nChar, nRepCnt, nFlags); // call base class for normal =
processing
return;
default:
return; // do nothing for any other character
}
}
Hope this helps...
David
----------
From: edwardlau@hactl.com.hk[SMTP:edwardlau@hactl.com.hk]
Sent: Tuesday, October 29, 1996 9:30 PM
To: mfc-l@netcom.com
Subject: Question of CEdit control
Environment: MSVC 4.0 / Win95
=20
I am trying to write a derived CEdit class to simlulate the=20
functionality of masked edit control. After reading from the =
discussion=20
for the procedure for developing type over mode, I almost succeed =
to=20
develop a mask with literal characters inside. (E.g., date time =
format,=20
which is dd/mm/yy, in which the slash is the literal character). It =
can=20
skip pass the literal character in the OnChar function, but what I=20
still cannot succeed is when backspace or delete key is pressed - =
it=20
works fine for 'yy', but not 'dd' or 'mm' since the literal =
character=20
will move to the left as well. I know this is normal behaviour but=20
that's not what I want. What I want is when the user press =
backspace or=20
insert character, the literal characters still remains in its =
original=20
position. How can I achieve this??
=20
=20
Below is part of the code extracted from OnChar of my derived =
class:
=20
=20
=20
if (b_isTypeOverMode)
{
WORD wPosition =3D LOWORD(GetSel());
=20
if (bMaskHasLiteralChar)
{
UINT iSpecPos;
BOOL bPosfound =3D FALSE;
CUIntArray* parint =3D GetLiteralCharPosArray();
=20
iSpecPos =3D (m_bIsBackSpaceorDelete) ? (UINT)wPosition - 1 : =
=20
(UINT)wPosition;
=
=20
for (int idx =3D 0; idx < parint->GetSize(); idx++)
{
if (parint->GetAt(idx) =3D=3D iSpecPos)
{
bPosfound =3D TRUE;
break;
}
}
=20
if ((bPosfound) && (!m_bIsBackSpaceorDelete))
wPosition++;
else if ((bPosfound) && (m_bIsBackSpaceorDelete))
wPosition--;
}
=20
if (m_bIsBackSpaceorDelete)
SetSel(wPosition, wPosition--);
else
SetSel(wPosition, wPosition++);
=20
}
=20
CEdit::OnChar(nChar, nRepCnt, nFlags);
=20
-----From: "Jim Alsup"
I'm not a 100% sure, but it sounds to me like you want to turn the backspace or
delete keystoke action into a replace the current character with
a space and possibly adjust cursor position (for backspace). I'd probably
attempt to adjust the edit buffer contents myself and avoid calling the
base call function "CEdit::OnChar(nChar, nRepCnt, nFlags)" for
these cases. It should be straightforward enough.
-jim ja@epsisupport.com
| Вернуться в корень Архива
|